OpenGL Lighting正常失败

时间:2014-05-12 09:11:36

标签: c++ opengl lighting normals fbx

我正在尝试在我的OpenGL场景中实现照明。我正在从正常文件加载FBX模型(由C4D生成)。但是光线看起来并不像我期待的那样。我在许多论坛上看,但没有任何相关结果。我启用了GL_NORMALIZE ... 这是一段代码:

glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
float specularm[] = {1.8,1.8, 1.8, 1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, specularm);
glMateriali(GL_FRONT, GL_SHININESS, 50);

float light_ambient[] = {0.0, 0.0, 0.0, 1.0};
float light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
float light_specular[] = {1.0, 1.0, 1.0, 1.0};
float position0[] = {0.0f, 50.0f, 0.0f, 1.0f};

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);

在绘图功能中:

(我使用VBO绘图)

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
...
glBindBufferARB(GL_ARRAY_BUFFER_ARB, geometry[model[m].gIndexes[g]].VBOName);
glVertexPointer(3, GL_FLOAT, 0, 0);
glNormalPointer(GL_FLOAT, 0, (void*)(geometry[model[m].gIndexes[g]].NumberOfPolygonVertexIndexes * 3 * sizeof(float)));
glTexCoordPointer(2, GL_FLOAT, 0, (void*)(geometry[model[m].gIndexes[g]].NumberOfPolygonVertexIndexes * 3 * sizeof(float)* 2));
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, geometry[model[m].gIndexes[g]].VBOIndices);
...
glDrawElements(GL_TRIANGLES, geometry[model[m].gIndexes[g]].usemtl[o].VertexCount, GL_UNSIGNED_INT, (unsigned int*)0 + LastVertex);

以下是问题的屏幕:

0 个答案:

没有答案