PDA

View Full Version : Texture problem



aQ
08-02-2005, 04:34 AM
some saying that OpenGL is a STATE machine:you change the state, then the state will change from now on.

I want to map texture on some object and some not(just using material),so when drawing the object WITHOUT texture, the LAST glBindTexture always interrupt it(make it using the last Texture)

so I want to draw object with texture with glEnable(GL_TEXTURE_2D)
and draw object without texture with glDisable(GL_TEXTURE_2D)

but It Can't work!

so i found that some glXXX(like glEnable) command affect the whole Opengl environment,not like the glColor just affect the next draw object

Am i right?

jide
08-02-2005, 04:42 AM
If you disable texturing (glDisable (GL_TEXTURE2D)) before drawing an object you want untextured, it should be drawn untextured and that even if the object you're drawing has specified texture coordinates.
Don't forget to re-enable texturing after.

OpenGL has a state machine. Look at the opengl specs on this website to know more about them. You can use glPushAttrib, glPushClientAttrib and their matching Pop*Attrib to 'play' with states.

Komat
08-02-2005, 04:05 PM
Originally posted by aQ:
so i found that some glXXX(like glEnable) command affect the whole Opengl environment,not like the glColor just affect the next draw object
Each object is drawn using OpenGL state that was active at time drawing command for that object was issued unless there is bug in driver. glEnable and glColor are working in same way in this regard.

glEnable(GL_TEXTURE_2D)
glColor3f( 0.0, 1.0, 0.0 )
draw object <- green textured object
glEnable(GL_FOO)
draw object <- green textured object with foo applied
glColor3f( 1.0, 0.0, 0.0 )
draw object <- red textured object with foo applied
glDisable(GL_TEXTURE_2D)
draw object <- red untextured object with foo applied
draw object <- red untextured object with foo applied
glColor3f( 0.0, 0.0, 1.0 )
draw object <- blue untextured object with foo applied
glDisable(GL_FOO)
draw object <- blue untextured object
glEnable(GL_TEXTURE_2D)
draw object <- blue textured object

avocados
08-02-2005, 05:34 PM
I'm not sure what the problem is but make sure you are not calling glDisable(GL_TEXTURE_2D) in between glBegin() and glEnd().

aQ
08-03-2005, 06:23 PM
yes
you right

My judgement was wrong

the glEnable(GL_TEXTURE_2D) actually affect the object untill the next glDisable(GL_TEXTURE_2D)

thanks all