Jump to content
  • Advertisement
Sign in to follow this  
Hauptman

OpenGL glColor and glBindTexture

This topic is 4465 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! I got a small problem with OpenGL: Say I render two objects in my scene: The first one, a simple triangle, colored with glColor to any color I want. The next object another triangle (or quad) with texture coordinates and a glBindTexture. However, OpenGL seems to take the color of my first object and then it biases the color of my texture to the color of my first object. So if I set my first object to red and render my second object the texture is biased with red. The code is fairly simple.
glTranslatef(1.5f,0.0f,0.0f);
	glColor3f(1.0f,0.0f,0.0f);
	glBegin(GL_QUADS); // this quad is rendered red
		glVertex3f(1.0f,1.0f,0.0f);
		glVertex3f(-1.0f,1.0f,0.0f);
		glVertex3f(-1.0f,-1.0f,0.0f);
		glVertex3f(1.0f,-1.0f,0.0f);
	glEnd();

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,texture[0]);
	glTranslatef(-2.5f,0.0f,0.0f);
	glBegin(GL_QUADS); // this quad is rendered with a texture but the textured is biased with a red color
		glTexCoord2f(1.0f,1.0f); glVertex3f(1.0f,1.0f,0.0f);
		glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f,1.0f,0.0f);
		glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f,0.0f);
		glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,-1.0f,0.0f);
	glEnd();
Maybe just a glEnable? I looked through the MSDN but I didn't found anything that could possibly make this bias disappear.

Share this post


Link to post
Share on other sites
Advertisement
If I add a glColor3f(0.0f,0.0f,0.0f) between the two lines the textured quad isn't showing up anymore and my red quad is darker ... -.-

Share this post


Link to post
Share on other sites
Quote:
Original post by Morrandir
Change the color to black, that way no additional color will be added to your textures.


Actually, you need to change the color to white. Otherwise, you will get no color at all.

Share this post


Link to post
Share on other sites
Ooops, I guess my OpenGL got a bit rusty... Sorry for the misinformation. It should work with white, as Dave pointed out.

Share this post


Link to post
Share on other sites
Dave Hunt is right on the ball. [smile]

This is because OpenGL does not work on a per-drawn-object basis, but rather a state machine. If you set the colour to red, it will apply (1,0,0) to everything pushed through the pipeline until you change it. Like Dave said, (1,1,1) white multiplies each R/G/B component by 1, thus not changing it from its original colour at all.

EDIT: Shoot, everyone posts so quickly. :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!