We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Anti-Aliasing for OSX Users
Pages: 1 2 
Anti-Aliasing for OSX Users (Read 9116 times)
Anti-Aliasing for OSX Users
Nov 22nd, 2006, 11:54pm
 
So, I just made the switch from Windows to OS X with the purchase of a new 15" MacBook Pro. One of the first things I noticed was that it was not (easily or apparently) possible to enable anti-aliasing for P5 sketches that used OPENGL as the renderer. After some Googling for enabling anti-aliasing in JOGL, I realized that I'd need to do it at the application level, specifically where the PApplet instantiates the PGraphicsOpenGL class.

After downloading the source code and some futzing, I managed to create a custom version that allows a user to enable OpenGL anti-aliasing for their sketches. Here are some snippets of what I implemented:

In PApplet, I added a couple variables:

Code:

private boolean isAntiAliased;
private int numSamples;


I set the default value in the constructor to true and 0 respectively.

Then I added a couple public methods in PApplet:

Code:

public boolean getIsAntialiased() {
return isAntiAliased;
}

public void setIsAntialiased(boolean useAntialiasing) {
isAntiAliased = useAntialiasing;
}

public void setNumSamples(int samples) {
numSamples = samples;
}

public int getNumSamples() {
return numSamples;
}


Lastly, in the PGraphicsOpenGL class, within the allocate() method, where it first creates a new GLCanvas, I added the following lines:

Code:

GLCapabilities capabilities = new GLCapabilities();
capabilities.setSampleBuffers(parent.getIsAntialiased());
if(parent.getIsAntialiased())
capabilities.setNumSamples(parent.getNumSamples());
canvas = new GLCanvas(capabilities);


Now, I'm not sure that this is necessarily the most elegant implementation of enabling anti-aliasing for an OpenGL render, since I'm not terribly familiar with the Processing source code and JOGL. I couldn't find any reference for being able to change the capabilities of the GLCanvas after it has already been instantiated. And a downside to this method is that you must call setIsAntialiased(true) and setNumSamples(XX) before calling the size() method.

In an ideal world you would simply pass it along as an optional parameter with the size method, it seems:

Code:

// The number 4 below indicates that you want
// 4x sampling for anti-aliasing
size(640, 480, OPENGL, 4);


Is there any way that this can be implemented in a future build of Processing so that users can enable anti-aliasing from within their sketch as opposed to some driver configuration panel (for Windows users) or no other option, to my knowledge (for OS X users)?

Any insight would be great. Thanks!
Re: Anti-Aliasing for OSX Users
Reply #1 - Nov 23rd, 2006, 12:12am
 
I did some digging about this a while ago too, and came to pretty much the same conclusion as you have. I added the GLCapabilities part for myself, but realised it was a bit of a hack, and would be a bit of a faff to get a nice way to set the sampling level on startup, so pretty much gave up trying to make a public version of it.

As a side note, I think you may also need a gl.glEnable(GL.GL_MULTISAMPLE); somewhere or it may not be used, even if it's capable.
Re: Anti-Aliasing for OSX Users
Reply #2 - Nov 23rd, 2006, 10:52am
 
One possible way around this would be to create a few classes that extend PGraphicsOpenGL and only implement the constructor, and allocate method.

e.g. create a class PgraphicsOpenGL4xAA which has an allocate method that sets up the sample buffers, but lets the normal PGraphicsOpenGL handle every other function.

You can then create this with size() similar to normal:

size(800,600,"my.library.PGraphicsOpenGL4xAA");

That way you don't lose or ahve to re-implement any of the functionality, and the wrapper classes are small and shuold cause little overhead.
Re: Anti-Aliasing for OSX Users
Reply #3 - Dec 18th, 2006, 4:11pm
 
A none-coding attempt to enable Anti-Aliasing:
(I tried this on a Dual G5 equipped with a ATI Radeon 9650.)

I exported the sketch as an application. Then I launched ATI Displays (http://www.macupdate.com/info.php/id/13327) and created a new Application Profile under "3D". I selected the exported sketch as the application and chose the "Best Quality"-Preset.

When I launched the sketch application I had working AA.
Re: Anti-Aliasing for OSX Users
Reply #4 - Feb 19th, 2007, 3:56am
 
Thanks a lot !!!
Re: Anti-Aliasing for OSX Users
Reply #5 - Apr 7th, 2007, 3:43am
 
Hi guys. I have made what is beginning to look like the mistake of buying a Mac Mini Intel, thinking that I could run installations off it. It's the one with the GMA 950 card, so I know it's not the best computer in the world, but still.

Anyway, so I tried the GLCapabilites hack for PGraphicsOpenGL, but I can not get any anti-aliasing going. This is regardless of whether I use Processing with a builtin OpenGL demo or I compile and run from Eclipse. Btw, GL.GL_MULTISAMPLE should be enabled by default, but even doing it manually has no effect.

Has anyone got this working, or should I just start treating the cute little thing as a $1000 external harddrive? The really bad thing is that I have no way of knowing if an app will have AA if run on another Mac model.
Re: Anti-Aliasing for OSX Users
Reply #6 - Apr 7th, 2007, 5:34am
 
Eek.

a) I'm sorry you purchased the Mac Mini with the assumption that you'd be able to run OpenGL-driven P5 applets with any level of anti-aliasing (while maintaining any sort of framerate).

