0

我可以在 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”

4

1 回答 1

5

调用会引发错误glEnd()文档指出:

GL_INVALID_OPERATION 如果执行 glEnd 而前面没有 glBegin 则生成。

由于代码只包含 aglEnd()但没有glBegin,所以这个调用是无效的。

于 2018-03-19T15:55:36.213 回答