glTexImage2D Trick

Discuss programming topics that involve the OpenGL API.
Post Reply
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

glTexImage2D Trick

Post by mh »

Say you're creating a texture object but you don't have the data for it yet. You might think that you need to allocate a dummy buffer of the right size, but you actually don't. Just give glTexImage2D a NULL pointer and it will happily create the texture for you.

It's all there in the documentation (http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml).
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

In GL version 1.1 or greater, data may be a null pointer.
In this case, texture memory is allocated to accommodate a texture of width width and height height. You can then download subtextures to initialize this texture memory.
The image is undefined if the user tries to apply an uninitialized
portion of the texture image to a primitive.
When they say 'download' are they referring to selecting a texture already in an array?
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

they mean uploading a section of a larger texture.
Post Reply