Textures change the color of my other objects!

Started by
6 comments, last by BigDaddyDrew 20 years, 5 months ago
Hi guys, I''m a brand newbie to this forum, and a slight newbie to OpenGL. I have a textured background, and an simple block in front of it. When I change the texture to something else, it alters the color of my object. My object is supposed to be a goldish color. For example, I have a red brick texture in the background. It makes my object appear red. When I run the program again, with, say, a blue marble texture, my object now looks blue! Any ideas?
Advertisement
OpenGL is a state machine, what state you set gets left active until you change it. Odds are you''re drawing your object with vertex colours, but after you drew the textured background you forgot to glDisable(GL_TEXTURE_2D).
You might have texturing turned on when drawing your block.

Try turning off texturing by calling:

glDisable(GL_TEXTURE_2D); 


prior to drawing your block.

Bob



Thanks for the replys guys,

That did the trick, but now I''m faced with the opposite problem: The color of my block influences the color of my texture. I wrapped my block-drawing calls with glEnable(GL_COLOR_MATERIAL) and glDisable(GL_COLOR_MATERIAL), but that didn''t do the job.

Any more advice?!

Thanks!
You could use the dirty trick I use. After I draw my objects that have different colored vertices I add the line glColor4f(1.0f, 1.0f, 1.0f, 1.0f) as the last gl call (Besides glPopMatrix() if I use it). It reset's it back to white so it wont change the color of your vertices for the next object.

void Render()
{
glColor4f(Red, Green, Blue, 1.0f);
DrawObject();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}

It's dirty, but it works for now. Not every object you draw is going to modify the glColor4f or glColor3f function. So when you come to an object and you forget to set the color back, you're going to run into problems like this.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on November 10, 2003 1:30:38 AM]
Heh, thanks.

So yes, that does work...but there must be a legit way to do it? (I''m not suggesting your method is illegitimate, just that it probably isn''t the intended way!)

Thanks!
Like I said, it''s a dirty trick lol. It works though

(If anyone does know a legit way, could you please let us know )

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"
There''s nothing dirty about using glColor... However, just for clarity you should put it right before you draw something that requires the color change (along with any other per-object state changes).

In this case, you''d want to put glColor4f(1,1,1,1); and glEnable(GL_TEXTURE_2D); right before drawing your background (because you want to use a texture and white vertex colors).

This topic is closed to new replies.

Advertisement