Need a 3D graph? Try the 3DSurface Viewer! Draw 3D graphs with free calculus software from Bright Ideas Software.
GLE32 Ver. 4 Manual
  Skip Navigation Links
Math ToolsExpand Math Tools
DevelopersExpand Developers
About BISExpand About BIS
  Skip Navigation LinksHome --> Developers --> GLE32 Version 4 --> GLE32 Manual --> 2D Texture Class Search:
Skip Navigation Links

OpenGL® and OpenGL|ES are trademarks of Silicon Graphics, Inc.





2D Texture Class

This class wraps a great deal, but not all, of the GL texture interface needed for typical 2D texture use. I've tried to simplify the handling of texture objects without masking any of their capability; hence the qualifier 'a great deal'. Familiarity with the OpenGL texturing API is required; like most of the library, code comments are rare, and this document will not attempt to explain basic GL texture operation. If you know how to use the texturing API you may find this class useful; if you don't, this class isn't going to help you. The public interface is presented below. In a nutshell, instantiate a CgleTexture object, either dynamically or statically. Set the desired filter modes, wrap mode, etc, then call one of the 'build' functions. A GL texture handle will be acquired, the image (and optional mipmaps) created, and GL texture object state will be configured with the filter mode, wrap mode, etc, you'd selected. Also refer to the demo programs available at http://www.brightideassoftware.com/gle32v4home.aspx for examples of the use of this class.

Features include automatic mipmap generation, ability to load images in a variety of formats from either embedded resources or external files, and use of the GL_ARB_texture_compression extension to perform runtime compression of textures, then optionally store the compressed version for later use on the client machine. Subsequent executions of the texture code will attempt to load the compressed file (saving compression time); failure to succesfully load the compressed file will result in it's regeneration, ensuring smooth operation of the client app. Images are optionally automatically resized to the next lower 2^n dimension if they aren't already valid 2^n values.

A note about loading embedded resources: The CgleTextgure class will load images stored as a resource in a variety of formats (.bmp, .jpg, .ppm, .pgm, most standard .tga formats). In order to store/reload images in formats other than .bmp (which are listed in an .rc file under the standard heading 'Bitmap'), they must be labeled as an 'IMAGE' resource. This is hard-coded into the class, although obviously you can change it to something else if you like. A typical entry in an .rc file should look something like this: IDI_ROCKWALL_IMAGE      IMAGE    "resources\\relief_rockwall.jpg". Note the 'IMAGE' tag, second item in the line. This, combined with the resource identifier (IDI_ROCKWALL_IMAGE in this case), is what CgleTexture looks for when it loads an embedded image.

The code for converting a height map to a normal map has it's roots in a white paper by Mark Kilgard; some of the procedural texture code has it's roots in Linas Vepstas' original GLE library.


CgleTexture

Variables  Description
 
BOOL m_bVertInvert   Set this TRUE before creating the texture to flip the image vertically. Default is FALSE.
BOOL m_bHorzInvert   Set this TRUE before creating the texture to flip the image horizontally. Default is FALSE.
BOOL m_bStretch   Set this TRUE to automatically resize images whose dimensions aren't already 2^n. If the image is not 2^n and m_bStretch is false, the image will be cropped to the next smaller 2^n dimension. Default is TRUE.
BOOL m_bUseCompressed   If this is TRUE, an attempt will be made to load the textuures with a GL_COMPRESSED internal format. You must initialize the GL_ARB_texture_compression API separately before attempting to use this feature. Default is FALSE.
BOOL m_bStoreCompressed   Set this TRUE to enable storage of the compressed textures as local files. (m_bUseCompressed must also be TRUE.) If this is enabled, the first time a texture is created CgleTexture will compress the texture then offload the compressed version into a file whose name you specify. Whenever the program is run after that, CgleTexture will attempt to load the pre-compressed texture from the file. If this fails it will load the original image and recreate the compressed file. Default is FALSE.
 
Methods   Description
 
 CgleTexture()   
virtual ~CgleTexture()   
 
void ReleaseResources()   This wraps glDeleteTextures, and resets the image dimensions to 0. It is called automatically from the destructor.
 
int GetTextureIndex()   Returns the handle or 'name' assigned to the texture object by glGenTextures when the texture was first built.
int GetTextureHeight()  Returns the height of the texture image.
int GetTextureWidth()  Returns the width of the texture image.
void SetTexFilterMode(GLenum MinFilter, GLenum MaxFilter)  Configure minification and magnification filters. Call this before building the texture; if you change the filter modes after creating the texture, call UpdateTexObject(). Defaults are both GL_LINEAR.
void SetTexWrapMode(GLenum SWrap, GLenum TWrap)  Configure the wrap mode. As with filtering, call this before building the texture; if you change the wrap modes after creating the texture, call UpdateTexObject(). Defaults are both GL_REPEAT.
void SetUseMipMaps(BOOL value)  Controls whether or not mipmaps are generated from the base image when the texture is created. Default is FALSE. Set this before creating the texture; subsequent changes require rebuilding the texture to take effect.
void UpdateTexObject()  This method wraps the calls to glTexParameteri that set up the wrap and filter modes.
 
void SetPlaneAlignment(float SPlane[4], float TPlane[4])  Call this to modify the reference planes used for texture coordinate generation. Default values are (1.0, 0.0, 0.0, 0.0) and (0.0, 1.0, 0.0, 0.0).
void SetCoordGenMode(GLenum SMode, GLenum TMode)  Call this to modify the coordinate generation mode. Defaults are both GL_OBJECT_LINEAR.
void SetCoordGenRefPlane(GLenum SPlane, GLenum TPlane)  Defaults are both GL_OBJECT_PLANE.
void TexGenEnable()  Turns on S and T axis coordinate generation, per the parameters set earlier.
void TexGenDisable()  Turns coordinate generation off.
 
