Skip to main content
gamedev.net
🔒 Locked

Materials

Started by BladeWise Jun 16, 2005 at 4:39 PM 1 replies 1.2k views
Original Post
BladeWise
BladeWise
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
TomasH
TomasH
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.)
BladeWise
BladeWise
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.