Color blending with OpenGL
From Processing
| Versions: | 1.0+ |
| Contributors: | Michael Chang (mflux) |
| Started: | 2009-09-25 |
GL allows us to do things with pixels that we otherwise wouldn't be able to. You can get away with blend using image functions and pixels array with normal Processing GL, but this goes a step beyond that.
Source Code
/** blending taken from http://wiki.processing.org/index.php?title=Color_Blending_with_OpenGL @author mflux */ import processing.opengl.*; import javax.media.opengl.GL; // <-- don't forget to include this! // an access point to opengl GL gl; void setup(){ size(800,160,OPENGL); // hook into opengl gl=((PGraphicsOpenGL)g).gl; } void draw(){ background(0); fill(20); stroke(50); float x = 0; translate(0,5); // normal gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glBlendEquation(GL.GL_FUNC_ADD); for(int i=0;i<200; i++){ x = lerp(x, width, 0.05f); ellipse(x,40, 60, 60); } x = 0; translate(0,70); // additive blending gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); for(int i=0;i<200; i++){ x = lerp(x, width, 0.05f); ellipse(x,40, 60, 60); } }
Downloads
Related Links
NeHe on Blending and Transparency OpenGL FAQ on Transparency, Translucency, and Blending