This brief tutorial explains the basics of texture mapping in OpenGL. You can find more information online.
To start, download the source and images files here. Create a visual studio project and insert the source files. Build the project and run the executable. You should see two triangles with textures attached. Use the mouse to manipulate the camera. Notice that the textures remain in place. Texture mapping is essentially the "gluing" of an image onto a polygonal surface. To texture map in OpenGL you need to do the following.
The enclosed demo has a simple method to read bmp files. This procedure only works with 24 bit image (8 bits for each of three channels). If you have a file in another format you can convert it to the prescribed format in gimp, photoshop, etc. Note: OpenGL requires that texture images have a width and height that are powers of 2! The texture does not have to be square. If you have problems with texture mapping this is the first thing to check.
This is done in the demo in initializeTexture(). There are various parameters that you can change to create various effects but the chosen settings should work for most applications. Note: The texture should be read and initialized ONCE when the application is started. Do not re-intialize each time you want to use the texture. The texture handle -- named htexture in the demo -- is used as the application runs to identify the texture. You can create more than one texture at a time; each will have a unique texture handle.
The display function in the demo shows how to draw a triangle with a texture map. You need to enable texturing and bind the appropriate texture before starting to draw the triangle, provide a texture coordinate fore each vertex during drawing, then disable texturing when done. The texture coordinate tells OpenGL the point in the image that should be glued to the triangle vertex. The image itself will be stretched or shrunk to fit. Texture coordinates of (0,0) and (1,1) correspond, respectively, to the lower left corner and upper right corners of the image. You can use texture coordinate outside the range of [0,1]; OpenGL simply drops the integer part. (Another way to think of this is that the plane is tessellated with 1x1 squares of your image. This is what the GL_REPEAT means in the initialization code.) Play around with the texture coordinates in the demo to be sure you understand how they work.