GLCanvas和GLJPanel产生不同的图像

时间:2015-10-05 15:12:39

标签: jogl

我的SSCE是:

    public static void main(final String[] args) throws IOException {

    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {

                int bitdepth = 10;
                GLProfile.initSingleton();
                GLProfile glProfile = GLProfile.getDefault();

                GLCapabilities glCapabilities = new GLCapabilities( glProfile );
                glCapabilities.setBlueBits(bitdepth);
                glCapabilities.setGreenBits(bitdepth);
                glCapabilities.setRedBits(bitdepth);
                glCapabilities.setAlphaBits(2);
                glCapabilities.setDoubleBuffered(true);
                glCapabilities.setHardwareAccelerated(true);
                glCapabilities.setNumSamples(4);
                glCapabilities.setBackgroundOpaque(false);
                glCapabilities.setSampleBuffers(true);
                GraphicsConfiguration gc = getSomeGC();




                JFrame jf = new JFrame(gc);
                jf.setExtendedState(JFrame.MAXIMIZED_BOTH);

                GLCanvas canvas = new GLCanvas(glCapabilities);
                canvas.addGLEventListener(new GLEventListener() {

                    @Override
                    public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
                            int arg4) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void init(GLAutoDrawable arg0) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void dispose(GLAutoDrawable arg0) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void display(GLAutoDrawable drawable) {
                        System.out.println("Painting");



                        BufferedImage image = null;
                        try {
                            image = ImageIO.read(new File("img.tiff"));
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        if(image!=null){
                            GL2 gl2 = drawable.getGL().getGL2();

                            //gl2.glClear(GL.GL_COLOR_BUFFER_BIT);
                            int format = GL.GL_LUMINANCE;
                            int type  = GL.GL_UNSIGNED_SHORT;

                            DataBufferUShort db = (DataBufferUShort) image.getRaster().getDataBuffer();
                            short[] shorts = db.getData(0);
                            Buffer buffer = ShortBuffer.wrap(shorts);
                            //gl2.glViewport(0, 0, image.getWidth(), image.getHeight());

                            gl2.glDrawPixels(image.getWidth(), image.getHeight(), format , type, buffer );

                        }

                    }
                });




                JPanel jp = new JPanel();
                jp.setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.fill = GridBagConstraints.BOTH;
                gbc.gridx=0;
                gbc.gridy=0;
                gbc.gridwidth=1;
                gbc.gridheight=1;
                gbc.weightx=1;
                gbc.weighty=1;
                gbc.anchor= GridBagConstraints.CENTER;
                jp.add(canvas,gbc);

                JScrollPane jsp = new JScrollPane();
                jsp.getViewport().add(jp);

                JLayeredPane jlp = new JLayeredPane();
                jlp.setLayout(new GridBagLayout());

                jlp.add(jsp, gbc);

                //jsp.getViewport().add(dsc);
                gbc = new GridBagConstraints();
                gbc.gridx=0;
                gbc.gridy=0;
                gbc.gridwidth=1;
                gbc.gridheight=1;
                gbc.weightx=1;
                gbc.weighty=1;
                gbc.fill=GridBagConstraints.BOTH;
                gbc.anchor= GridBagConstraints.CENTER;
                jf.getContentPane().setLayout(new GridBagLayout());
                jf.getContentPane().add(jlp,gbc);

                jf.setVisible(true);


            }
        });
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

我通过GLJPanel为GLCanvas提供了两个不同的显示。我试图在能够达到10位灰度的显示器上获得10位显示。

GLJPanel是8位,而GLCanvas抛出异常,但我相信在10位时正确显示。

 Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Error making context 0x20000 current on Thread AWT-EventQueue-0, drawableWrite 0x42011b9a, drawableRead 0x42011b9a, werr: 0, WindowsWGLContext [Version 4.2 (Compat profile, arb, ES2 compat, ES3 compat, FBO, hardware) - 4.2.12327 Compatibility Profile Context FireGL 12.104.2.3000 [GL 4.2.0, vendor 12.104.2 (Compatibility Profile Context FireGL 12.104.2.3000)], options 0x1c03, this 0x263ce8f2, handle 0x20000, isShared false, jogamp.opengl.gl4.GL4bcImpl@633cca0,
 quirks: [NoDoubleBufferedBitmap],
Drawable: WindowsOnscreenWGLDrawable[Realized true,
Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@5dba26,
Handle    0x42011b9a,

1 个答案:

答案 0 :(得分:1)

由于这是一个jogl bugreport,请将包含所有包含的完整可编辑SSCE发布到https://jogamp.org/bugzilla/的错误报告中 不要忘记附上源代码和img.tiff

您在技术上报告了两个错误,因此您应该提交两个错误:

错误一: 我们需要了解您的用例以及使用GLCanvas和GLJPanel时在两个图像中看到的差异。

错误二: 我们需要一个GLException的重现器:错误使线程上的上下文0x20000当前

欲了解更多详情,请阅读JOGL Bugreports&测试FAQ: http://jogamp.org/wiki/index.php/Jogl_FAQ#Bugreports_.26_Testing