Mini-tutorial: Additive Blending
I have been getting a few requests lately about the hows and whys of additive blending so I thought I would whip up a quickie little tutorial to get those interested parties on the path to easy glowiness. But first, the standard disclaimer.
I AM NOT A GOOD TEACHER!!! Here is why. I dont really know OpenGL. I dont know much about the limitations of JOGL either. What I do know is that with Processing, I can make OpenGL calls that can do great things but as for why they work or why they might be better or why I didnt optimize them further, the simple answer is that I am learning just like the rest of you. So please keep these 2 points in mind when you read the rest of this post.
1) If you have problems with the source code, please research the answer yourself. I wont be able to help you understand why you are getting an error with Processing v.123 on Windows running Vista with 2 webcams attached and Java version 1.4 with a cat on your lap and the right mouse button pressed. I would probably just refer you to the Discourse section of Processing.org.
2) If you can improve this code or help me understand more about why it works, please post your comments here instead of emailing me so that others can benefit from your knowledge. Im sure there are ways to make the following info much tighter and stronger… so chip in your 2 cents so we can all be a bit richer.

On the left is a screengrab from the supernova project without any blending. On the right, I have added additive blending and disabled the depth test. Suddenly, the orb glows are more glowy and the overlap issue goes away entirely. Lets look at the code.
First, you will need to make a new PGraphicsOpenGL and GL object. Before you can do this, you need to make sure you import the proper libraries. Stick this code in with your other import statements if you have any. The top one makes sure you can use the OPENGL renderer specified in your size() method, and the second is the JOGL stuff you will need.
import processing.opengl.*;
import javax.media.opengl.*;
Then you make your PGraphicsOpenGL and GL objects.
PGraphicsOpenGL pgl;
GL gl;
In your setup code, you will need to define these pgl and gl objects so put in the following after your size() method.
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
Almost there! The only thing left is to do the additive blending magic. It is soooo easy! You will kick yourself. Stick this at the beginning of your draw method.
pgl.beginGL();
// This fixes the overlap issue
gl.glDisable(GL.GL_DEPTH_TEST);// Turn on the blend mode
gl.glEnable(GL.GL_BLEND);// Define the blend mode
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);pgl.endGL();
Voila! Glowy good times. The BlendFunc takes several parameters. Check here for a sample as to why I dont bother getting too invested in the ‘why’ this works.
Go and glow.


















