0

I am trying to implement lighting in my OpenGL scene. I am loading FBX model from file with normals (Generated by C4D). But the light doesn't look as I was expecting. I was looking on many forums, but wihout any relevant result. I have GL_NORMALIZE enabled... Here is a code snippet:

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

In draw function:

(I'm using VBO for drawing)

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

Here is a screen of the problem:

logain
  • 1,475
  • 1
  • 12
  • 18
ProXicT
  • 1,903
  • 3
  • 22
  • 46
  • You shouldn't use specular material parameters > 1. Change them to 1 and see if that's the problem. – Nico Schertler May 12 '14 at 09:24
  • Thanks for the quick reply. But still the same problem :/ – ProXicT May 12 '14 at 09:27
  • Are you sure that your offset calculations are correct? `NumberOfPolygonVertexIndexes` does not sound like "the total number of vertices in the buffer". And are you sure that the normals are correctly exported? – Nico Schertler May 12 '14 at 09:43
  • Normals are wrong. Check data you feed to VBO at exactly specified offset. [even better, use interleaved arrays, but that's not relevant to the question] – keltar May 12 '14 at 09:56
  • `NumberOfPolygonVertexIndexes` is really the total number of vertices in the buffer. I am 90% sure, that the normals are exported correctly, because when I import the model in any 3D editor, it is behaving as it should. – ProXicT May 12 '14 at 16:56
  • You were right guys, it was really in VBO...Just one letter was wrong in my variable name, I've got 2 variables, one is `onormals` and the other is just `normal`...bad mistake. Thank you for your help :) – ProXicT May 12 '14 at 17:19

0 Answers0