b) I have absolutely no authorative answer for you, but am I wrong in guessing that while a card may have basic OpenGL support, it doesn't necessarily support any degree of Anti-aliasing and would simply "fail silently" when asked to anti-alias a scene in OpenGL?

When I think back to all kinds of cards as they were coming out (when hardware acceleration was just becoming possible), one of the "features" always listed was something like 4x anti-aliasing (or more obviously). So, my assumption (maybe it's bad to assume) is that the card simply doesn't support OpenGL anti-aliasing at any level.

So while the Processing code may be working, it's simply "failing silently" when it attempts to tell your card what to do.

But I will say that most likely, your code will work on those other Macs that have something more than a graphics chip built into the motherboard.
Re: Anti-Aliasing for OSX Users
Reply #7 - Apr 7th, 2007, 5:43pm
 
Mike, thanks for the response. I implemented your code and had a friend test it, who confirmed that your technique works on her Mac. I had her test it with the regular Processing code, and that did not anti-alias properly.

On my PC with a Nvidia card I previously had to hardwire the anti-aliasing setting in the Nvidia control panel. But with your code I can leave it on "Application-controlled", and it will still be smooth. That's an improvement both on Mac and PC, so thanks for the hack.

As for the Mac Mini, the <a href="http://www.intel.com/products/chipsets/gma950/">spec sheet</a> for the GMA 950 does not mention anti-aliasing. I  guess it was naive of me to assume it would at least do a minimum of AA. In fact, I might try to return it based on the fact that this detail is pretty hard to discern from the information given by Apple.
Re: Anti-Aliasing for OSX Users
Reply #8 - Apr 8th, 2007, 10:01am
 
did you make sure to run all of the software updates? sometimes apple slips in a driver update or two that might help. I don't have a mini so i can't say for sure.

Also, if you must, you could try to install windows and see if the windows driver has better luck. Again, this is just conjecture, i haven't tried myself.
Re: Anti-Aliasing for OSX Users
Reply #9 - Apr 8th, 2007, 6:38pm
 
I have installed all updates available, so it's not likely to be a simple driver issue. Is there even a way to figure out which driver is in use etc On Windows driver hacks are so prevalent it gives you a different kind of headache, but since I haven't worked on a Mac for so long I'm feeling the familiar sense of staring at a blank wall of user-friendliness...

I will call Apple next week to check, but it seems likely that the GMA 950 is missing AA since I've had it confirmed that it works on other Mac models.

As an aside, I've blogged some useful tips for deploying Processing applications on the Mac OS platform.

It is primarily aimed at people who (like me) write their applications outside the Processing IDE. It also includes a reference to this discussion, as well as how to auto-hide the dock and menu bar on application start. It's all easily done by using Processing's own application export as a template.
Re: Anti-Aliasing for OSX Users
Reply #10 - Apr 12th, 2007, 8:12pm
 
I've create a new class that extends the PGraphicsOpenGL class and overwrite the allocate function. It works well but now I've got problems to do to things like this:
Code:
((PGraphicsOpenGLExt) g).gl.glDisable( GL.GL_DEPTH_TEST ); 


When I change the line
canvas = new GLCanvas(capabilities);
back to
canvas = new GLCanvas();
the openGL stuff work.

Does someone know what happens?
Re: Anti-Aliasing for OSX Users
Reply #11 - Apr 30th, 2007, 4:47pm
 
I had enough requests in a workshop for a drop-in AA hack that I posted a opengl.jar replacement on my Code & Form blog. Simply download and drop into the "libraries\opengl\library" subfolder of the Processing application library, and all your sketches should have 4x supersampling forced for OpenGL.

Remember to keep a copy of the old opengl.jar just in case everything breaks...
Re: Anti-Aliasing for OSX Users
Reply #12 - Apr 30th, 2007, 11:45pm
 
Thank you so much watz, i was waiting for this hack for macintel for so long.

The only way to activate AA on Mac was by using an app profile in ATI pref panes. (it is only PPC)

4x AA is simply great. Smiley
Re: Anti-Aliasing for OSX Users
Reply #13 - May 2nd, 2007, 3:26am
 
Awesome!  Works flawlessly!  Thank you so much!
Re: Anti-Aliasing for OSX Users
Reply #14 - May 2nd, 2007, 7:06am
 
Glad you like it. The downside is that (as observed by Eskimoblood) when using the hack it is no longer possible to get "trails". The screen is always cleared between frames. I'm not sure if there is a solution that allows anti-aliasing while not erasing the existing image.
Pages: 1 2