c++ - 使用GLM加载obj文件

标签 c++ opengl glsl

我在使用 GLM 库从 obj 文件加载纹理坐标时遇到一些困难

使用 OpenGL 3.3

http://www.cs.manchester.ac.uk/ugt/COMP37111/glm/glm.h http://www.cs.manchester.ac.uk/ugt/COMP37111/glm/glm.c

我的印象是,obj 文件将具有与纹理坐标相同数量的索引(无重复)顶点,然后“GLMtriangle:Struct”将包含索引纹理坐标数组的顶点“GLuinttindices[3]” “文本坐标”。然而,我发现的例子没有与顶点相同数量的纹理坐标。

根据上述理解,我尝试通过循环每个 GLMtriangle 并将索引纹理坐标添加到数组中,将所有纹理坐标放入数组中。为我提供每个顶点的纹理坐标。

基于 C++ 的伪代码。

for (the number of GLMtriangles)

    t= (the GLMtriangle index ) 

    //vertex0
    rawTextCoords[t] = GLMmodel->texcoords [GLMtriangle.tindices[0]];
    rawTextCoords[t+1] = GLMmodel->texcoords [GLMtriangle.tindices[0]+1];
    //vertex1
    rawTextCoords[t+2] = GLMmodel->texcoords [GLMtriangle.tindices[1]];
    rawTextCoords[t+3] = GLMmodel->texcoords [GLMtriangle.tindices[1]+1];
    //vertex2 
    rawTextCoords[t+4] = GLMmodel->texcoords [GLMtriangle.tindices[2]];
    rawTextCoords[t+5] = GLMmodel->texcoords [GLMtriangle.tindices[2]+1];
od

这是我当前的输出。

glm problem

最佳答案

您的示例伪代码至少看起来不错。

疯狂猜测:您没有将正确的值传递给glTexCoordPointer()(或glVertexAttribPointer())。如果输入速度太快,很容易将 sizetype 值弄错。从你的伪代码来看,size 需要是 2。

关于c++ - 使用GLM加载obj文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10267054/

相关文章:

c++ - 如何将bmp加载到GLubyte数组中?

c++ - 在 OpenGL 中加载 DDS DXT1,崩溃

c - 在窗口 OpenGL 中一起打印变量和多边形

java - GLSL 渲染纹理错误

c++ - 跨平台 C++ IDE?

c++ - 如何将非常量 int 作为模板参数传递?

c++ - OpenGL在GPU上构建和使用数据

c++ - 使用 binomial_heap 和 indirect_cmp

c++ - OpenGL 批处理渲染器中的纹理出血/损坏

c++ - 将任意数量值的顶点数组传递给 GLSL 顶点着色器