我一直很喜欢用OpenGL玩和遵循一些例子等iPhone的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]);
}
所以,正如我所说的,一切都呈现但是立方体的一侧(看不到顶和底部所以不担心)纹理变得奇怪
由于
UPDATE **
我现在尝试了这些COORDS和纹理在每一侧上没有出现由前向后的纹理它,所以侧面是像从纹理的另一个边缘线。我必须接近破解这个
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
};
你好,感谢您的回复。我正在使用书籍等例子来创建我的代码。那么你将如何去构造一个立方体纹理。我真的很陌生,除了这个血腥的纹理之外,我得到了一切正常的工作(更多的代码) – Burf2000 2010-11-11 08:55:05
作为第一步,总共使用24个顶点 - 每个面各有四个顶点,每个顶点都有自己的一组纹理坐标。因此,请保留最近添加的squareTextureCoords3,但展开cubeVertices数组并调整cubeVertexFaces。我现在不得不从我的办公桌冲下来,但如果问题仍然存在,我会在今晚稍后提供一个例子。 – Tommy 2010-11-11 18:18:00