Wow. It's been a long time since I've answered any OpenGL questions. All of this is off the top of my head, so I may be forgetting something, but here are the basic steps for using textures.
1.
Enable texture mappingThis is done using:
glEnable(GL_TEXTURE);
This only needs to be done once, usually right after OpenGL is initialized.
2.
Create a texture handleYou can either use hardcoded texture handles, or use glGenTextures to generate an unused one. Using glGenTextures is usually best in apps where you have many textures. If you only need to generate 1 texture, use it something like so:
int nTextureID;
glGenTextures(1, &nTextureID);
If you want to generate many textures handles at a time, you can put them into an array like so:
int vTextureIDs[100];
glGenTextures(100, vTextureIDs);
3.
Bind the textureBefore you do anything with your texture (configure it, load data into it, use it), you need to bind it. You do that by using glBindTexture with the texture ID you got in step 2.
glBindTexture(GL_TEXTURE_2D, nTextureID);
4.
Configure the texture parametersThere are a number of parameters you can configure with regard to textures wrapping and what sort of resizing algorithms to use. A typical set of configurations is something like the following:
glTexParameteri(GL_TEXTURE_MIN_FILTER, GL_LINEAR); // need to change this if you use mipmapping
glTexParameteri(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexparameteri(GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexparameteri(GL_TEXTURE_WRAP_T, GL_REPEAT);
If you look at the documentation for glTexParameteri you can find out what other parameters there are and values they can be set to.
5.
Load the imageThere are a number of ways to load the image data. OpenGL itself doesn't have any functions for opening image format files like BMP, TGA, etc. Since your subject mentions glut, I'll assume you want to use the glut functions. Unfortunately, I don't think glut even has a BMP loading function. I'm not sure if you are using standard glut or OpenGLUT, but it looks like the latter has at least proposed a function called glutReadImageFile. There is also a glAux function for loading BMP files called auxDIBImageLoad, but it only works on Windows, and glAux is even less supported than the old glut and requires you to have the glaux DLLs. (I'm not even sure if XP still ships with those and that function doesn't even show up in the latest version of MSDN I have for VS 2005.)
Anyway, I'll leave getting the actual image data up to you. My suggestion would be to use TGA files and find one of the many examples of getting the image data from a TGA. It is a pretty simple file format, and supports an alpha channel.
One more thing needs to be said regarding your textures. They need have dimensions that are a power of 2. (e.g. 2,4,8,16,32,64,128,256,512,etc.) The width and height do not need to be the same, but they both need to be a power of 2. (e.g. 512x256, 1024x1024, etc.) If you use mipmaps and gluBuild2DMipMaps you don't have to worry quite so much about the size as it will resize each mipmap to be a power of 2 for you. Mipmapping is probably overkill for the simple texturing of a quad or triangle example, though.
Once you have your image data into an array of bytes, you can tell OpenGL to use that data with glTexImage2D:
glTexImage2D(
GL_TEXTURE_2D,
0, // mipmap level. 0 is base image
GL_RGB8, // The format of the data as you want OpenGL to store it
width, // width of your image
height, // height of your image
0, // border
GL_RGB8, // The format of the data in your array, note this can be different from the internal format above
GL_BYTE, // The data type your image is stored in
pImageData // The char* holding your image data
);
6.
Using the textureNow that you have all of that out of the way, you have to actually use your image. To do that, when you specify vertices, you first have to specify texture coordinates. A texture coordinate is an X/Y value usually from 0.0 to 1.0, with 0 being one edge of your texture and 1.0 being the other side of your texture. As an example, I'll show you how you would use them for a quad.
// Not necessarily needed when only using 1 texture, but good practice for when you have multiple textures loaded.
glBindTexture(GL_TEXTURE_2D, nTextureID);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); // Tex-coord must come before vertex position
glVertex2f(-1.0, -1.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, -1.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glTexture2f(-1.0, 1.0);
glEnd();
There can be a lot more to it, but that's the quick run through of one of the simplest usages of textures. If you have any other questions, there are some good tutorials at
NeHe Productions. There are also some good forums at
OpenGL.org. Those ones are a lot more active than these.