JOGL纹理问题

发布于 2024-12-07 10:48:52 字数 1269 浏览 1 评论 0原文

我正在尝试学习 JOGL 绑定。这些教程似乎已经过时了,所以我总是试图从每个教程中拼凑出有效的内容。

我在尝试将简单纹理应用到方形平面时遇到问题。

我有一个 204 X 204 的图像,名为 box.png。

在我的 init() 中,我执行以下操作来加载纹理:

        try {
            InputStream stream = getClass().getResourceAsStream("box.png");
            TextureData data = TextureIO.newTextureData(gl.getGLProfile(),
                stream, 100, 200, false, "png");
            boxTexture = TextureIO.newTexture(data);
        } catch (IOException exc) {
            exc.printStackTrace();
            System.exit(1);
        }

然后我尝试在 display() 中执行以下操作来应用纹理:

        gl.glEnable(GL.GL_TEXTURE_2D);

        boxTexture.enable(gl);
        boxTexture.bind(gl);

        gl.glBegin(GL2.GL_QUADS);
        // Front Face
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(-1.0f, 1.0f, 1.0f);

        gl.glEnd();

是否有任何明显的问题可以解释我失败的原因?

I'm in the process of trying to learn JOGL bindings. The tutorials seem to be outdated, so I'm always trying to piece together what is valid from each one.

I'm having problems trying to apply a simple texture to a square plane.

I have an image that is 204 X 204 called box.png.

In my init() I do the following to get the texture loaded:

        try {
            InputStream stream = getClass().getResourceAsStream("box.png");
            TextureData data = TextureIO.newTextureData(gl.getGLProfile(),
                stream, 100, 200, false, "png");
            boxTexture = TextureIO.newTexture(data);
        } catch (IOException exc) {
            exc.printStackTrace();
            System.exit(1);
        }

Then I try to apply my texture doing the following in my display():

        gl.glEnable(GL.GL_TEXTURE_2D);

        boxTexture.enable(gl);
        boxTexture.bind(gl);

        gl.glBegin(GL2.GL_QUADS);
        // Front Face
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(-1.0f, 1.0f, 1.0f);

        gl.glEnd();

Are there any blaring problems that would explain why I'm failing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘过的浮云 2024-12-14 10:48:52

我唯一能想到的是纹理不是 2 的幂。将纹理的大小更改为 256x256,然后看看它是否有效。根据您的显卡,它会或不会受支持(如果该卡不是旧的,则应该是)。

Only thing I can think of is that the texture isn't a power of 2. Change the size of the texture to 256x256 and see if it works then. Depending on your graphics card, it will or won't be supported (it should be if the card isn't ancient).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文