Sign in to follow this  
Gazoo

[SOLVED] glEnable and glDisable

Recommended Posts

Hey Forum-dudez, Been a while since I posted - but then again - it's been a while since I messed around with Graphics... However, now I've done it, and I'm for another long graphics haul... But I digress - something has been bothering me for a while - for which I have no clear answer: I use glEnable to enable GL_TEXTURE_2D, GL_TEXTURE_3D, and GL_TEXTURE_RECTANGLE_ARB (I'm not sure about the non-ARB version). Right now I am under the assumption that I only need to call glEnable on these handles right before I render, and call glDisable right after I am done rendering with them... However - I've seen other posts and examples enabling these handles multiple times after selecting a new active texture... I am under the impression that the enable calls change the graphics pipeline to include these features in general and do not need to be enabled per texture... Can someone either confirm or deny this? So far my googelings have not helped me understand the matter further. Answers and especially explinations are very welcome! Regards, Gazoo [Edited by - Gazoo on July 22, 2009 5:58:36 AM]

Share this post


Link to post
Share on other sites
Does OpenGL not simply use the texture units the texture is bound to when it is both created and bound?


glTexImage3D( GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );
glBindTexture(GL_TEXTURE_3D, 0);


Your short answer hints at something I am not understanding... But I am too stupid to understand what... Further explination would be much appreciated.

Share this post


Link to post
Share on other sites
Say you want to use multi texturing with three textures.

glActiveTexture(GL_TEXTURE0); // select texture unit 0
glBindTexture(GL_TEXTURE_2D, texA[0]); // bind texture ID texA[0] to the selected texture unit

glActiveTexture(GL_TEXTURE1); // select texture unit 1
glBindTexture(GL_TEXTURE_2D, texA[1]); // bind texture ID texA[1] to the selected texture unit

glActiveTexture(GL_TEXTURE2); // ... and so on
glBindTexture(GL_TEXTURE_2D, texA[2]);

The array texA[0..2] contains the texture ID:s for the textures you want to bind to texture unit 0, 1 and 2 when drawing object A.

This was my question; without explicitly enabling texturing for all three texture units, how is OpenGL supposed to know what texture units to use? You could say; three texture units, because we have bound textures to three texture units. But then, what happens when you draw object B, which uses only two textures.

glActiveTexture(GL_TEXTURE0); // select texture unit 0
glBindTexture(GL_TEXTURE_2D, texB[0]); // bind texture ID texB[0] to the selected texture unit

glActiveTexture(GL_TEXTURE1); // select texture unit 1
glBindTexture(GL_TEXTURE_2D, texB[1]); // bind texture ID texB[1] to the selected texture unit

Again, what texture units shall OpenGL use? Keep in mind that texA[2] is bound to texture unit 2 still from last object.

So unbind the textures you don't need? The problem is that there is no way to unbind a texture to a state that no texture at all is bound. As soon as you call glBindTexture on an unused name, the name is associated with a newly created texture object. So whatever name you bind, it will always map to a texture object. The default name, zero, is actually the name of the default object, which is a perfectly valid texture to use, so you cannot indicate no texture by binding ID 0 either.

Therefore, since there is no way to indicate texture or no texture, you use enable and disable to turn units on and off.

Share this post


Link to post
Share on other sites
Thank you Brother Bob - So essentially, you're telling me that it IS necessary to write:

glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);

...

for each Texture that I no long wish to use, because there is no call such as:

glDisableActiveTexture(GL_TEXTURE0);

Correct?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this