Microsoft KB Archive/160817

{|
 * width="100%"|

Demonstrates OpenGL Texture-Mapping Capabilities

 * }

Q160817

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * Microsoft Windows 98
 * Microsoft Windows 95
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional

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" For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

"ARTICLE-ID: Q119591 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:


 * "Scene Distance from Viewer" allows you to push the scene farther away or bring it closer. This is achieved with glTranslate.
 * "Shape Rotation" allows you to modify the angle of rotation around the x, y, and z axes. This is achieved with glRotate for each axis.
 * "Light Position" allows you to move the single light source used. Note that by changing the w coordinate, you can modify whether you are using a directional (w = 0.0) or positional (w = 1.0) light source. This is achieved with glLight(...GL_POSITION...).
 * "Texture Mode" allows you to use two of the three texture modes available with OpenGL. Decal mode essentially means that the texture is applied directly to the object without any calculation of material properties or lighting. Modulate mode blends the underlying object (that is effected by material properties and lighting) with the texture. This gives the effect of a lighted texture. The third possibility, Blending, doesn't make sense for a three-component (RGB) image. This is achieved with glTexEnv.
 * "Perspective Hint" should be changed to Nicest if the texture appears to be projected incorrectly. You should try it anyway because it will allow you to see the difference. This is achieved with glHint.
 * "Minification Filter" controls how a screen pixel should be mapped to a collection of texels (texture elements). This is achieved with glTexParameter(...GL_TEXTURE_MIN_FILTER...).
 * "Magnification Filter" controls how a screen pixel should be mapped to a portion of a texel (texture element). This is achieved with glTexParameter(...GL_TEXTURE_MIN_FILTER...).
 * "Texture Wrap S" and "Texture Wrap T" allow you to specify whether the image should repeat in the S and T directions. (These can be thought of as the X and Y directions in the texture's world.) This is achieved with glTexParameter(...GL_TEXTURE__WRAP...).
 * "Texture Coordinates" specifies how the texture is mapped to the object. Because 0.0 is the default for the first parameter, one side of the texture is always mapped to the edge of the cube's face. This should be used in conjunction with Texture Wrap S and T for repeating the texture across the cube's faces. This is achieved with glTexCoord.
 * "Sphere Complexity" allows you to modify the number of faces used to create the sphere. Initially the complexity is 0, which is a very rough 20-sided approximation of a sphere. You can increase this to a point, but keep in mind the complexity increases rapidly and can slow down the rendering (especially when spinning the objects). See GLSphere.c for the details.
 * "Transparency" allows you to choose an RGB color that you would like to treat as transparent for the chosen texture. An alpha function is set up to let you see through the texture onto the underlying object where this color exists. Because it is difficult to chose one exact color to use, you can modify how exact the color-matching should be. No variance means only the exact RGB color is made transparent, while total variance means all colors are treated as transparent.
 * "S Generation" and "T Generation" allow you to instruct OpenGL to ignore the texture coordinates specified for the individual shape faces by GLTexCoord, and generate textures based on a mode (Object Linear, Eye Linear, or Sphere Map) and a plane (specified by X, Y, Z, W). You can achieve some interesting effects quickly by playing with texture coordinate generation. Note that you will probably want to keep "Texture Wrap S" and "Texture Wrap T" set to repeat. Also, spinning the objects is often the easiest way to see what has been affected.
 * "Spin!" speaks for itself. Keep in mind that the "Shape Rotation" setting is a constant that "Spin!" doesn't modify. Also, depending on the speed of your processor and video card, the spinning objects can become quite slow if you have lots of effects turned on at once.