我可以在com.jogamp.opengl.awt.GLCanvas上绘制一个纹理,但是当bufferedimage更改时,我想更新纹理。我写了这样的显示方法:

    public void display(GLAutoDrawable glAutoDrawable) {
        try {
            if (gl2 == null) {
                gl2 = glAutoDrawable.getGL().getGL2();  // get the OpenGL 2 graphics context
            }
            gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
            gl2.glLoadIdentity();  // reset the model-view matrix


            if (image != null) {

                if (image != null) {
                    int[] pixels_raw = new int[this.camPanel.width * this.camPanel.height];
                    pixels_raw = image.getRGB(0, 0, this.camPanel.width, this.camPanel.height, null, 0, this.camPanel.width);

                    pixels.rewind();
                    for (int j = this.camPanel.height - 1; j >= 0; j--) {
                        for (int i = 0; i < this.camPanel.width; i++) {
                            int pixel = pixels_raw[j * this.camPanel.width + i];
                            pixels.put((byte) ((pixel >> 16) & 0xFF));//RED
                            pixels.put((byte) ((pixel >> 8) & 0xFF));//GREEN
                            pixels.put((byte) ((pixel >> 0) & 0xFF));//BLUE
                            pixels.put((byte) ((pixel >> 24) & 0xFF));//ALPHA
                        }
                    }

                    pixels.flip();

//                    gl2.glBindTexture(gl2.GL_TEXTURE_2D, 1);
//                    gl2.glTexParameterf(gl2.GL_TEXTURE_2D, gl2.GL_TEXTURE_WRAP_S, gl2.GL_REPEAT);
//                    gl2.glTexParameterf(gl2.GL_TEXTURE_2D, gl2.GL_TEXTURE_WRAP_T, gl2.GL_REPEAT);
//                    gl2.glTexParameterf(gl2.GL_TEXTURE_2D, gl2.GL_TEXTURE_MIN_FILTER, gl2.GL_NEAREST);
//                    gl2.glTexParameterf(gl2.GL_TEXTURE_2D, gl2.GL_TEXTURE_MAG_FILTER, gl2.GL_NEAREST);
                    gl2.glTexImage2D(gl2.GL_TEXTURE_2D, 0, gl2.GL_RGBA, this.camPanel.width, this.camPanel.height, 0, gl2.GL_RGBA, gl2.GL_UNSIGNED_BYTE, pixels);
//                    gl2.glFlush();
                    System.out.println("Error " + gl2.glGetError());

                    pixels.clear();
                }
                gl2.glEnd();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


当图像更改时,我正在调用显示方法,但始终存在黑屏并给出错误:
“ JAWTWindow:表面变化0x17011262-> 0x7e011c18”
“错误1282”

最佳答案

通过调用glEnd()引发错误。 docs指出:


  如果在没有glBegin的情况下执行glEnd,则生成GL_INVALID_OPERATION。


由于代码仅包含glEnd(),但没有glBegin,因此此调用无效。

10-08 03:30