osx上的纹理消失-GL_TEXTURE_2D JOGL Eclipse Java [英] Texture disappears on osx - GL_TEXTURE_2D JOGL Eclipse java

查看:61
本文介绍了osx上的纹理消失-GL_TEXTURE_2D JOGL Eclipse Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中绘制纹理时遇到一些问题.

I have some problems with drawing textures in Eclipse.

当我运行Java应用程序并且弹出窗口时,我只看到纹理(png中的红色四边形)几毫秒,然后一切都变黑了.

When I run the Java application and when the window popup I only see the texture (red quads from a png.) some milliseconds then everything turns black.

我得到了这段代码,它可以在所有同学PC上完美运行,但不能在Macbook Pro 2012上运行.运行JRE 1.8.

I got this code and it works perfectly on all my classmates PC's but not on my Macbook Pro 2012. Run JRE 1.8.

已将jogl库更改为mac osx的库,调试时没有出现任何错误.我看到的是drawQuad函数有问题,如果删除行gl.glEnable(GL.GL_TEXTURE_2D),则所有内容都会绘制,但没有您可能理解的纹理,只是白色.

Have changed the jogl libary to the ones for mac osx and I dont get any errors when debugging. What I can see is that there is something wrong in the drawQuad function and if I delete the row gl.glEnable(GL.GL_TEXTURE_2D) , everything draws but without the textures as u might understand, just white.

那么有人知道这可能是什么问题吗?还是GL_TEXTURE_2D的osx中存在任何已知的错误?如我所写,该应用程序可以在其他PC上正常运行.

So does anyone know what the problem might be? Or is there any known bugs in osx with GL_TEXTURE_2D ? As I wrote, the application works fine on other PC's.

这是我认为问题所在的班级

Here's the class I think where the problem is:

private Texture texture;

void loadResources() throws GLException, IOException {
    if (texture == null)
        texture = TextureIO.newTexture(new File("3.png"), false);
}

void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL2 gl = drawable.getGL().getGL2();
    GLU glu = new GLU();

    gl.glMatrixMode(GL_PROJECTION);
    gl.glLoadIdentity(); // reset
    glu.gluOrtho2D (0.0, w, h, 0);  // define drawing area

    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity(); // reset

}

void drawQuad(GLAutoDrawable drawable, float x, float y, float w, float h) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glEnable(GL.GL_TEXTURE_2D);
    gl.glBindTexture(GL.GL_TEXTURE0, texture.getTarget());
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(1, 1, 1);
    gl.glTexCoord2f(1, 1);
    gl.glVertex2f(x,      y);
    gl.glTexCoord2f(1, 1);
    gl.glVertex2f(x + w, y);
    gl.glTexCoord2f(1, 0);
    gl.glVertex2f(x + w, y + h);
    gl.glTexCoord2f(0, 0);
    gl.glVertex2f(x,      y + h);

    gl.glEnd();

}

public void clearScreen(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}

如果您需要更多代码,请留言.

Just leave a message if u need more code.

推荐答案

根据

According to here glBindTexture is not allowed between glBegin and glEnd. Did you check for OpenGL errors? This should generate a GL_INVALID_OPERATION.

根据此处的相同,glBindTexture(目标)的第一个参数不能为GL.GL_TEXTURE0.这应该已经产生了GL_INVALID_ENUM错误.

According to the same here, the first parameter of glBindTexture (target) cannot be GL.GL_TEXTURE0. This should have generated a GL_INVALID_ENUM error.

这篇关于osx上的纹理消失-GL_TEXTURE_2D JOGL Eclipse Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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