Search code examples
delphiopengl3dwavefrontopengl-compat

.OBJ OpenGL wrong render


anybody knows, why it happen? A try to render OBJ file with Opengl.

enter image description here

  // (0 - индекс вершины / 1 - индекс текстурной координаты / 2 - индекс нормали)
  for i := 0 to length(faces) - 1 do
  begin
    glBegin(faces[i].mode);
    Count := length(faces[i].data);
    for k := 0 to Count - 1 do
    begin
      glNormal3fv(@normals[faces[i].data[k].normalIndex]);
      glTexCoord2fv(@texcoords[faces[i].data[k].texCoodIndex]);
      glVertex3fv(@vertexes[faces[i].data[k].vIndex]);
    end;
    glEnd();

Solution

  • Wavefront OBJ start at 1. So you have to subtract 1 from each index:

    glNormal3fv(@normals[faces[i].data[k].normalIndex - 1]);
    glTexCoord2fv(@texcoords[faces[i].data[k].texCoodIndex - 1]);
    glVertex3fv(@vertexes[faces[i].data[k].vIndex - 1]);