opengl中纹理的位置 [英] position for texture in opengl

查看:203
本文介绍了opengl中纹理的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,关于如何在立方体上声明纹理的点

i have a question concerning how to declare the points for a texture on a cube

确切地说,我的意思是:

to be exactly i mean the:

glTexCoord2f(x.f, y.f);

在正面,我的声明起作用:

for the front side, my declaration works:

glBegin(GL_POLYGON);   //Vorderseite
        glNormal3f(0.0f, 0.0f, 1.0f);//normale für vorderseite

    glTexCoord2f(0.0f, -1.f);
    glVertex3f(-fSeitenL/2.0f,-fSeitenL/2.0f,+fSeitenL/2.0f);

    glTexCoord2f(1.f, -1.f);
    glVertex3f(+fSeitenL/2.0f,-fSeitenL/2.0f,+fSeitenL/2.0f);

    glTexCoord2f(1.f, 0.0f);
    glVertex3f(+fSeitenL/2.0f,+fSeitenL/2.0f,+fSeitenL/2.0f); 

    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-fSeitenL/2.0f,+fSeitenL/2.0f,+fSeitenL/2.0f);
    glEnd();

但是对于右侧,它不起作用,我建议我需要其他参数,例如glTexCoord2f,但是我不知道那个.

but for the right side, it doesn't work, i suggest i need other parameters, for glTexCoord2f, but i don't know witch one.

glBegin(GL_POLYGON);   //Rechte Seite

    glNormal3f(1.0f, 0.0f, 0.0f); //normale für rechte seite

    glTexCoord2f(0.0f, -1.f);
    glVertex3f(+fSeitenL/2.0f,-fSeitenL/2.0f,+fSeitenL/2.0f);

    glTexCoord2f(1.0f, -1.f);
    glVertex3f(+fSeitenL/2.0f,-fSeitenL/2.0f,-fSeitenL/0.0f);

    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(+fSeitenL/2.0f,+fSeitenL/2.0f,-fSeitenL/0.0f);

    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(+fSeitenL/2.0f,+fSeitenL/2.0f,+fSeitenL/0.0f);
    glEnd();

毕竟我关闭了纹理声明"

after all i close the "texture-declaration with"

glDisable(GL_TEXTURE_2D);

预先感谢

正面显示有图片,另一面没有显示,甚至立方体"也没有显示. 现在,我只是使用带有一些随机空白的黑色图片,因此尽管我对如何正确设置glTexCoord2f非常感兴趣,确切的位置并没有那么重要.

the frontside is shown with the picture, the other side isn't shown, not even the "cubeside". for now i just use a picture that's black with some random white spaces, so the exactly position is not that much importent, despite that i'm very interessted how to set the glTexCoord2f right.

推荐答案

由于您使用的是负纹理坐标(或者实际上是0..1范围以外的任何东西),因此需要确保将纹理环绕模式设置为重复.

Since you're using negative texture coordinates (or really anything outside the 0..1 range) you need to make sure that your texture wrap mode is set to repeat.

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

如果将它们设置为GL_CLAMP,则任何小于0的值都将被设置为0,而大于1的任何值都将被设置为1.但是由于您说的是模型纹理的第一部分,所以这很可能是不是你的问题.

If those are set to GL_CLAMP instead, then any value less than 0 will be set to 0 and any value greater than 1 will be set to 1. But since you say the first part of your model textures correctly, this is probably not your problem.

下一个最可能出现的问题是照明.如果使用glDisable(GL_LIGHTING);关闭照明,是否会显示整个模型?如果是这样,那么您需要确保您的光源面向模型的问题部分,或者向光源添加环境组件.

The next most likely issue is lighting. If you turn off lighting with glDisable(GL_LIGHTING); does the entire model show up? If so, then you need to make sure you have a light facing the problem portion of your model, or add an ambient component to your light.

这篇关于opengl中纹理的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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