opengl顶点数组贴图的问题
之前顶点数组这一块完全是自己在摸索,现在发现没人指导一下完全做不下去了。。。
所以可能程序和提问都有点小白,请大神轻喷。。。。
问题:贴图的数组怎么对应索引呢?代码如下,有两个面的贴图是乱的。。。。
还有就是要用多重纹理的话,该如何写呢。。。。
static const GLfloat vertex_list[][3] = {
-10.0f, -10.0f, -10.0f,
10.0f, -10.0f, -10.0f,
-10.0f, 10.0f, -10.0f,
10.0f, 10.0f, -10.0f,
-10.0f, -10.0f, 10.0f,
10.0f, -10.0f, 10.0f,
-10.0f, 10.0f, 10.0f,
10.0f, 10.0f, 10.0f,
};
static const GLfloat texCoord_list[][2] = {
0.0f,0.0f,
1.0f,0.0f,
1.0f,1.0f,
0.0f,1.0f,
1.0f,0.0f,
1.0f,1.0f,
0.0f,1.0f,
0.0f,0.0f,
};
static const GLint index_list[][4] = {
4, 5, 7, 6,
0, 2, 3, 1,
2, 6, 7, 3,
0, 1, 5, 4,
1, 3, 7, 5,
0, 4, 6, 2,
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertex_list);
glTexCoordPointer(2,GL_FLOAT,0,texCoord_list);
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, index_list);
[解决办法]
debug glDrawElements()
each time send one quad down, find the incorrent indices, like this:
&index_list[0]
&index_list[4]
...