Jump to content
  • Advertisement
Sign in to follow this  
BladeWise

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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?

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!