0

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();
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Anna Robin
  • 33
  • 3
  • already answered but see [How do I sort the texture positions based on the texture indices given in a Wavefront (.obj) file?](https://stackoverflow.com/a/51722009/2521214) for some more info – Spektre Jan 29 '20 at 08:59

1 Answers1

4

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]);
Rabbid76
  • 202,892
  • 27
  • 131
  • 174