How do I unbind Textures?

Started by
8 comments, last by Roquqkie 19 years, 2 months ago
Hello, In my OpenGL game, after I perform a glBindTexture, I draw some polygons and the texture appears just fine. Now if I want to draw another polygon without any texture, how do I do this? Is there a way to unbind the texture being used? Thanks, Ryback
Advertisement
glBindTexture(GL_TEXTURE_2D,0); // will this work?

glDisable(GL_TEXTURE_2D); // this will work
glDisable ?
Quote:Original post by Anonymous Poster
glDisable ?


its the oposite of glEnable();
Quote:Original post by mike25025
glBindTexture(GL_TEXTURE_2D,0); // will this work?

glDisable(GL_TEXTURE_2D); // this will work


Thanks, it 'sorta' works. Perhaps the problem is something else. After drawing the textured polygons, I am drawing some lines on the screen. Before the lines would be the color of the previously used texture. If I unbind it with glDisable(GL_TEXTURE_2D) then the lines are white. I am trying to draw red lines with glColor3f(1.0,0.0,0.0) but they are always drawn white.

Quote:Original post by Ryback

Thanks, it 'sorta' works. Perhaps the problem is something else. After drawing the textured polygons, I am drawing some lines on the screen. Before the lines would be the color of the previously used texture. If I unbind it with glDisable(GL_TEXTURE_2D) then the lines are white. I am trying to draw red lines with glColor3f(1.0,0.0,0.0) but they are always drawn white.


Is lighting enabled?
If so, you could enable GL_COlOR_MATERIAL...
Or, you could disable lighting (glDisable(GL_LIGHTING)) while drawing the lines..
Quote:Original post by dotproduct
Is lighting enabled?
If so, you could enable GL_COlOR_MATERIAL...
Or, you could disable lighting (glDisable(GL_LIGHTING)) while drawing the lines..


Bingo. It was the lighting. Thanks for the help!
I can't remember what the function is, but OpenGL lighting supports making the material color of something that is lighted the current OpenGL drawing color. You wouldn't have to turn off lighting in this case if you want something affected by lighting and want to change the color. Sorry I just remembered.
glEnable(GL_COLOR_MATERIAL);
If you call this, then the colors work like you expect them to, even with lighting.


Quote:Original post by kburkhart84
I can't remember what the function is, but OpenGL lighting supports making the material color of something that is lighted the current OpenGL drawing color. You wouldn't have to turn off lighting in this case if you want something affected by lighting and want to change the color. Sorry I just remembered.
glEnable(GL_COLOR_MATERIAL);
If you call this, then the colors work like you expect them to, even with lighting.


As an addendum to that...

glColorMaterial lets you specify which faces (front/back/both) the color material is set to, and also which material properties to apply it to.
People tend to forget the fact that OpenGL is a state-machine.
When you bind a texture, it will be bound until you bind another texture or you simply disable texturing.
Keeping in mind that you're working with a state-machine, really simplifies much of your work and prevents it from being very error-prone.

Best regards
Roquqkie

This topic is closed to new replies.

Advertisement