Next | Prev | Up | Top | Contents | Index

Using Null Images With Subtextures

It is sometimes useful to define the parameters of a texture image without actually initializing the contents of that image. For example, if you want to load a frame of an NTSC video as a texture, you need to first define a region larger than the video frame that meets the height and width requirements of textures (power of 2). Null images are also useful when you want to first define the parameters of a texture and later initialize the texture image using glTexSubImage*() calls.

To create a null image, call one of the texture creation functions, for example, glTexImage2D() with pixels set to the null pointer. The specified texture is created, but no pixels are processed. Using an uninitialized part of a texture yields undefined results.

The following code fragment creates a null image texture, then loads a subimage:

{
/* need to initialize "image" to something interesting */
    static unsigned char image[32][32][4]; 
/* create a 256 x 256 null texture */
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_EXT, 256, 256, 0,
                 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
/* load a 32 x 32 subimage starting at 100,110 */
    glTexSubImage2DEXT(GL_TEXTURE_2D, 0, 100, 110, 32, 32,
                       GL_RGBA, GL_UNSIGNED_BYTE, image);
} 

Next | Prev | Up | Top | Contents | Index