• 13
• 18
• 19
• 27
• 10

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

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

## 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:
glPushMatrix();
glTranslatef(-LEG_WIDTH/2,-LEG_HEIGHT/2,+LEG_DEPTH/2);
glScalef(LEG_WIDTH,LEG_HEIGHT,LEG_DEPTH);
glutSolidCube(1.0);
glPopMatrix();

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);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);

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 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.