SAMPLE: GLTex Demos How to Use DIBs for Texture MappingLast reviewed: August 5, 1996Article ID: Q148301 |
The information in this article applies to:
SUMMARYThe GLTex sample (GLTEXTUR.EXE) provides a demonstration of how to use a DIB (device-independent bitmap) as a texture-map for OpenGL by pasting a DIB (chosen by the user) onto all sides of a three-dimensional cube. GLTex also allows you to modify various texture settings so that you can quickly and easily see the visual effect created.
You can find GLTEXTUR.EXE (size: 91394 bytes) , a self-extracting file, on these services: 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 ftp ftp.microsoft.com Change to the Softlib/Mslfiles folder Get GLTEXTUR.EXE (size: 91394 bytes) On the Edit menu, click Go To, and then click Other Location Type "mssupport" (without the quotation marks) Double-click the MS Software Library icon Find the appropriate product area Locate and Download GLTEXTUR.EXE 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 INFORMATIONOpenGL for Windows NT and Windows 95 support powerful texture-mapping capabilities. GLTex lets you easily experiment with many (but not all) of these capabilities by using a series of conversions to generate the texture map. It allows the user to modify various OpenGL settings. To use a DIB as a texture in OpenGL, you must first convert the DIB into a format that is compatible with OpenGL. Because a 32-bpp DIB is the most closely related to an OpenGL formatted image, you can take the DIB that the user provides and regardless of its format copy it by using StretchDIBits onto a 32-bpp DIB Section. Therefore, from this point on, GLTex can assume that it is working with a 32-bpp DIB Section. Note that because a 32-bpp DIB is used, you don't have to worry about the DWORD-alignment of DIBs. 32-bit DIBs are already DWORD-aligned. After ensuring that you have a 32-bpp DIB Section, you must convert that DIB Section into an OpenGL image. This involves converting the BGR format of the DIB into the RGBA format that OpenGL uses. This translation from an "any format DIB" into an OpenGL image is handled by GLTex's DIBtoGLImage function. Now that you have an OpenGL image, you must scale it to a format that is 2^n x 2^n. This is required for OpenGL textures. (There is one exception to this rule involving texture borders, but GLTex does not use borders.) You might want to chose to always scale the image to be square because you're mapping onto cube faces. Then GLTex scales the image sides to the closest 2^n by using the utility function gluScaleImage. Finally, this scaled image is set as the texture-image by calling glTexImage2D. This scaling and setting of the texture is handled by GLTex's GLImagetoTexture function. When the OpenGL scene is rendered, a simple three-dimensional cube is drawn with the converted and scaled texture mapped onto it. This mapping is taken care of by the glTexCoord function, which is called as the cube vertices are specified. This is handled by GLTex's BuildCube function.
SettingsOnce you have loaded a DIB and see how it maps to the cube's sides, GLTex allows you to change several 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 which functions are used to change them:
REFERENCESNOTE: 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. 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). For more information on the settings and OpenGL in general, please see the following resource:
|
Additional reference words: 3.51 4.00 image texture mapping
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |