Jump to content
  • Advertisement
Sign in to follow this  
carrigda

OpenGL Masking with blending

This topic is 3127 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

Hey All, I have a 2d openGL scene set up with a lot of texture mapped polys. I'd like it so that I can mask different different ones based on where an object is... Something along the lines of: http://www.smartwebby.com/Flash/photo_masking_effects.asp with my scene, except instead of adding/removing color, I'd like to add and show additional objects. So there's my scene, and when the user shines a blacklight over an area, another object appears there. Any thoughts?

Share this post


Link to post
Share on other sites
Advertisement
For masking you can follow this tutorial
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20
Just move the texture coordinates of the "mask texture" every frame for the desired effect

Share this post


Link to post
Share on other sites
I'm already using blending for pngs with transparency, using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), or glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR) for some images to get some neat additive blending.

With this in mind, the tutorials say something along the lines:
glBlendFunc(GL_DST_COLOR,GL_ZERO);
Draw mask
glBlendFunc(GL_ONE, GL_ONE);
Draw second texture

Obviously, I want to preserve the current blending I'm using, so I've been trying:
glBlendFunc(GL_DST_COLOR,GL_ZERO);
Draw mask
Set desired blend
Draw second texture

...but this doesn't really work out, as I end up with large areas of the mask being visible.

Am I doing something wrong here, is it not possible to do masking with my current blend modes, or am I missing something?


Example I'm trying to get: http://i.imgur.com/IN7cu.png

[Edited by - carrigda on February 22, 2010 5:17:28 PM]

Share this post


Link to post
Share on other sites
The example you are trying to get is about making a hole so that parts of an object are not visible. If that is what you want, you can use many buffers such as the stencil buffer or the alpha buffer. My favorite is certainly the depth buffer as you are 100% sure it works on any graphics card and is hardware-accelerated :
glDepthRange(0,0); // Force writing to the nearest depth value ever possible
Draw your "digging" mask
glDepthRange(0,1); // Standard depth mapping
Draw your object

This way you can still use glBlendFunc for additive blending or whatever.

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!