问题纹理映射OpenGL中的一个四元组

时间:2022-09-10 18:00:35

The following code produces the image that follows. The image I am using for the background is 640 x 480, as is the displayMode. The texture background is a .bmp and is loaded with the Slick texture loader. I am confuse to why it is not filling the Quad and why it is reflected. EDIT: The background of my OpenGL scene is pink, the black you see is from the Quad created. The background image is the green block with a 2px light blue border with "test" plastered on it.

下面的代码生成下面的图像。我在后台使用的图像是640×480,显示模式也是如此。纹理背景是一个。bmp,加载了光滑的纹理加载程序。我搞不懂为什么它没有填满四边形,为什么它被反映出来。编辑:我的OpenGL场景的背景是粉红色的,你看到的黑色来自创建的四轴飞行器。背景图像是绿色街区,有一个2px的浅蓝色边框,上面贴着“测试”。

private void renderBackground(){
    float w = displayMode.getHeight()/2;
    float h = displayMode.getWidth()/2;

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();

    GL11.glLoadIdentity();
    GLU.gluOrtho2D(-w, w, -h, h);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();

    GL11.glLoadIdentity();      
    GL11.glDisable(GL11.GL_DEPTH_TEST);

    if(useTextures)background.bind();
    GL11.glBegin(GL11.GL_QUADS);

    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex2f(-w,-h);

    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex2f(w,-h);

    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex2f(w, h);

    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex2f(-w, h);

    GL11.glEnd();

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPopMatrix();
}

问题纹理映射OpenGL中的一个四元组

Now when I add GL11.glTranslatef(20.0f, 20.0f, 0.0f); you will notice that the pink appears, which is the colour created int my "initGL" method: GL11.glClearColor(1.0f, 0.75f, 0.796f, 0.0f);问题纹理映射OpenGL中的一个四元组

现在加上gl11。gltranslatef (20.0f 20.0f, 20.0f, 0.0f)你会注意到粉色出现了,这是在我的“initGL”方法中创建的颜色:gl11 glclearcolor (1.0f, 0.75f, 0.796f, 0.0f);

My GL_PROJECTION contains the following before pushing it, my GL_MODELVIEW is unmodified when renderBackground() is called.

我的gl_project包含以下内容,在调用renderBackground()时,我的GL_MODELVIEW不会被修改。

    GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    GLU.gluPerspective(45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 25.0f);
    //position camera
    GLU.gluLookAt(5.0f, 3.0f, -5.0f, 0.0f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

2 个解决方案

#1


3  

I need more information to determine the problem, but here is a list with some possibilities.

我需要更多的信息来确定这个问题,但是这里有一些可能性。

1) You are using an older video card, which does not support texture non-power of 2, since you are using a library to load the texture, maybe it is detecting it, creating a power of two image, and filling it with black.

1)你正在使用一个旧的视频卡,它不支持2的纹理非幂,因为你正在使用一个库来加载纹理,也许它正在检测它,创建一个2的图像的幂,并填充它的黑色。

2) You (or some library you are using) changed the matrix of the texture matrix stack, and it is changing the texture coordinates.

2)您(或您正在使用的某个库)更改了纹理矩阵堆栈的矩阵,它正在更改纹理坐标。

3) You are doing something wrong when you load the texture (or call the library to do so).

3)在加载纹理时(或调用库来加载纹理时),您正在做一些错误的事情。

The first thing I would check is if your video card supports texture non-power of 2 extension. You can check it at runtime, see how to detect if openGL/card supports non power of 2?

我要检查的第一件事是你的显卡是否支持纹理非2倍扩展。您可以在运行时检查它,看看如何检测openGL/card是否支持2的非幂?

#2


0  

What I see first, is that you compute

我首先看到的是你的计算

float w = displayMode.getHeight()/2;
float h = displayMode.getWidth()/2;

switched?

换了吗?

Second, the texture could be flipped because the loader flipped it (when I remember right this happened to me, too especially with BMPs).

其次,纹理可以翻转,因为加载器翻转了它(当我记得正确的时候,这种情况也发生在我身上,尤其是在BMPs上)。

#1


3  

I need more information to determine the problem, but here is a list with some possibilities.

我需要更多的信息来确定这个问题,但是这里有一些可能性。

1) You are using an older video card, which does not support texture non-power of 2, since you are using a library to load the texture, maybe it is detecting it, creating a power of two image, and filling it with black.

1)你正在使用一个旧的视频卡,它不支持2的纹理非幂,因为你正在使用一个库来加载纹理,也许它正在检测它,创建一个2的图像的幂,并填充它的黑色。

2) You (or some library you are using) changed the matrix of the texture matrix stack, and it is changing the texture coordinates.

2)您(或您正在使用的某个库)更改了纹理矩阵堆栈的矩阵,它正在更改纹理坐标。

3) You are doing something wrong when you load the texture (or call the library to do so).

3)在加载纹理时(或调用库来加载纹理时),您正在做一些错误的事情。

The first thing I would check is if your video card supports texture non-power of 2 extension. You can check it at runtime, see how to detect if openGL/card supports non power of 2?

我要检查的第一件事是你的显卡是否支持纹理非2倍扩展。您可以在运行时检查它,看看如何检测openGL/card是否支持2的非幂?

#2


0  

What I see first, is that you compute

我首先看到的是你的计算

float w = displayMode.getHeight()/2;
float h = displayMode.getWidth()/2;

switched?

换了吗?

Second, the texture could be flipped because the loader flipped it (when I remember right this happened to me, too especially with BMPs).

其次,纹理可以翻转,因为加载器翻转了它(当我记得正确的时候,这种情况也发生在我身上,尤其是在BMPs上)。