GLCanvas and GLJPanel produce different images

两盒软妹~` 提交于 2020-01-16 13:13:32

问题


My SSCE is:

    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();
    }


}

I get two different displays for GLCanvas over GLJPanel. I trying to get 10 bit display on a monitor capable of 10bit grayscale.

The GLJPanel is in 8 bit while the GLCanvas throws an exception but is I believe displayed correctly at 10 bit.

 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:


Since this is a jogl bugreport please post the complete compilable SSCE with all includes into a bugreport at https://jogamp.org/bugzilla/ don't forget to attach the source code and the img.tiff

You are technically reporting two bugs thus you should file two bugs:

bug one: We need to know more about your use-case and what kind of differences you see in the two images when using a GLCanvas and GLJPanel.

bug two: We need a reproducer for the GLException: Error making context 0x20000 current on Thread

For more details read the JOGL Bugreports & Testing FAQ: http://jogamp.org/wiki/index.php/Jogl_FAQ#Bugreports_.26_Testing



来源:https://stackoverflow.com/questions/32951981/glcanvas-and-gljpanel-produce-different-images

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