Re: GL_FRAMEBUFFER_SRGB and GLJPanel
Posted by cmbruns on Feb 12, 2014; 1:40pm
URL: https://forum.jogamp.org/GL-FRAMEBUFFER-SRGB-and-GLJPanel-tp4030329p4031547.html
Is it possible more me to modify the GLSL fragment shader that GLJPanel uses to blit the framebuffer, since this bug has been closed as WONTFIX, and I do not have a general workaround? This way I could insert srgb color correction into that shader. And that shader could thus apply the correction correctly to everything, including glClearColor(), which NEVER gets sRGB correction in recent versions of GLJPanel (jogl 2.1+).
The suggested workarounds do not work for this issue:
1) I tried wrapping my display method inside glEnable(GL_FRAMEBUFFER_SRGB)/glDisable(GL_FRAMEBUFFER_SRGB), but that did not seem to help.
2) I also tried setting the GLJPanel setSkipGLOrientationVerticalFlip(true). Sure, my scene is now rendered upside down, but the sRGB color correction remains unapplied.
3) I tried passing "-Djogl.gljpanel.noglsl" to the JVM, but that did not help.
Do I really need to allocate my own render buffer, render to it, and blit it to the screen myself with my own srgb shader, to get physically correct lighting in my scene? I feel like this puts me on the road toward writing my own replacement for GLJPanel. On Windows and Linux, I am able to kludge a non-broken GLCanvas into my Swing application, but on Mac, GLCanvas is unusable in a Swing container, so I must use GLJPanel. So Mac is the platform I most need a solution for.
Below is an updated version of my demonstration program, including the suggested workarounds. But the problem remains. Any other workaround suggestions?
*********************************
package org.janelia.it.FlyWorkstation.gui.opengl.demo;
import java.awt.Dimension;
import javax.media.opengl.GL;
import javax.media.opengl.GL2GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.awt.GLJPanel;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
// Demonstration program to show that GL_FRAMEBUFFER_SRGB is not
// respected by GLJPanel in JOGL 2.1. The two displayed boxes should
// be the same brightness. The one on the right is wrongly too dark.
// (GL_FRAMEBUFFER_SRGB behavior was correct in JOGL 2.0)
//
// Suggested solution of passing "-Djogl.gljpanel.noglsl" to the JVM does NOT
// resolve the problem.
public class TestSrgbFramebuffer extends JFrame implements GLEventListener
{
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TestSrgbFramebuffer();
}
});
}
public TestSrgbFramebuffer() {
// left GLCanvas demonstrates correct paler brightness
GLCanvas glPanel1 = new GLCanvas();
// right GLJPanel demonstrates wrong darker brightness
GLJPanel glPanel2 = new GLJPanel();
// setSkipGLOrientationVerticalFlip(true) does NOT resolve the problem
glPanel2.setSkipGLOrientationVerticalFlip(true);
glPanel1.setPreferredSize(new Dimension(200, 200));
glPanel2.setPreferredSize(new Dimension(200, 200));
getContentPane().setLayout(new BoxLayout(
getContentPane(), BoxLayout.LINE_AXIS));
getContentPane().add(glPanel1);
getContentPane().add(glPanel2);
glPanel1.addGLEventListener(this);
glPanel2.addGLEventListener(this);
pack();
setVisible(true);
}
@Override
public void display(GLAutoDrawable gad) {
GL gl = gad.getGL();
// This line should raise the brightness of the image
gl.glEnable(GL2GL3.GL_FRAMEBUFFER_SRGB);
// Solid midtone clear color demonstrates the sRGB effect,
// or lack thereof
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
// glDisable(GL2GL3.GL_FRAMEBUFFER_SRGB) does NOT resolve the problem
gl.glDisable(GL2GL3.GL_FRAMEBUFFER_SRGB);
}
@Override
public void dispose(GLAutoDrawable arg0) {}
@Override
public void init(GLAutoDrawable gad) {
GL2GL3 gl2gl3 = gad.getGL().getGL2GL3();
// This next line should raise the brightness of the image
// (moved to display() method, to show futility of one proposed solution)
// gl2gl3.glEnable(GL2GL3.GL_FRAMEBUFFER_SRGB);
// midtone gray color clearly shows effect of sRGB correction
// (when it works!)
gl2gl3.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
}
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
int arg4) {}
}