Texture disappears on osx - GL_TEXTURE_2D JOGL Eclipse java

拥有回忆 提交于 2019-12-25 01:24:18

问题


I have some problems with drawing textures in Eclipse.

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.

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.

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.

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.


回答1:


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

Edit: 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.



来源:https://stackoverflow.com/questions/26767516/texture-disappears-on-osx-gl-texture-2d-jogl-eclipse-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!