void BuildBarberTexture(COLORREF TexColor, COLORREF BackColor, int Density = 32, BYTE TexAlpha = 255, BYTE BackAlpha = 255, BOOL bUseAlpha = FALSE)  Build a barber-pole stripe texture. Density refers to the density of the pattern. If bUseAlpha is TRUE, the TexAlpha and BackAlpha values will be incorporated in a 32 bit texture; if bUseAlpha is FALSE, the other two Alpha values are ignored and the texture created is 24 bit.
void BuildCheckerTexture(COLORREF TexColor, COLORREF BackColor, int Density = 16, BYTE TexAlpha = 255, BYTE BackAlpha = 255, BOOL bUseAlpha = FALSE)  Checkerboard pattern - all parameters as described above.
void BuildGridTexture(COLORREF TexColor, COLORREF BackColor, int Density = 8, BYTE TexAlpha = 255, BYTE BackAlpha = 255, BOOL bUseAlpha = FALSE)  Grid pattern - all parameters as described above.
void BuildHoundTexture(COLORREF TexColor, COLORREF BackColor, int Density = 16, BYTE TexAlpha = 255, BYTE BackAlpha = 255, BOOL bUseAlpha = FALSE)  Hounds tooth pattern - all parameters as described above.
void BuildCheckerTexture(COLORREF TexColor, COLORREF BackColor, int Density = 16, BYTE TexAlpha = 255, BYTE BackAlpha = 255, BOOL bUseAlpha = FALSE)  Checkerboard pattern - all parameters as described above.
void BuildPlanetTexture( BYTE TexAlpha = 255, BOOL bUseAlpha = FALSE)  Abstract pattern - all parameters as described above.
void BuildStripeTexture(COLORREF TexColor, COLORREF BackColor, int Density = 32, BYTE TexAlpha = 255, BYTE BackAlpha = 255, BOOL bUseAlpha = FALSE)  Stripes - all parameters as described above.
 
void BuildTextureFromResource(HINSTANCE AppInstance, UINT ImageID)  AppInstance should self explanatory. Image ID is the resource ID from the .rc file (IDI_ROCKWALL_IMAGE in the example above). If the image is 32 bits per pixel, the texture will be created as GL_RGBA and the alpha information will be preserved. If bUseAlpha is TRUE and the image is less than 32 bpp, the texture will be created as GL_RGBA and the TexAlpha value will be used at each pixel If bUseAlpha is FALSE, the texture will be created as GL_RGB. CompressedFileName is for use with the variables bUseCompressed and bStoreCompressed, described above. If both are TRUE, the file name supplied here will be used for the compressed texture. The extension will be '.bist'.
void BuildTextureFromResource(HINSTANCE AppInstance, UINT ImageID, BYTE TexAlpha, BOOL bUseAlpha)
void BuildTextureFromResource(HINSTANCE AppInstance, UINT ImageID, BYTE TexAlpha, BOOL bUseAlpha, LPTSTR CompressedFileName)
 
void BuildTextureFromFile(LPTSTR FileName)  FileName should be self-explanatory; bTexAlpha, bUseAlpha and CompressedFileName are the same as with BuildTextureFromResource.
void BuildTextureFromFile(LPTSTR FileName, BYTE TexAlpha, BOOL bUseAlpha)
void BuildTextureFromFile(LPTSTR FileName, BYTE TexAlpha, BOOL bUseAlpha, LPTSTR CompressedFileName)
 
void BuildTextureFromBitmap(HBITMAP hBitmap)  hBitmap is the handle to any valid bitmap. If the bit per pixel is less than 24, it will be set to either 24 or 32, depending on the bUseAlpha parameter. bTexAlpha, bUseAlpha and CompressedFileName are the same as with BuildTextureFromResource.
void BuildTextureFromBitmap(HBITMAP hBitmap, BYTE TexAlpha, BOOL bUseAlpha)
void BuildTextureFromBitmap(HBITMAP hBitmap, BYTE TexAlpha, BOOL bUseAlpha, LPTSTR CompressedFileName )
 
void BuildTextureFromRamChunk(BYTE* data, int byte_count, LPSTR cExtension)  Creates a texture from a block of ram containing an image in tga, ppm, ppg, bmp or jpg format. bTexAlpha, bUseAlpha and CompressedFileName are the same as with BuildTextureFromResource.
void BuildTextureFromRamChunk(BYTE* data, int byte_count, LPSTR cExtension, BYTE TexAlpha, BOOL bUseAlpha)
void BuildTextureFromRamChunk(BYTE* data, int byte_count, LPSTR cExtension, BYTE TexAlpha, BOOL bUseAlpha, LPTSTR CompressedFileName)
 
void BuildCustomTexture(BYTE* ImagePtr, int iBitCount, LPTSTR compressedFileName)  This will build a texture from a byte array. iBitCount must be either 24 or 32 bpp; CompressedFileName is as described above.
void BuildNormalMapFromHeightMap(HBITMAP hImage, float Scale = 1.0)  This uses Mark Kilgard's code to build a full set of mip-mapped normal maps from a grayscale heightmap. The normal maps are suitable for use with the bump-mapped objects.

Back To Top



Copyright© 2001-2008 by Bright Ideas Software®. All rights reserved.