Archived

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

Textures change the color of my other objects!

This topic is 5152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!"

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites