Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How and when to use glMaterial?

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

Hi Sorry if this has been done before, but I can''t get my head round when I can use glMaterial. I have calls to glMaterial just before my objects vertices are drawn. Great! I can see the object no problem, but I don''t get any lighting effects. Yes lighting is enabled and setup (I used an example from online Red Book). Is there something else that needs to be enabled? Any tips/advice would be most welcome.

Share this post

Link to post
Share on other sites
Enabling lighting isn''t sufficient. You also need to define
the normals for your surfaces.
Without them you won''t see any lighting in your scene.

Share this post

Link to post
Share on other sites
I am loading an OBJ file that has the normals defined. and in my rendering code I am also making the call to glNormal along with glTexCoord etc. Here is an extract

if(ptrTIndex != NULL) glBindTexture(GL_TEXTURE_2D, GLtextures[texture_id]);

if (ptrNIndex != NULL)

The lighting is set up as follows:-

GLfloat Ka[] = {0.5000f, 0.5000f, 0.5000f, 1.0f};
GLfloat Kd[] = {0.7000f, 0.7000f, 0.7000f, 1.0f};
GLfloat Ks[] = {1.0000f, 1.0000f, 1.0000f, 1.0f};
GLfloat lightpos[] = { 0.30f, 3.0f, 1.0f, 0.0f };

glLightfv(GL_LIGHT1, GL_AMBIENT, Ka);
glLightfv(GL_LIGHT1, GL_DIFFUSE, Kd);
glLightfv(GL_LIGHT1, GL_POSITION, lightpos);


I thought that this would be enough. I mean I can see the object, no problem. Its just when I rotate it I do not see any light effects as it rotates.

Thanks in advance.

Share this post

Link to post
Share on other sites
You need to be carefull when to setup your lights since lights in OpenGL are affected by modelview transformations. So when you rotate your object and the light follows you won''t see any lighting effects...

Hope this helps!


Share this post

Link to post
Share on other sites

  • 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!