几天前,我开始使用opengl 1.1(我知道它非常过时)进行了一个小型体素游戏。我使用 sfml 库来创建一个 opengl 上下文。我认为问题出在纹理坐标上,但我不确定。渲染代码:
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(0.5, 0.5, 0.5);
//front
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(1, 0); glVertex3f(0, 1, 0);
glTexCoord2f(1, 1); glVertex3f(1, 1, 0);
glTexCoord2f(1, 0); glVertex3f(1, 0, 0);
//back
glTexCoord2f(0, 0); glVertex3f(0, 0, 1);
glTexCoord2f(1, 0); glVertex3f(0, 1, 1);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(1, 0); glVertex3f(1, 0, 1);
glColor3f(0.6, 0.6, 0.6);
//top
glTexCoord2f(0, 0); glVertex3f(0, 1, 0);
glTexCoord2f(1, 0); glVertex3f(0, 1, 1);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(1, 0); glVertex3f(1, 1, 0);
//bottom
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(1, 0); glVertex3f(0, 0, 1);
glTexCoord2f(1, 1); glVertex3f(1, 0, 1);
glTexCoord2f(1, 0); glVertex3f(1, 0, 0);
glColor3f(0.7, 0.7, 0.7);
//left
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(1, 0); glVertex3f(0, 1, 0);
glTexCoord2f(1, 1); glVertex3f(0, 1, 1);
glTexCoord2f(1, 0); glVertex3f(0, 0, 1);
//right
glTexCoord2f(0, 0); glVertex3f(1, 0, 0);
glTexCoord2f(1, 0); glVertex3f(1, 1, 0);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(1, 0); glVertex3f(1, 0, 1);
glEnd();
glPopMatrix();
这是游戏中的木材纹理之一:
这是木材纹理的图像:
它的映射真的很奇怪。怎么了?有人可以发布一个普通纹理立方体的例子吗?