gpt4 book ai didi

c++ - 未正确映射 OpenGL 纹理立方体

转载 作者:行者123 更新时间:2023-11-30 01:57:53 25 4
gpt4 key购买 nike

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

这是游戏中的木材纹理之一: In game texture

这是木材纹理的图像: enter image description here

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

最佳答案

尝试更改您的代码:

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)

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

关于c++ - 未正确映射 OpenGL 纹理立方体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18070230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com