Jump to content
  • Advertisement
Sign in to follow this  

glutSolidCube - can't see cube faces depending on light!

This topic is 3676 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 All, I am sure this is a pretty trivial problem but I can't seem to understand what the hell is happening. I am drawing this in my display function:
setting this lights in my init function:
GLfloat mat_specular[]={1.0, 1.0, 1.0, 1.0};
GLfloat mat_diffuse[]={1.0, 1.0, 1.0, 1.0};
GLfloat mat_ambient[]={1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess={100.0};
GLfloat light_ambient[]={0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[]={1.0, 0.0, 0.0, 1.0};
GLfloat light_specular[]={1.0, 1.0, 1.0, 1.0};
GLfloat light_position[]={10.0, 10.0, 10.0, 0.0};

glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess);

My problem is that depending on how much I rotate the scaled cube (or If I move the light) I can't see some of the faces of the cube! If you need more info I can post all my code - I thought before doing that I might give some hint so that if this rings any bell I can avoid posting the whole thing. Any help appreciated!

Share this post

Link to post
Share on other sites
As far as I know (could be wrong though ;) ), glutSolidCube only has one normal per face, and one face per side. The fixed function lighting in OGL is per vertex only, which means that you can only light up one face at a time. So chances are, if you want more accurate lighting, you need to either move to shaders and use per-pixel lighting, or use a cube with more polygons/normals.

EDIT: Also, remember that the sides of a cube are all 90 degrees from each other, which means that even with more accurate lighting, you sometimes get "binary lighting" (a side is either fully lit, or not lit at all) when the light is far away from cube and the camera is looking at certain points.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!