SAMPLE: Demonstrates OpenGL Texture-Mapping Capabilities

ID: Q160817

The information in this article applies to:

SUMMARY

GLTEXTUR.EXE provides a demonstration of how to use a Device-independent Bitmap (DIB) as a texture-map for OpenGL by pasting a DIB (chosen by the user) onto three different OpenGL objects.

GLTex allows you to modify texture settings so you can see quickly and easily the visual effect created.

Please see the REFERENCES section of this article for more information on resources.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ GLTEXTUR.EXE (size: 91394 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from
               Online Services

OpenGL for Windows NT and Windows 95 supports powerful texture-mapping capabilities. GLTex lets you experiment easily with most of these capabilities and immediately see the effect on-screen.

The new GL_BGRA_EXT image format makes using DIBs as textures easy because BGR is the same ordering used for DIBs. For convenience's sake, GLTex converts all DIBs it reads into 32-bpp DIBs (by calling StretchDIBits). This makes the DIB handling and texture handling much cleaner throughout the sample. OpenGL textures require that the image used be of size 2^n by 2^n. GLTex's ScaleDIB function performs the conversion to 32-bpp and scales the image to a square one of size 2^n by 2^n.

When the OpenGL scene is rendered, three simple three-dimensional shapes are drawn with the converted and scaled texture mapped onto *each* face. This mapping is handled (initially) by the glTexCoord function, which is called as the shape vertices are specified. The drawing of the shapes is handled by GLTex's BuildShapes function.

Settings

Once you have loaded a DIB and see how it maps to the shape faces, GLTex allows you to change the texture mapping settings in order to see how these changes would effect the image. The following list gives modifications that GLTex allows you to make, a brief description of their effect, and explains which functions are used to change them:

REFERENCES

NOTE: Most of the following references can be found on the Microsoft Developer Network (MSDN) Developer Library CD-ROM. Some of these references are published by publishers independent of Microsoft; we make no warranty, implied or otherwise, regarding the reliability of these resources.

Some code for this GLTex sample was borrowed from the ShowDIB sample for DIB-handling (Dib.c) and from Dale Rogerson's articles/samples for OpenGL palette creation (Glpalette.c). The DIB code has been enhanced in order to handle the loading of 16-bpp and 32-bpp DIBs.

For more information on the settings and OpenGL in general, please see the following resource:

For more information on DIBs and Texture Mapping in OpenGL, please see the following resources: For more information on DIBs in general, please see the following resources: Additional query words: kbfile
Keywords          : kbNTOS400 kbWinOS95 kbSDKWin32 kbsample
Version           : 4.00
Platform          : NT WINDOWS

Last Reviewed: June 15, 1999