Archived

This topic is now archived and is closed to further replies.

CoMaNdore

weird colors ?

Recommended Posts

CoMaNdore    223
When I load a image using the : glTexImage2D() function my colors fuc* up... So that the color 255,255,255 aint white anymore but some kind of light blue/green color. When i remove the call to glTexImage2D() i get normal colors again. Anyone got any ideas ?

Share this post


Link to post
Share on other sites
Enigma    1410
OpenGL is a state machine. When you enable texturing it remains enabled until you disable it. When you specify a texture coordinate it applies to all subsequent vertices until you change it. So:

glEnable(GL_TEXTURE_2D);
// try to draw textured quad

glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(1, 0);
glTexCoord2f(1, 1);
glVertex2f(1, 1);
glTexCoord2f(0, 1);
glVertex2f(0, 1);
glEnd();
// try to draw coloured quad

glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glVertex2f(2, 0);
glVertex2f(3, 0);
glVertex2f(3, 1);
glVertex2f(2, 1);
glEnd();


is actually equivalent to:

glEnable(GL_TEXTURE_2D);
// try to draw textured quad

glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(1, 0);
glTexCoord2f(1, 1);
glVertex2f(1, 1);
glTexCoord2f(0, 1);
glVertex2f(0, 1);
glEnd();
// try to draw coloured quad

glEnable(GL_TEXTURE_2D); // texturing still enabled

glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); // last texture coord repeated

glVertex2f(2, 0);
glTexCoord2f(0, 1); // last texture coord repeated

glVertex2f(3, 0);
glTexCoord2f(0, 1); // last texture coord repeated

glVertex2f(3, 1);
glTexCoord2f(0, 1); // last texture coord repeated

glVertex2f(2, 1);
glEnd();


So your coloured quad is actually textured with a single texel from your texture.

The solution, as stated by Trienco above, is to disable texturing for any objects you don''t want textured.

Share this post


Link to post
Share on other sites