Table of Contents

blending

versions0135+
contributorsmflux
started on2009-09-25 17:14

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://processinghacks.com/hacks:blending
@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);
  }  
}

Related Links

For more info on the way blending works and what other effects you can achieve check out:

Transparency, Translucency, and Blending

NeHe on blending and transparency

http://processing.org

hacks/blending.txt · Last modified: 2009-09-25 17:18 by mflux