我开始使用 OpenGL ES 1.0 并且遇到了一些(初学者)问题:我试图将方形纹理映射到由三角形描述的立方体。
// Turn necessary features on
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_SRC_COLOR);
glEnable(GL_CULL_FACE);
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
// Bind the number of textures we need, in this case one.
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Drawing code
static GLfloat rot = 0.0;
static const Vertex3D vertices[] = {
-1.0f,-1.0f,-1.0f, //0 00
1.0f,-1.0f,-1.0f, //1 10
1.0f, 1.0f,-1.0f, //2 11
-1.0f, 1.0f,-1.0f, //3 01
};
static const int vertexCnt = 3 * 2;
static const GLubyte cube[] = {
3,0,2,
1,2,0,
};
static const GLfloat texCoords[] = {
0,1,
0,0,
1,1,
1,0,
1,1,
0,0,
};
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_COLOR_MATERIAL);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glVertexPointer(3, GL_FLOAT, 0, vertices);
//glColorPointer(4, GL_FLOAT, 0, colors);
glNormalPointer(GL_FLOAT, 0, normals);
glDrawElements(GL_TRIANGLES, vertexCnt, GL_UNSIGNED_BYTE, cube);
glDisableClientState(GL_VERTEX_ARRAY);
//glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
现在,经过无数次尝试,我无法让它在其他方面工作......在将方形纹理映射到三角形时是否有一些经验法则?
编辑:我想我知道应该如何进行映射。但它不适用于这个例子(一张脸)。有人可以验证我是否正确完成了映射(假设其余代码正常工作)?
非常感谢