2012-04-22 50 views
2

我有一些困难,使用GLM库使用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文件纹理COORDS在装入一个OBJ文件将具有相同数量的索引(无重复)vertexs作为纹理COORDS的那么“GLMtriangle:结构”将包含vertexs“GLuint tindices [3]”该索引texturecoord阵列“texcoords”。但是我发现的例子没有与顶点相同数量的纹理坐标。

使用上述认识我试图通过每个GLMtriangle循环和添加索引的纹理COORDS到一个数组把所有纹理COORDS中的数组。给我一个每个顶点的纹理坐标。

基于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

+1

,你有没有使用一个实际考虑[处理网呢?(http://assimp.sourceforge.net/)。 Open Asset将网格正确设置为三角形,可以上传和渲染。 – 2012-04-22 10:34:21

+0

我加载来自同一OBJ装载机的vertexs和指数法,我不得不使用GLM OBJ装载机分配 – Andrew 2012-04-22 10:41:52

+0

在我看来,'GLMmodel'表示数据相当原始。你不能使用顶点索引来查找tex坐标。你需要tex索引('tindices')。 – 2012-04-22 10:51:01

回答

2

你的样本伪代码至少看起来声音。

疯狂的猜测:你没有通过适当的值glTexCoordPointer()(或glVertexAttribPointer())。如果键入的速度过快,则很容易得到sizetype值错误。从你的伪size需要既然你已经使用网状装载机为2

+0

IM几乎是100%肯定,我的缓冲是好的我只是我vertexs后缓冲他们,你随时随地知道,有一个可行的sphere.obj?我使用的讲座有一个不同数量的纹理坐标到顶点看起来不对。 – Andrew 2012-04-22 14:58:12

+0

这非常好。面向索引到顶点和tex坐标和什么不是数组,甚至可能有三个以上的顶点;那么你需要三角测量。 – 2012-04-22 19:12:24