有人可以解釋我爲什麼除了以下行OpenGL是否需要法線才能製作陰影?
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, 0);
代碼
glewInit();
glEnable (GL_LIGHTING) ;
glEnable (GL_COLOR_MATERIAL) ;
glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) ;
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_GREATER);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glClearDepth(0);
GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER,vertexbuffer);
glBufferData(GL_ARRAY_BUFFER,sizeof(float)*Loader.verticesFixed.size(),&Loader.verticesFixed[0],GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
12, // stride
(void*)(0) // array buffer offset
);
glDrawArrays(GL_TRIANGLES,0,Loader.verticesFixed.size()/3);
到這個模型的陰影:
我沒有提供任何正常數據,我被告知OpenGL不計算法線。但是,我怎麼才能在模型上獲得適當的陰影效果?我錯誤地認爲陰影需要法線或者OpenGL計算法線嗎?
非常有趣的解釋。謝謝。 –