1

几天前,我开始使用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();

这是游戏中的木材纹理之一: 游戏质感

这是木材纹理的图像: 在此处输入图像描述

它的映射真的很奇怪。怎么了?有人可以发布一个普通纹理立方体的例子吗?

4

1 回答 1

4

尝试更改您的代码:

glTexCoord2f(0, 0); ...
glTexCoord2f(1, 0); ...
glTexCoord2f(1, 1); ...
glTexCoord2f(1, 0); ...

进入

glTexCoord2f(0, 0); ...
glTexCoord2f(1, 0); ...
glTexCoord2f(1, 1); ...
glTexCoord2f(0, 1); ... (changed this line)

您将立方体的两个角映射到纹理中的同一点。

于 2013-08-06T01:08:12.387 回答