【问题标题】:.OBJ OpenGL wrong render [closed].OBJ OpenGL错误渲染[关闭]
【发布时间】:2020-05-12 07:41:46
【问题描述】:

谁知道,为什么会这样?尝试使用 Opengl 渲染 OBJ 文件。

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

【问题讨论】:

标签: delphi opengl 3d wavefront opengl-compat


【解决方案1】:

Wavefront OBJ 从 1 开始。所以你必须从每个索引中减去 1:

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

【讨论】:

  • 令人惊讶的是,解析 obj 文件的代码没有进行调整
  • @DavidHeffernan 这是许多语言的许多不同波前解析器中的常见问题。
  • 就好像解析器的作者从来没有费心写代码来渲染模型!
猜你喜欢
  • 2013-04-16
  • 2014-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-10
  • 2013-12-11
  • 2012-09-13
  • 1970-01-01
相关资源
最近更新 更多