Login  Register

Face Culling Issues in GLJPanel

Posted by Pascal on Feb 29, 2016; 10:23pm
URL: https://forum.jogamp.org/Face-Culling-Issues-in-GLJPanel-tp4036391.html

It appears as though GLJPanel doesn't support clockwise front faces for culling. I.e. the following causes issues:
gl.glEnable(GL.GL_CULL_FACE);
gl.glFrontFace(GL.GL_CW);

vs. the following is fine:
gl.glEnable(GL.GL_CULL_FACE);
gl.glFrontFace(GL.GL_CCW);

Running the below code snippet, I expect the triangle to be culled and the blue background to be rendered. Instead I get a black background and if the window is resized, it shows garbage. If I change it to CCW culling and re-order the vertices, everything is fine. Similarly, GLCanvas is fine with CW culling. The same thing happens with newer GL profiles, I'm just using GL2 for brevity of the code.

Java: 1.8.0_72 (But I've also seen it in 1.7 and 1.6)
OSX Version 10.11.3 (But I've also seen it on Linux)
JOGL version: 2.3
-----------------------------------------------------------------------------------------------------
Package: com.jogamp.opengl
Extension Name: com.jogamp.opengl
Specification Title: Java Bindings for OpenGL API Specification
Specification Vendor: JogAmp Community
Specification Version: 2.3
Implementation Title: Java Bindings for OpenGL Runtime Environment
Implementation Vendor: JogAmp Community
Implementation Vendor ID: com.jogamp
Implementation URL: http://jogamp.org/
Implementation Version: 2.3.2
Implementation Build: 2.3-b1469-20151010
Implementation Branch: origin/master
Implementation Commit: e794fc40ba723f2fca4ac892e873975fb393e007
-----------------------------------------------------------------------------------------------------

public class CullingTest {
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        GLJPanel panel = new GLJPanel();
        panel.addGLEventListener(new GLEventListener() {
          @Override
          public void reshape(GLAutoDrawable d, int x, int y, int w, int h) {
            d.getGL().glViewport(x, y, w, h);
          }
          @Override
          public void init(GLAutoDrawable d) {
            GL2 gl = d.getGL().getGL2();
            gl.glClearColor(0, 0, 0.5f, 1);
            gl.glEnable(GL.GL_CULL_FACE);
            gl.glFrontFace(GL.GL_CW);
          }
          @Override
          public void dispose(GLAutoDrawable d) {
          }
          @Override
          public void display(GLAutoDrawable d) {
            GL2 gl = d.getGL().getGL2();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glLoadIdentity();
            gl.glBegin(GL.GL_TRIANGLES);
              gl.glVertex3f( 0.0f, 1.0f, 0.0f);
              gl.glVertex3f(-1.0f,-1.0f, 0.0f);
              gl.glVertex3f( 1.0f,-1.0f, 0.0f);
            gl.glEnd();
            gl.glFlush();
          }
        });

        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);
        frame.getContentPane().add(panel);
        frame.setVisible(true);
      }
    });
  }
}