How to use OpenGL blending with GLModels in GLGraphics
in
Contributed Library Questions
•
1 years ago
I was testing out some additive blending in GLGraphics and I wasn't seeing any effect. I brought it down to the basic example below based on the wiki's blending example. As you can see OpenGL blending as such does work within GLGraphics as can be seen from the difference between the first and second row of ellipses. However I can't make it work with GLModels, as seen from the third row of planes. The example is pretty basic (in the real sketch there are many different GLModels), but it's just to show the problem.
The fact that OpenGL blending does not work on a GLModel can also be seen in the example included with the GLGraphics library itself (Integration > OpenGL). Disabling the depth mask works, but the blending has no effect. I have tested this on both a Radeon and NVIDIA card using Processing 1.5.1 and GLGraphics 1.0.0.
My question is: how can I use OpenGL blending on GLModels in GLGraphics?
Code Example
The fact that OpenGL blending does not work on a GLModel can also be seen in the example included with the GLGraphics library itself (Integration > OpenGL). Disabling the depth mask works, but the blending has no effect. I have tested this on both a Radeon and NVIDIA card using Processing 1.5.1 and GLGraphics 1.0.0.
My question is: how can I use OpenGL blending on GLModels in GLGraphics?
Code Example
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- import javax.media.opengl.GL;
- GLModel plane;
- int c = 50; // global 'color'
- void setup() {
- size(800, 160, GLConstants.GLGRAPHICS);
- createPlane();
- noStroke();
- }
- void draw() {
- background(0);
- fill(c);
- GLGraphics renderer = (GLGraphics)g;
- renderer.beginGL();
- GL gl = renderer.gl;
- float x = 0;
- for (int i=0; i<200; i++) {
- x = lerp(x, width*1.9, 0.05f);
- ellipse(x, 40, 60, 60); // regular
- }
- gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); // additive blending
- x = 0;
- translate(0, 80);
- for (int i=0; i<200; i++) {
- x = lerp(x, width*1.9, 0.05f);
- ellipse(x, 40, 60, 60); // blending works
- }
- x = 0;
- translate(10, 40);
- for (int i=0; i<50; i++) {
- x = lerp(x, width, 0.05f);
- pushMatrix();
- translate(x, 0);
- renderer.model(plane); // blending does not work
- popMatrix();
- }
- renderer.endGL();
- }
- void createPlane() {
- plane = new GLModel(this, 4, QUADS, GLModel.STATIC);
- plane.beginUpdateVertices();
- plane.updateVertex(0, -20, -20, 0);
- plane.updateVertex(1, +20, -20, 0);
- plane.updateVertex(2, +20, +20, 0);
- plane.updateVertex(3, -20, +20, 0);
- plane.endUpdateVertices();
- plane.initColors();
- plane.beginUpdateColors();
- plane.updateColor(0, c, c, c, 255);
- plane.updateColor(1, c, c, c, 255);
- plane.updateColor(2, c, c, c, 255);
- plane.updateColor(3, c, c, c, 255);
- plane.endUpdateColors();
- }
1