How to achieve full anti-aliasing while doing native OpenGL calls.

Hello,

Using P5 2.1.1, I used to setup antialising with smooth(32).. However, as soon as I make a direct OpenGL call (like glTranslate3f, etc..), the sketch refuses to run and antialiasing is bad..

Though, using smooth(); alone lets the sketch work but full antialiasing is not on..

My question is how (P5 code and/or OpenGL code) to achieve full antialiasing while making direct OpenGL call in the sketch ?

Answers

  • smooth() sets an antialiased opengl context where your low-level opengl calls should draw to as well, so I'm surprised that you don't get antialiasing. Maybe if you post some code would be easier to find the problem.

  • edited March 2014

    Sure..

    Here is an example code :

    import com.jogamp.opengl.util.gl2.GLUT;
    import java.nio.*;
    import java.util.*;
    import javax.media.opengl.GL2;
    import javax.media.opengl.glu.GLU;
    
     PJOGL   pgl;
     GL2     gl;
     GLU     glu;  
     GLUT    glut;
    float angle = .67;
    void setup() 
    {  
    
      size(1280, 720, P3D);
      pgl  = (PJOGL) beginPGL();
      glu  = pgl.glu;
      glut = new GLUT();
      gl   = GLU.getCurrentGL().getGL2();
    
      gl.setSwapInterval(1);  
      gl.glShadeModel(GL2.GL_SMOOTH);                                  
      gl.glClearDepth(1.0f);                                           
      gl.glEnable(GL2.GL_DEPTH_TEST);                                  
      gl.glDepthFunc(GL2.GL_LEQUAL);                                   
      gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);    
    
      // OFFENDING LINE ! runs with just "smooth();", but not "smooth(32)",
      // as soon as I use OpenGL objects..
      smooth(32);
    }
    
    void draw() 
    { 
      background(50);
    
      gl.glPushMatrix();
      gl.glTranslatef(displayWidth/2, displayHeight/2, 0);
      gl.glRotatef(angle,0,1,0); 
      gl.glRotatef(angle * 1.02 ,1,0,0);  
      gl.glScalef(1,-1,1);
      gl.glScalef(200,200,200);
    
      drawGlCube();
      gl.glPopMatrix();
    
    }
    
    public void drawGlCube()
    {
      gl.glBegin(GL2.GL_QUADS);
    
      gl.glNormal3f(0,0,-1);
    
      gl.glTexCoord2f(0,0);
      gl.glVertex3f(-1,1,-1);
      gl.glTexCoord2f(0,1);
      gl.glVertex3f(-1,-1,-1);
      gl.glTexCoord2f(1,1);
      gl.glVertex3f(1,-1,-1);
      gl.glTexCoord2f(1,0);
      gl.glVertex3f(1,1,-1);
    
    
      gl.glNormal3f(1,0,0);  
    
      gl.glTexCoord2f(1,1);
      gl.glVertex3f(1,-1,1);
      gl.glTexCoord2f(1,0);
      gl.glVertex3f(1,1,1);
      gl.glTexCoord2f(0,0);
      gl.glVertex3f(1,1,-1);
      gl.glTexCoord2f(0,1);
      gl.glVertex3f(1,-1,-1);
    
      gl.glNormal3f(0,0,1);
    
      gl.glTexCoord2f(1,1);
      gl.glVertex3f(-1,-1,1);
      gl.glTexCoord2f(1,0);
      gl.glVertex3f(-1,1,1);
      gl.glTexCoord2f(0,0);
      gl.glVertex3f(1,1,1);
      gl.glTexCoord2f(0,1);
      gl.glVertex3f(1,-1,1);
    
    
      gl.glNormal3f(-1,0,0);
    
      gl.glTexCoord2f(0,0);
      gl.glVertex3f(-1,1,1);
      gl.glTexCoord2f(0,1);
      gl.glVertex3f(-1,-1,1);
      gl.glTexCoord2f(1,1);
      gl.glVertex3f(-1,-1,-1);
      gl.glTexCoord2f(1,0);
      gl.glVertex3f(-1,1,-1);
    
    
      gl.glNormal3f(0,1,0);
    
      gl.glTexCoord2f(0,0);
      gl.glVertex3f(1,1,1);
      gl.glTexCoord2f(0,1);
      gl.glVertex3f(-1,1,1);
      gl.glTexCoord2f(1,1);
      gl.glVertex3f(-1,1,-1);
      gl.glTexCoord2f(1,0);
      gl.glVertex3f(1,1,-1);
    
    
      gl.glNormal3f(0,-1,0);
    
      gl.glTexCoord2f(0,0);
      gl.glVertex3f(-1,-1,1);
      gl.glTexCoord2f(0,1);
      gl.glVertex3f(1,-1,1);
      gl.glTexCoord2f(1,1);
      gl.glVertex3f(1,-1,-1);
      gl.glTexCoord2f(1,0);
      gl.glVertex3f(-1,-1,-1);
    
      gl.glEnd();
    }
    

    When I try to run this, I get a NullPointerException with the following call stack dump :

        java.lang.NullPointerException
            at processing.mode.java.runner.Runner.findException(Runner.java:926)
            at processing.mode.java.runner.Runner.reportException(Runner.java:871)
            at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:797)
            at processing.mode.java.runner.Runner$2.run(Runner.java:686)
    

    When I use smooth(), everything runs fine, but as soon as I write smooth(32) and use OpenGL code afterwards, I get this exception.

    Any idea where it may come from ?

Sign In or Register to comment.