The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API)
for Windows NT & Win95, version 4.00
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.
You can find GLTEXTUR.EXE (size: 91394 bytes)
, a self-extracting file, on the following
services:
- Microsoft's World Wide Web Site on the Internet
On the www.microsoft.com home page, click the Support icon.
Click Knowledge Base, and select the product.
Enter kbfile GLTEXTUR.EXE (size: 91394 bytes)
, and click GO!
Open the article, and click the button to download the file.
- Internet (anonymous FTP)
ftp ftp.microsoft.com
Change to the Softlib/Mslfiles folder.
Get GLTEXTUR.EXE (size: 91394 bytes)
- Microsoft Download Service (MSDL)
Dial (206) 936-6735 to connect to MSDL
Download GLTEXTUR.EXE (size: 91394 bytes)
For additional information about downloading, please see the following
article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591
TITLE : How to Obtain Microsoft Support Files from Online
Services
MORE INFORMATION
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_<S or T>_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.
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:
- Neider, Jackie, Tom Davis, and Mason Woo. OpenGL Programming Guide: The
Official Guide to Learning OpenGL, Release 1. Reading, MA: Addison-
Wesley, 1993. ISBN 0-201-63274-8. (This book is also known as the "Red
Book.")
For more information on DIBs and Texture Mapping in OpenGL, please see the
following resources:
- Rogerson, Dale. "OpenGL V: Translating Windows DIBs." January 1995.
(Development Library, Technical Articles)
- Rogerson, Dale. "OpenGL VII: Scratching the Surface of Texture Mapping."
April 1995. (Development Library, Technical Articles)
For more information on DIBs in general, please see the following
resources:
- Gery, Ron. "DIBs and Their Use.". March 1992. (Development Library,
Technical Articles)
- Gery, Ron. "Using DIBs with Palettes." March 1992. (Development Library,
Technical Articles)