Jump to content
  • Advertisement
Sign in to follow this  
BradDaBug

Can't disable GL_COLOR_MATERIAL

This topic is 4844 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

I'm drawing a bunch of cubes, one of the cubes being "highlighted." I'm trying to set the color of the cube to a higher value than the rest of them, but the problem is as soon as I enable GL_COLOR_MATERIAL I can't get it to turn off, and all the cubes are highlighted and lighting info is thrown away. glDisable(GL_COLOR_MATERIAL) seems to have absolutely no effect.
int CBox::Draw(bool highlighted)
{
	const real * quat = CPhysics::GetBodyQuaternon(body);
	const real * pos = CPhysics::GetBodyPosition(body);
	
	// convert the quaternion to axis and angle
	float angle = 2 * acos(quat[0]);

	glPushMatrix();

	glTranslatef(pos[0], pos[1], pos[2]);
	glRotatef(angle * 57.2958279, quat[1], quat[2], quat[3]);
	glScalef(sizex, sizey, sizez);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glNormalPointer(GL_FLOAT, 0, normals);


	if (highlighted)
	{
		glEnable(GL_COLOR_MATERIAL);
		glColor3f(1, 0.5, 0.5);
	}
	else
	{
		glDisable(GL_COLOR_MATERIAL);
	}

	glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, indices);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	glPopMatrix();

	return 0;
}
What am I doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

#14

What's happening is this.
OpenGL is a state machine - as soon as you set GL_COLOR_MATERIAL it loads the current color as a material. But disabling GL_COLOR_MATERIAL won't unload that state - it just prevents future glColor calls from affecting the material state. You'll need to manually change the state to make highlighting go away.

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!