Masking with blending

Started by
2 comments, last by vincoof 14 years, 1 month ago
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?
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
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]
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.

This topic is closed to new replies.

Advertisement