PDA

View Full Version : undesired results of texture binding



Old GLman
03-21-2002, 10:07 AM
Ok, Im rendering some font on the screen using texture mapped quads. Now when I start introducing other primitives into my scene, binding other textures onto them, my texture mapped font quads just go all black.

If I comment out the glBindTexture that binds a texture to my other primitives, my font returns to legible text. Does anyone have an idea of what is happening?

Old GLman


[This message has been edited by Old GLman (edited 03-21-2002).]

Korval
03-21-2002, 11:30 AM
Did you re-bind the font texture when you start drawing your font quads?

Old GLman
03-21-2002, 11:40 PM
Korval, thanks for your reply. The problem is not how I bind the textures, but how I'm generating texture objects. Im using a structure similar to the one found on NeHe, which has variable unsigned int texID. Lets call my texture structure TEXTURE. I declare
an array for 3 textures: TEXTURE tex[3].
So each texture is identified by tex[i].texID, where i is the desired texture. How do I pass this to glGenTextures so it will generate 3 textures in one call? It works fine if I bind each texture seperatley, but I should be able to do them all in one call right? I hope this makes sense. Thanks

[This message has been edited by Old GLman (edited 03-22-2002).]

Brent Fogarty
03-22-2002, 12:57 AM
You must bind each texture before creating it, it is fine to generate multiple texture names at once (glGenTextures) but when you create the texture you must bind it before you call your load texture function.

glBindTexture(GL_TEXTURE_2D, tex[0].ID);
LoadTexture("tex0.tga");

glBindTexture(GL_TEXTURE_2D, tex[1].ID);
LoadTexture("tex1.tga");

glBindTexture(GL_TEXTURE_2D, tex[2].ID);
LoadTexture("tex2.tga");

hope that fixes your problem, don't forget to rebind them when you need to use them, also don't forget to disable(GL_TEXTURE_2D) when drawing things which shouldn't be textured.

Old GLman
03-22-2002, 08:12 AM
Brent thanks for the info. My problem is that I dont believe glGenTextures is parsing the array im passing it correctly. Sorry, maybe I wasnt clear enough in the above post http://www.opengl.org/discussion_boards/ubb/smile.gif Hope this makes more sense now

Old GLman

Elixer
03-22-2002, 09:29 AM
Post a code snippet then.

If you did like what Brent said, then in your rendering loop, have something like:

glBindTexture(GL_TEXTURE_2d,tex[0].texid);
draw...
bind the next texture
draw...
and so on, and you might want to throw in some push/pop matrix commands depending on what exactly you are doing, hence the request for code snippet.

Old GLman
03-22-2002, 10:03 AM
Ok, my problem has nothing to do with glBindTextures. I mentioned this in my prior posts. It has to do with glGenTextures. You should be able to pass it an array and let it generate texture objects right? In other words I should only have to call glGenTextures once. Sorry for being abrupt, but I'm wondering if you even read my prior posts in full. Right now I'm doing this:

glGenTextures(1,&tgaimage[0].texID);
glGenTextures(1,&tgaimage[1].texID);
glGenTextures(1,&tgaimage[2].texID);

tgaimage is my structure that holds all my texture information. texID is the indentifier. It works correctly if I do it this way, but it's not correct. I want to be able to do this:

glGenTextures(3,&tgaimage[0].texID);

so it will generate all the texture objects in one call. My understanding is that glGenTextures will go through an array and generate texture names.

Old GLman


[This message has been edited by Old GLman (edited 03-22-2002).]

zeckensack
03-22-2002, 10:22 AM
No.

OpenGL knows nothing about the layout of your structures and there's no way you can change that. You can do this


uint tex_object_id[3];
glGenTextures(3,tex_object_id);
for (int i=0;i<3;++i)
{
your_array[i].texID=tex_object_id[i];
}
But you won't get any closer.

Old GLman
03-22-2002, 10:49 AM
Hi, yeah I thought of that. I guess I was just hoping for a cleaner solution. That will work though, thanks for the info.

Old GLman


[This message has been edited by Old GLman (edited 03-22-2002).]

03-23-2002, 04:13 AM
Hi,
I did a programm in which I didn't use glBindTexture()...every time I change the texture using glTexImage2D...so...glBindTexture() is used to avoid repeating every time glTexImage bla bla bla or there are other functions?
Thank you

zeckensack
03-23-2002, 05:34 AM
Originally posted by Sbronz:
Hi,
I did a programm in which I didn't use glBindTexture()...every time I change the texture using glTexImage2D...so...glBindTexture() is used to avoid repeating every time glTexImage bla bla bla or there are other functions?
Thank you

Strange to ask a question at the end of a topic, but here you go:
Texture objects (glGenTextures, glBindTexture) do exactly that. When you bind a texture object, all further changes to the texturing state - including the texture image itself, wrap modes, filtering modes and lod ranges - are remembered. If you bind a new texture object later and make changes to that 'state', you can quickly recall the older texture by binding the first texture object again.

You should really use them, they save you (and your driver too!) a lot of hassle. For a more technical explanation, read the EXT_texture_object spec (http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_object.txt) . This has been included into version 1.1 of the core OpenGL spec, so you don't need to do any extension loading to use it.

03-25-2002, 12:02 AM
thank you