0

我正在尝试渲染一些带有单个纹理的网格,结果很奇怪,可能是因为 UV 数据的步幅参数不正确。

我省略了 glGenBuffers 和绑定调用。

我以这种方式打包数据:

float (*vertices)[3];     //list of vertices
int   nvertices;
unsigned int (*indices)[3]; //one row define indices for a triangle
int   nindices;
float (*texuv)[6];          //one row defines 3 UVcoord for the 3 triangle vertices

我设置数据:

  glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*nvertices, vertices, GL_STATIC_DRAW);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(float)*nindices*3, indices, GL_STATIC_DRAW);
  glBufferData(GL_ARRAY_BUFFER, sizeof(float)*nindices*6, texuv, GL_STATIC_DRAW);

我画它:

glVertexAttribPointer(position_slot,3,GL_FLOAT,GL_FALSE,sizeof(float)*3,0);
glVertexAttribPointer(texcoord_slot,2,GL_FLOAT,GL_FALSE,sizeof(float)*6,0);

glDrawElements(GL_TRIANGLES,nindices*3,GL_UNSIGNED_INT,0);

但结果在纹理级别似乎有点奇怪......

你会建议我如何将我的 UV 数据提交给着色器或如何以更实用的方式重新格式化?

4

0 回答 0