Jump to content
  • Advertisement
Sign in to follow this  
bennyW

OpenGL OpenGL Blend Question

This topic is 4575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm new to OpenGl so please bear with me. I'm trying to clear out alpha in a section of the frame-buffer and then later draw to only sections where alpha is 1. I'm using OpenGL ES 1.1 which doesn't allow masking of individual color channels. So I figured I'd accomplish this by drawing sprites.
// Clear Alpha Pass
// Sprite color = (0,0,0,1)
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
Does that look okay so far? I'm testing it by drawing another sprite over it which should only draw in areas where the frame buffer has an alpha of 1. So I drew the sprite with 0,0,1,0:
// Test Pass, nothing should show up
// Sprite color = (0,0,1,0)
glBlendFunc(GL_DST_ALPHA, GL_ONE);
The problem is this sprite draws when I think it shouldn't. Am I wrong? If I change the src factor in my test pass to GL_ONE_MINUS_DST_ALPHA, then the sprite doesn't draw...almost like its the reverse of what I expect. Thanks, BennyW

Share this post


Link to post
Share on other sites
Advertisement
instead of glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); try
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);... that's the blend function most commonly used, i hope that helps.

Share this post


Link to post
Share on other sites
I'm using blending to clear out the alpha channels in a region of the frame-buffer not to write color values. Basically creating a mask of sorts.

I'm finding that if I draw a test sprite with this:
glBlendFunc(GL_DST_ALPHA, GL_ONE);

on a screen I just cleared, it shows up. It shouldn't though, right? B/c the dest alpha should be 0 which should effectively cancel out the color contribution of my test sprite.

[edit: added]
As I test, I tried this with the nehe tutorial that just draws a colored triangle and a quad.

Share this post


Link to post
Share on other sites
This isn't perhaps the most efficient manner for masked rendering. The stencil buffer might be more suited to your needs. If you are just trying to render a masked sprite, you can build the alpha mask right into the sprite texture and use the alpha test - no blending is required, and it can be done in a single pass. Of course blending can smooth the edges if you have coverage values other than zero and one.

Share this post


Link to post
Share on other sites
Not sure I understand what you're saying.

I can't build the alpha mask into the sprite, b/c this mask could potentially change per-frame due to occlusion. I need the alpha values to modulate with a glare-sprite. I'll try to think up some new ways.

I'm starting to think that there is no alpha channel in my frame buffer. Any pixels I read back always have an alpha of 1 despite the fact that I clear it to 0.

Share this post


Link to post
Share on other sites
When you create the window and choose the pixel format, make sure you request alpha bits as well as color bits. Also make sure your desktop is 32-bit, not 24. I'm not sure I understand exactly what you are trying to do, would the stencil buffer be an appropriate solution?

Edit - I just noticed you are using OpenGL ES. You may not have the ability to request alpha planes, depending on your device. Hopefully stencil planes are supported.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!