I’m using the glmaterial to change the colour of objects in a scene in openGl. The problem is that I want to change the colour of one object, but end up changing the colour of all objects in the scene. I used glPushMatrix and glPopMatrix, but it didn’t help.
Hope you can help me,
glPushMatrix and glPopMatrix, as the names suggest, operate on matrices. Matrices do not affect color.
Just use whatever function you’re using to change object color, but set it back after you’ve rendered the object.
Thanks for the reply Alfonse,
You are right. But the thing is that I have several objects in the scene. Fore example, I have an object standing on a ground and I only want to change the colour this object. The glMaterial will cause the colour of both (object& ground) to change.
How to overcome that?
Change the color. Render the object you want to render in that color. Then change the color to the next object’s color. Render that object. Keep doing that until you’re out of objects.