I have developed a large application using Swing. I am going to port some of the display to JOGL to achieve 10bit grayscale display in some cases.
I have run into an issue where no image was displayed. I have narrowed the issue down to some problem with the GridbagLayout. For example, if I change the value of gbc.anchor in the code below the image displays correctly in some cases but not in others 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 = DeviceController.getConfOfRightMostMonitorAndLargest(); 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.NONE; gbc.anchor= GridBagConstraints.CENTER; jf.getContentPane().setLayout(new GridBagLayout()); jf.getContentPane().add(jlp,gbc); jf.setVisible(true); |
Administrator
|
Do you reproduce this bug when using a GLJPanel instead of a GLCanvas?
Julien Gouesse | Personal blog | Website
|
No the same effect is observed. I notice that modifying the GridBagConstraints of the GL component with
gbc.fill = GridBagConstraints.NONE; gbc.anchor= GridBagConstraints.CENTER; I get noimage but with gbc.fill = GridBagConstraints.BOTH; gbc.anchor= GridBagConstraints.CENTER; I get an image and with gbc.fill = GridBagConstraints.NONE; gbc.anchor= GridBagConstraints.LINE_START; I get noimage. |
Sounds like the Panel you use do not set minimum/preferred size. Gridbag will not set the size on a contained component unless you set fill.
http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagConstraints.html#fill |
Administrator
|
Then, it's a problem of Swing usage rather than a JOGL bug.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |