Antialiased polygons in JOGL 2.0 rc3

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Antialiased polygons in JOGL 2.0 rc3

Archie
Hey guys,  

I'm having some serious trouble trying to get antialiased polygons working with JOGL 2.0 rc3.  Essentially what I am trying to do is take the nice little demonstration file that is on the leolol website and just add antialiasing to the it's polygon or QUADS drawing.  I have followed the advice of a few OPENGL tutorials out there but none of them seem to work.  If anyone can share some insights that would be great.  Along with the bits of the program that are of interest I have also included a full link to the source code here: http://pastebin.com/msdmfWTV

I'm on windows 7 with a geforce 8800gts.

Here is what I have in the init method:

    public void init(GLAutoDrawable gLDrawable) {
        GL2 gl = gLDrawable.getGL().getGL2();
        gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
       
        //gl.glBlendFunc (GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);  // This makes everything black!?
        gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
       
        // enable polygon antialiasing
        gl.glClear (GL.GL_COLOR_BUFFER_BIT);
        gl.glEnable (GL2.GL_BLEND);
        gl.glEnable (GL2.GL_POLYGON_SMOOTH);
        gl.glDisable (GL.GL_DEPTH_TEST);
        gl.glHint(GL2.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST);
       
        gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
        ((Component) gLDrawable).addKeyListener(this);
    }

and here is the display method:

    public void display(GLAutoDrawable gLDrawable) {
        final GL2 gl = gLDrawable.getGL().getGL2();
       
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        //gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
       
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, 0.0f, -5.0f);
 
        // rotate on the three axis
        gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
        gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
        gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
 
        // Draw A Quad
        gl.glBegin(GL2.GL_QUADS);          
            gl.glColor4f(0.0f, 1.0f, 1.0f, 1.0f);   // set the color of the quad
            gl.glVertex3f(-1.0f, 1.0f, 0.0f);      // Top Left
            gl.glVertex3f( 1.0f, 1.0f, 0.0f);       // Top Right
            gl.glVertex3f( 1.0f,-1.0f, 0.0f);      // Bottom Right
            gl.glVertex3f(-1.0f,-1.0f, 0.0f);     // Bottom Left
        // Done Drawing The Quad
        gl.glEnd();                                                    
 
        // increasing rotation for the next iteration                                
        rotateT += 0.2f;
    }

Thanks for your time!
Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Wade Walker
Administrator
Are you saying that it draws polys, but they're not anti-aliased? Or it doesn't draw at all? I know JOGL 2 should work with your system, since I have an almost identical setup.
Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Archie
This post was updated on .
Thanks for getting back to me Wade,
I should have been more specific. I'd say JOGL2 is pretty much working.  In it's current state it actually draws the polygon but it is not antialiased.  

However, if you uncomment the line that says:
//gl.glBlendFunc (GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); (Some examples encourage this setting)
It doesn't appear to draw the polygon anymore.

So either I can draw it and it isn't antialiased, or I can't see it at all. :)

Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Sven Gothel
Administrator
On Tuesday, September 27, 2011 07:41:33 AM Archie [via jogamp] wrote:
>
> Thanks for getting back to me Wade,
> I should have been more specific. I'd say JOGL2 is pretty much working.  In
> it's current state it actually draws the polygon but it is not antialiased.  
>
besides all set smooth fixed function pipeline hints you enable,
how about
  gl.glShadeModel(GL2.GL_SMOOTH) ?


> However, if you uncomment the line that says:
> //gl.glBlendFunc (GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); (Some examples
> encourage this setting)
> It doesn't appear to draw the polygon anymore.
yeah well, this triggers sort of a 2nd rendering pass,
I would need to read the spec to be precise here - however,
it blends (composites) 2 framebuffers together with a specific method.
Read the spec - but I already can tell at least you would need alpha
to be enabled for your GLCapabilities.

>
> So either I can draw it and it is antialiased, or I can't see it at all. :)
haha :)

well, compare it with let's say Gears GL2 and Gears ES1 .. ?
play with the 'smooth' state .. hmm.

Sorry, hope it helps a little.

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Rami Santina
Administrator

As i remember the polygon smooth is of inconsistant behaviour dependent on the driver. So even with direct opengl u will get the same results.

IMHO u can try using msaa to smooth ur polygon edges. In the end the poly smooth will be doing the same thing but for one polygon...expensive.  and wont produce good results for neighboring polys.

Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Archie

I tried to turn the alpha on in the capabilities but either I couldn't find the right setting to do this or it is still not helping.

I tried playing with the following setting:

capabilities.setAlphaBits(1);

and also different combinations with these just in case that would have an effect.

capabilities.setBackgroundOpaque(false);
capabilities.setTransparentAlphaValue(0);

I'm now going to play with the gears demo as was suggested and see what is the situation with that.  After that I'll check out Rami's advice and see if I can get msaa going instead.  But I'm still keen to at least get this polygon smoothing going just for the sake of nutting it out.  I have a reasonably modern graphics card (geforce 8800 GTS) so I'm 'fairly' certain it can do smoothing in this way (even if it is not the ultimate approach).  

Anyway, I'll let you guys know if the gears demo's help shine some light on this.

Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Archie

Ok, I finally managed to download the source code for the gears demo (As was recommended).  It might be beneficial to new users if you make the source for these more easily available.  Working demo's like this in the form of source code are a powerful way to learn the most relevant methods and techniques.

Anyway, I couldn't find anything in the gears demo that would allow me to set them to smooth.  

I also tried adding: gl.glShadeModel(GL2.GL_SMOOTH)  to my init code but it didn't help.

Has anyone got a little working example of polygon smoothing in JOGL?  (Not the more advanced multi sampled jitter method)

Sorry to keep pressing this angle guys.

Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

jacksmash
Are there no updates on this topic at all? I can't get AA working either...
Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

Demoscene Passivist
Administrator
I'm using build #510 of JOGL an MSAA works fine here (NEWT+AWT). Seems theres a driver/code issue on ur side and not a general JOGL MSAA problem.

Generally u only have to do this to enable MSAA in JOGL:
            
tGLCapabilities.setSampleBuffers(true);
tGLCapabilities.setNumSamples(getNumberOfSamplingBuffers());

For a more complete setup code (tested with build #510 and MSAA working) take a look at my repo on github and my AWT setup code

Also if hardware MSAA does not work on ur side for any reason u can not change I suggest u take a look at 'super sampling'. I implemented a JOGL2 version of this technique long ago while JOGLs MSAA support was actually broken temporarily. See this post  on my blog for code and further explanation.

If none of the above techniques work for u there is another alternative called "post-processing AA" wich has become very popular with the recent dawn of deferred renderers. So if wanna try out that u could take a look at my JOGL2 implementation of FXAA.
Reply | Threaded
Open this post in threaded view
|

Re: Antialiased polygons in JOGL 2.0 rc3

jacksmash
Perfect! Thanks for your reply... works well.