JOGL纹理问题
我正在尝试学习 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我唯一能想到的是纹理不是 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).