【发布时间】:2010-11-10 23:15:23
【问题描述】:
我真的很喜欢玩 OpenGL,并遵循了一些示例等
我的问题是纹理立方体。大多数侧面纹理很好(前,后,左),但右边是一团糟。
我的魔方
// cube
static const GLfloat cubeVertices[] = {
-5.0f, 15.0f, 5.0f,
5.0f, 15.0f, 5.0f,
5.0f,0.0f, 5.0f,
-5.0f,0.0f, 5.0f,
-5.0f, 15.0f,-5.0f,
5.0f, 15.0f,-5.0f,
5.0f,0.0f,-5.0f,
-5.0f,0.0f,-5.0f
};
static const GLubyte cubeNumberOfIndices = 36;
const GLubyte cubeVertexFaces[] = {
0, 1, 5, // Half of top face
0, 5, 4, // Other half of top face
4, 6, 5, // Half of front face
4, 6, 7, // Other half of front face
0, 1, 2, // Half of back face
0, 3, 2, // Other half of back face
1, 2, 5, // Half of right face
2, 5, 6, // Other half of right face
0, 3, 4, // Half of left face
7, 4, 3, // Other half of left face
3, 6, 2, // Half of bottom face
6, 7, 3, // Other half of bottom face
};
我的纹理贴图
const GLshort squareTextureCoords2[] = {
0, 5, // top left
0, 0, // bottom left
15, 0, //bottom right
15, 5 //top right
};
我的立方体代码
//tell GL about our texture
glBindTexture(GL_TEXTURE_2D, 1);
glTexCoordPointer(2, GL_SHORT, 0, squareTextureCoords2);
glVertexPointer(3, GL_FLOAT, 0, cubeVertices);
for(int i = 0; i < cubeNumberOfIndices; i += 3) {
//glColor4ub(cubeFaceColors[colorIndex], cubeFaceColors[colorIndex+1], cubeFaceColors[colorIndex+2], cubeFaceColors[colorIndex+3]);
int face = (i / 3.0);
if (face % 2 != 0.0) {
}
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, &cubeVertexFaces[i]);
}
所以正如我所说,除了立方体的一侧(看不到顶部和底部,所以不用担心),所有东西都会渲染,纹理变得很奇怪
谢谢
更新**
我现在尝试了这些坐标,但纹理不会出现在每一侧,它从前到后对其进行纹理处理,因此两侧就像纹理另一边的线条。我必须接近破解这个
const GLfloat squareTextureCoords3[] = {
// Front face
0, 5, // top left
0, 0, // bottom left
5, 0, // bottom right
5, 5, // top right
// Top face
0, 5, // top left
0, 0, // bottom left
5, 0, // bottom right
5, 5, // top right
// Rear face
0, 5, // top left
0, 0, // bottom left
5, 0, // bottom right
5, 5, // top right
// Bottom face
0, 5, // top left
0, 0, // bottom left
5, 0, // bottom right
5, 5, // top right
// Left face
5, 5, // top left
0, 5, // bottom left
0, 0, // bottom right
5, 0, // top right
// Right face
0, 5, // top left
0, 0, // bottom left
5, 0, // bottom right
5, 5, // top right
};
【问题讨论】: