# OpenGL Materials

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

## Recommended Posts

I need some clarifications about materials in OpenGL... what is the difference between glColorMaterial and glMaterial? As far as I understand, the first is somehow "lighter", and binds materials properties to a color (am I wrong?)... so, I think setting a color, means setting a material, if GL_COLOR_MATERIAL is enabled... if so, glMaterial needs instead to be called every time I have to switch a material... is it so? I am a bit confused about this... :( Maybe too many infos in too few days! :P

##### Share on other sites
Basically, you use glColorMaterial to select material properties that should be changed when calling glColor.

So, when you do lighting you could do like this to set the diffuse material property like this:
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

or, if you start by initializing like this:
glColorMaterial(GL_FRONT,GL_DIFFUSE);glEnable(GL_COLOR_MATERIAL);

you can then do the same with glColor:
glColor4fv(diffuse);

This can come in handy when using vertex arrays, for example, since there is no material array :)

It is also better to use glColorMaterial if you're not going to change many parameters each time. (It should be a bit faster, I think. And easier to read.)

##### Share on other sites
Now it's clearer, so, It means that if I need two objects with the same color, but with different materials, I should switch glColorMaterial to the desidered one... let's say I have a "steel" red cube and a "plastic" red sphere... before rendering the second element, I need to change the glColorMaterial... but, if I have different objects with the same color and the same material, I can avoid glColorMaterial calling, is it right? Or better, I could initialize all my materials at the beginning associating them to a color, and then I could simply draw the scene with the correct color... am I right?

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 13
• 17
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632962
• Total Posts
3009506
• ### Who's Online (See full list)

There are no registered users currently online

×