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 › Color blending in OpenGL
Page Index Toggle Pages: 1
Color blending in OpenGL (Read 543 times)
Color blending in OpenGL
Mar 3rd, 2006, 9:51pm
 
Hello, I am attempting to blend colors using alpha (ala flash 8's additive blend).  So far it seems to work with two layers but if I add a third layer the color is always shaded like the top color.  I'm aware of blend() the then I would need to keep track of the colors in an array and I would much rather just slap the shape primitives on top of each other.  Here's a simple example of what I'm trying to do, I would expect the combination of all three to be gray.  But instead it slightly red since the Red Square is the last one I draw.

import processing.opengl.*;

void setup()
{
 size(800, 600, OPENGL);
 noStroke();
}

void draw()
{
 background(255);
 fill(0, 255, 0, 85);
 beginShape(QUADS);
 vertex(20, 20);
 vertex(100, 20);
 vertex(100, 100);
 vertex(20, 100);
 endShape();
 
 fill(0, 0, 255, 85);
 beginShape(QUADS);
 vertex(30, 30);
 vertex(110, 30);
 vertex(110, 110);
 vertex(30, 110);
 endShape();
 
   fill(255, 0, 0, 85);
 beginShape(QUADS);
 vertex(40, 40);
 vertex(120, 40);
 vertex(120, 120);
 vertex(40, 120);
 endShape();
}

Thanks,
Bentopia
Page Index Toggle Pages: 1