OpenGL (1.2 - 2.0) Code Samples - Page 3

Texture Addressing
 

Demonstrates how texture addressing works under OpenGL by allowing the texture addressing mode to be changed at run-time with a textured quad whose texture coordinates range from 0.0 to 3.0. A few of the modes are available through extensions. The sample uses the following extensions: ARB_texture_mirrored_repeat, ARB_texture_border_clamp, SGIS_texture_edge_clamp. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: auxDIBImageLoad, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glEnable, glBindTexture, AUX_RGBImageRec, GL_T2F_V3F, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_REPEAT, GL_CLAMP, GL_MIRRORED_REPEAT_ARB, GL_CLAMP_TO_BORDER_ARB, GL_CLAMP_TO_EDGE, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_LINEAR, and GL_UNSIGNED_BYTE.

 

Texture Sub-loading
 

Demonstrates how texture sub-loading works under OpenGL by copying a smaller texture over the texel data of a larger texture. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: glTexSubImage2D, auxDIBImageLoad, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glEnable, glBindTexture, AUX_RGBImageRec, GL_T2F_V3F, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_LINEAR, and GL_UNSIGNED_BYTE.

 

Texture Mip-mapping
 

This sample demonstrates how mip-mapping works under OpenGL by tiling a single textured quad across a 25x25 unit area. The original texture is simply white with a thin black border, but in a effort to show mip-mapping in action, several mip-map levels have been altered by replacing the auto generated mip-map texture for that level with a color-coded version. This causes mip-map filtering to produce rainbow colored bands which radiate across the surface as the eye point moves about. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: gluBuild2DMipmaps, glPixelStorei, auxDIBImageLoad, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glEnable, glBindTexture, AUX_RGBImageRec, GL_UNPACK_ALIGNMENT, GL_T2F_V3F, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR, and GL_UNSIGNED_BYTE.

 

Multi-Texturing
 

This sample demonstrates how to perform multi-texturing with OpenGL's ARB_multitexture extension by either modulating or adding two textures together in one rendering pass. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: GL_ARB_multitexture, glActiveTextureARB, glMultiTexCoord2fARB, glClientActiveTextureARB, glTexEnvi, glVertex3f, wglGetProcAddress, glGetString, auxDIBImageLoad, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glEnable, glDisable, glBindTexture, AUX_RGBImageRec, GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE, GL_ADD, GL_TEXTURE0_ARB, GL_TEXTURE1_ARB, GL_EXTENSIONS, GL_BLEND, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_UNSIGNED_BYTE, PFNGLACTIVETEXTUREARBPROC, PFNGLMULTITEXCOORD2FARBPROC, and PFNGLCLIENTACTIVETEXTUREARBPROC.

 

Alpha Texture Blending

 

This sample demonstrates how to perform alpha blending using the alpha channel of a standard .tga texture. For proper alpha blending, the sample uses a cull-mode sorting trick to ensure the sides of the textured cube get rendered in back-to-front order. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glEnable, glDisable, GL_T2F_V3F, GL_DEPTH_TEST, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_BLEND, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_LINEAR, GL_CULL_FACE, GL_FRONT, GL_BACK, and GL_UNSIGNED_BYTE.