PDA

View Full Version : Changing, reload or unbinding textures



SenSej
10-22-2008, 08:16 AM
Hello there,

got several quads to paint. For each, itīs own texture image is stored in an vector. How many quads are to paint is given by the size of this image vector.



for (int i=0; i < images.size(); ++i)
textures[i] = bindTexture(images[i], GL_TEXTURE_2D);


In my newbee understanding, now the images are transformed in textures and are thrown into the graphic cardīs buffer. Am i right?

How to delete or replace one of this texture choosen by index i, like


textures.removeAt[i];
texture[i] = bindTexture(new_or_changed_Image, GL_TEXTURE_2D);
since
GLuint* textures is used and typicall stl methods are not available?

I donīt want to
glDeleteTextures(all, textures)
and
bindTextures(images[i], GL_TEXTURE_2D)
again, when just repainting the scene, without anything changed in images[]??

Some ideas? Thanks for you hints in advance.

dletozeun
10-22-2008, 09:42 AM
for (int i=0; i < images.size(); ++i)
textures[i] = bindTexture(images[i], GL_TEXTURE_2D);


What is this? What does bindTexture do? It does not look like the regular glBindTexture function.

To load and use a 2D texture in opengl you need to:

1) Load image data into system memory
2) Generate a texture name with glGenTextures
3) Bind the texture name with gBindTexture
4) call glTexImage2D with the right parameters depending on the image nature to load image data into video memory
5) Set wrapping and filtering mode with glTexParameter

Finally just bind the texture before drawing it onto a quad.

Look at opengl man pages (http://www.opengl.org/sdk/docs/man/) for more information about all these functions.

SenSej
10-22-2008, 09:59 AM
bindTexture
comes from QT.

Iīm already able to map the textures and show them.
The delete one texture afterwards issue is more important.

But thanks for your reply.

dletozeun
10-22-2008, 10:13 AM
To replace texture data, just bind the texture and call glTexImage2D with the new data.

bindTexture, at least the opengl one, just binds a texture name to a specific target, GL_TEXTURE_2D here. It does not delete or replace anything, just put a particular texture in use.

Calling glDeleteTextures will delete specified texture names, then the allowed video memory will be set free by the driver and the texture name free to reuse.

SenSej
10-22-2008, 01:45 PM
"Calling glDeleteTextures will delete specified texture names,..."

Same in QT - and this was the problem.

Iīve used bindTexture together with glDeleteTextures, so the QT and the OpenGL functions together. Obviously this is going to crash.

So i replaced glDeleteTextures with QTīs deleteTexture and done.

Thanks again!