Loading...
Logo
Processing Forum
i feel like i've asked this question before, but not sure i ever got an answer and scouring the forums isn't getting me anywhere...

i'd like a nice antialiased ellipse in GL.  i'm using 2.0a6.  this code:

Copy code
  1. void setup () {
  2.   size(200, 200, OPENGL);
  3. }

  4. void draw () {
  5.   background(0);
  6.   
  7.   ellipseMode(CENTER);
  8.   stroke(255);
  9.   noFill();
  10.   ellipse(0.5*width, 0.5*height, 100, 100);
  11. }
yields this image:

adding smooth() to setup() or to draw() has no effect.  the aliasing is even more apparent when the strokeWidth() increases...

Replies(15)

smooth() in OpenGL has no effect because it is enabled by default and cannot be turned off.
See the smooth() reference:

Starting in Processing 1.0, smoothing is always enabled with the OPENGL renderer setting. The smooth() and noSmooth() methods are ignored. See the hint() reference for information on disabling smoothing with OpenGL.

I feel like the issue with larger stroke weights has been brought up before... several times, at that...
Perhaps old, but here's one of the first things that I found: Bug 533
yeah, i noticed that in the reference...wasn't sure if that was still the case in 2.0.  and, i'd hardly call this smooth...not sure if my graphics card is missing some AA capabilities?  i'm on a 2011 MacBook Pro, AMD Radeon HD 6750M.

and yeah, the larger issue with stroke weights has definitely been brought up before, and line caps/joins.  but i can't even get a 1px strokeWeight to appear antialiased in GL...
i ran your example and got slightly different results, which include antialiasing.

Ubuntu 10.4, nVidia GT130M, Processing 1.5.1 and 2.0a5


hm.  seems that your hardware is doing *some* antialiasing (though that's not super-high quality...).  i zoomed in on the screenshots (using OSX's Digital Color Meter) and i see that my setup is not antialiasing at all, it's completely aliased.

any other OSX/Radeon users see the same, and/or know a way to get antialiased strokes or fills (i'm seeing aliased fills, as well) in GL?
Since higher strokeWeights make the ring look terrible (even with AA), I often use a manual solution which makes use of a TRIANGLE_STRIP. See the code example below. How do these look on your system?

Code Example
Copy code
  1. import processing.opengl.*;
  2.  
  3. void setup () {
  4.   size(300, 200, OPENGL);
  5. }
  6.  
  7. void draw () {
  8.   background(0);
  9.  
  10.   strokeWeight(10);
  11.   stroke(255);
  12.   noFill();
  13.   ellipse(0.25*width, 0.5*height, 100, 100);
  14.  
  15.   PVector v = new PVector(0.75*width, 0.5*height);
  16.   noStroke();
  17.   fill(255);
  18.   drawRing(v, 45, 55, 100);
  19. }
  20.  
  21. void drawRing(PVector v, float innerRad, float outerRad, int points) {
  22.   float px = 0, py = 0, angle = 0;
  23.   float rot = 360.0/points;
  24.  
  25.   beginShape(TRIANGLE_STRIP);
  26.   for (int i=0; i<points; i++) {
  27.     px = v.x + cos(radians(angle))*outerRad;
  28.     py = v.y + sin(radians(angle))*outerRad;
  29.     angle += rot;
  30.     vertex(px, py);
  31.     px = v.x + cos(radians(angle))*innerRad;
  32.     py = v.y + sin(radians(angle))*innerRad;
  33.     vertex(px, py);
  34.     angle += rot;
  35.   }
  36.   endShape();
  37. }
All right, I tested it in Processing 1.5.1 and 2.0a6:
  • In 1.5.1 there is a big difference between these two methods. One looks shit, the other smooth.
  • In 2.0a6 there is no difference between these two methods. Both look mediocre.

Hello, the new P2D/P3D renderers in 2.0a6 use hardware antialiasing through OpenGL. You set the desired level by calling smooth(n), where n is typically 2, 4, 8, etc., and depends on your video card. 8X should give you a quality level similar to that of JAVA2D, but it can be expensive specially on older/integrated cards.

The following chart gives you all the OpenGL capabilities across different cards models and OSX versions:


Look for the Max Samples entry near the bottom.

Ok, I'm happy to report that the smooth function, as pointed out by andres, works very well. For full comparison, I've tested the above code again under different smooth settings. Of course the biggest quality improvement is in the first step (from 0 to 2). You really have to zoom in to see that smooth(8) is even better.

The difference between the methods is also gone, except for a small crevasse when using strokeWeight.





thanks andres.

i tried adding smooth(2) to my initial test code (above), to setup() -- no change.  tried it in draw(), before calling ellipse() -- no change.  tried both with smooth(8) instead -- no change.

i looked at that opengl capabilities link you sent, andres, and i see 8 for my adapter's Max Samples.  not sure if it's a one-to-one comparison with the parameter to smooth(), but regardless i'm not seeing any difference -- still completely aliased.

am i missing something?
What version of OSX are you using?
10.6.8.  i clicked 10.6.8 on that apple link to get the info i posted above.
Well, that's strange. I know that antialiasing is giving some trouble in Lion and newer (see  this for more details), but never seen any issues with the smooth() function on 10.6. What video card do you have?

i'm on a 2011 MacBook Pro, AMD Radeon HD 6750M.
just read your bug report on the jogamp list.  wow.  thank you for all the work you're putting into processing, andres!! we're so incredibly lucky to have someone as devoted and thorough as you on the processing team.  really appreciate it.
I see. The antialiasing bug appeared to be limited to AMD cards on Lion or newer, but maybe it happens on older versions of OSX as well (but because I only have one macbook pro with Snow Leopard and NVidia GPU I cannot check this). The workaround in 2.0a6 kicks in only when it detects an OSX version greater or equal than 10.7, in the recent trunk revisions I made it so its enabled in 10.6 as well.

thx andres!  that did it.
(this is with smooth(8).)