Demo - Loading Bitmaps & Texture Mapping

There have been several threads lately about loading images such as .bmp, .jpg, .tga, for use as texture maps. It’s an issue not easy to address in a forum because image loaders are not trivial. I’ve put together a demo which loads .bmps and displays them as textures on a quad and on a sphere. It displays a third image (the OpenGL logo) directly as an image using glDrawPixels. Though I tried to keep the program simple, it is still comes to about 400 lines of code. This includes a short routine that loads .bmp files (provided by Michael Sweet). You may want to separate this routine (Load_BMP_Img) into a its own file along with its header (inside the $$$$$ signs). For the sake of simplicity, I put everything into one file -

Texture Maps From .bmp Files Demo - MaxH

This code uses glut for windowing and interaction. The directory below contains an image (MaxH_Textures.jpg) that shows what this code should generate. The same directory has 3 .bmp images required by the demo (frac.bmp, logo.bmp, and wmap.bmp).

Texture Demo Images - MaxH

If you get all this to work, try substituting your own images for mine. Your images must have the same pixel dimensions as mine, unless you change the corresponding lines of code in my program. OpenGL textures must have pixel dimensions that are powers of 2, like 256, 512, 1024, etc. Anyone who wants to do anything more serious than a homework assignment with this code should read up on OpenGL texturing. I have kept things very basic in this demo. Suggestions from experienced OpenGL programmers are welcome. You might also try changing that last parameter in the glTexParameteri calls. You will see a subtle difference in the way the textures are rendered.

The arrow keys rotate the scene. The ‘a’ key starts and stops animation of the earth and floor. Let me know if you have any trouble getting this to run.