OpenGL纹理多维数据集未正确映射 [英] OpenGL Textured Cube Not Being Mapped Correctly

查看:86
本文介绍了OpenGL纹理多维数据集未正确映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我开始使用opengl 1.1进行小型体素游戏(我知道它已经过时了).我使用sfml库创建一个opengl上下文.我认为问题在于纹理坐标,但是我不确定.渲染代码:

A couple days ago I started on a small voxel game with opengl 1.1(I know its very outdated). I use the sfml library to create an opengl context. I think the problem is with the texture coordinates, but I'm not sure. The render code:

    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();

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

This is the one of the in-game wood textures:

这是木材纹理的图像:

This is the image of the wood texture:

它真的很奇怪地被映射了.怎么了?有人可以发布普通纹理立方体的示例吗?

It gets mapped on really weirdly. What is wrong? Can someone post an example of a normal textured cube?

推荐答案

尝试更改您的代码:

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)

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

You're mapping two corners of the cube to the same point in the texture.

这篇关于OpenGL纹理多维数据集未正确映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