OpenGL:立方体形状上缺少阴影

时间:2013-10-16 07:54:08

标签: opengl shadows light

当我使用数组:

时,为什么阴影从我的立方体形状的未被照亮的面消失
vertices[] 
indices[] 
colors[] 
normals[] 
texcoords[] 
// and draw them by
glDrawElements();

但是当我使用时:

glBegin(...);
 glVertex3f(...);
glEnd(...); 

阴影还可以。 在这里,您可以看到正在发生的事情:IMG

我的灯光设置如下:

glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);        
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

GLfloat AmbientLight[] = {0.0, 0.0, 0,0, 1.0};
GLfloat DiffuseLight[] = {1.0, 1.0, 1,0, 1.0};
GLfloat SpecularLight[] = {1.0, 1.0, 1.0, 1.0};
GLfloat Shininess[] = { 90.0 };
GLfloat Emission[] = {0.0, 0.0, 0.0, 1.0};

glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularLight);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, AmbientLight);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, DiffuseLight);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SpecularLight);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, Shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);

1 个答案:

答案 0 :(得分:0)

您可能错过了对

的调用
glEnableClientState( GL_NORMAL_ARRAY );