After drawing the texture, call the OpenGL function glTexImage2D() (There are also versions of this function for one and three-dimensional textures) to specify the texture image. This function takes nine arguments.
For the sample code I included in this article, I used the internal format GL_RGBA8. This format has 8 bits of red, green, blue, and alpha. GL_RGBA8 works well on Mac OS X if you’re using 32-bit color.
The most common Mac offscreen buffer pixel format is k32ARGBPixelFormat, which has 8 bits of alpha, red, green, and blue. There is no GL_ARGB format in OpenGL. If you use k32ARGBPixelFormat, your format must be GL_BGRA, which is the reverse of ARGB. On a PowerPC Mac you must use the data type GL_UNSIGNED_INT_8_8_8_8_REV, which reverses the bytes. Intel Macs don’t need to reverse the bytes so they use the data type GL_UNSIGNED_INT_8_8_8_8.
#if __BIG_ENDIAN__ textureMap.SetType(GL_UNSIGNED_INT_8_8_8_8_REV); #else textureMap.SetType(GL_UNSIGNED_INT_8_8_8_8); #endif
The following code demonstrates the call to glTexImage2D() on Mac OS X:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, type, imageData);
Next (Cleaning Up)
Previous (Drawing the Texture)