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!