TextureBMP is sample C++ code illustrating the use of textures in OpenGL.   It is intended to accompany the book 3D Computer Graphics: A mathematical approach with OpenGL, by S. Buss, Cambridge University Press, 2003.   However, it can be used independently as well.

TextureBMP reads a texture map from a bitmap file (.bmp extension).  Bitmap files can be created with many standard graphics editting programs, include the PC program Paint.   These programs often allow coverting other file formats to bitmap images.   The main program is in TextureMap.cpp.   The C++ class RgbImage is used to read the image data from a bitmap file.

There are several options for downloading the files.

Things to look at:

  1. Compile and run the program.  Note how it behaves when the window is resized larger and smaller.  Do you see an unwanted aliasing problems?
  2. Look at how texture coordinates must be explicitly given with glTexCoord2f commands as the quad is drawn.
  3. The RgbImage class returns the pixels in an array.  Each row of the array begins on a word boundary (so the rows are padded as necessary to make this work).  This is what OpenGL expects by default, otherwise, we would have had use the glPixelStore command to inform OpenGL about the row alignment.
  4. Try modifying the program to display the mirror-image of the texture.  You do not need to modify the texture, just the teture coordinates.