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 › enable and disable GL_BLEND
Page Index Toggle Pages: 1
enable and disable GL_BLEND (Read 2347 times)
enable and disable GL_BLEND
Feb 16th, 2010, 1:20pm
 
Hi, here is the setup, I have 2 PImage objects I need to display in the draw(), image 1 consist in a simple gradient .jpg it shows with no problems, image 2 is a 30% black stuff and 70% full transparent .png. This second image wont show up, here is my code in the draw()
Code:
gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

directionalLight(255, 255, 255, 0, 1, -1);
ambientLight(255, 255, 255);
 
// jpg
image(waterBG, 0, 0);
 
// png
image(reef, 0, 0);
 
pgl.endGL();


I try Code:
gl.glDisable(GL.GL_BLEND); 

after the jpg image but it doesnt work

Any ideas?

Cheers
rS
Re: enable and disable GL_BLEND
Reply #1 - Feb 17th, 2010, 1:15am
 
I sort of solve the problem

Code:

gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

directionalLight(255, 255, 255, 0, 1, -1);
ambientLight(255, 255, 255);
 
// jpg
image(waterBG, 0, 0);

// HERE I DRAW OTHER STUFF THAT NEEDS  ADD BLENDING

gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
pushMatrix();
translate(width - reef.width, 0.0, 1.0);
// png
image(reef, 0, 0);
popMatrix();
 
pgl.endGL();


Two things I did first add a blend function
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
so I can draw black pixels and second I move the image 1 forward, but as usual I got another problem, I lose the additive blending

By adding the second blend function the first one nevers activates again, so my question is how can I (if possible) use both?

Cheers
rS
Re: enable and disable GL_BLEND
Reply #2 - Feb 17th, 2010, 3:04am
 
You're trying to add a black/transparent texture with ADD blending? that won't work. as ADD black to some color will give you that color.

what exactly do you want to do ?
Re: enable and disable GL_BLEND
Reply #3 - Feb 17th, 2010, 3:10am
 
Hi V, I have 2 images

1) .jpg with color gradient
2) .png full transparent with some black dots

so I need to have the gradient image as background, draw some 3D stuff suing additive blend, and on top draw the black dots png image

Cheers
rS
Re: enable and disable GL_BLEND
Reply #4 - Feb 17th, 2010, 3:20am
 
ok, its pretty simple actually:


{
gl.glEnable(GL.GL_BLEND);

// disable zwriting for background image
gl.glDisable(GL.GL_DEPTH_TEST);
// alpha blend.
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

// render background image here
(.....)


//
// draw 3d scene here
//
// turn z writing on for 3d scene
gl.glEnable( GL.GL_DEPTH_TEST );
// set additive blend now. this will blend 3d scene with background image
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE );
// disable depthmask. uncomment and see the differences
//gl.glDepthMask( false );
gl.glDisable(GL.GL_DEPTH_TEST);
// render 3d scene here
(.....)
// restore depthmask writing
//gl.glDepthMask( true);


//
// render dot overlay
//

// disable zwriting for overlay
gl.glDisable(GL.GL_DEPTH_TEST);
// alpha blend.
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
// render overlay image here
(.....)

// render dot image here

}
Re: enable and disable GL_BLEND
Reply #5 - Feb 17th, 2010, 3:26am
 
Crystal clear many thanks V

rS
Re: enable and disable GL_BLEND
Reply #6 - Feb 17th, 2010, 5:07am
 
I try what your suggestion but the
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); is not doing it, the only blend working is the last one gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

Any ideas?

rS
Re: enable and disable GL_BLEND
Reply #7 - Feb 17th, 2010, 5:29am
 
does it look like alpha-blend?
maybe processing/whatever you're using, is overriding your opengl blend mode. can't be sure without more details
Page Index Toggle Pages: 1