Jump to content
  • Advertisement
Sign in to follow this  
Jenison

OpenGL Custom Masking Problem

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

I would like to use a custom mask color like Pink Now I'm trying to mask everything where its Pink to go through 100%. If its not its not blended at all. Now ever example I find uses two images for masking. One is the alpha channel, the other the image. as I said I tried searching for "custom mask" and googled custom mask color and didnt seem to get what I needed. 1. How would I specify I want a perticular RGB color to be my mask? 2. Is there a way to combine the two? Do I need to save / load my image data differently?

Share this post


Link to post
Share on other sites
Advertisement
If you don't like using two files, why dont you just use a file format the supports 4 color channels( TGA for one), then just use the last channel( alpha channle) as the masking or blending part.

BTW. NeHe has a tutorial on loading and blending 32 bit TGA files (GL_RGBA) correctly.
Shouldn't be that hard since your all ready loading images.

Share this post


Link to post
Share on other sites
if you want to do it using Opengl you have to generate the alpha channel yourself, this will probably allow for maximum flexibility

here is some pseudo code:


struct Image {
byte r, g, b, a;
} src, dest;

ForEach pixel in src
dest[pixelNum] = pixel;

if( pixel == maskColor )
dest[pixelNum].a = 0.0f;
else {
dest[pixelNum].a = 1.0f;
}

Next

createOpenGLTexture( dest );
...
now when you bind the texture, just enable alphatesting or alpha blending.

hope that helps.

Share this post


Link to post
Share on other sites
Thanks for the help ... however, I want to avoid binding two textures just to do alpha blending.

however, that does give me the idea of creating an RGBA texture from the given data. I simply write in the Alpha value where its the color that I want, and replace that value with pure black.

This would allow any image to be used with alpha channels even though it may not be saved as RGBA.

So many ideas ...
Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Jenison
Thanks for the help ... however, I want to avoid binding two textures just to do alpha blending. Thanks
you don't need two textures for alpha blending, you only need one texture with an alpha channel (ie. 32bit texture). here is the gluBuildMipMaps call i use to make my 32bit TGA texture (with alpha channel) OpenGL textures (with alpha maps)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image);
and when i want to render something with alpha blending i just do this
glBindTexture( GL_TEXTURE_2D );
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_BLEND );
drawObject();
glDisable( GL_BLEND );
hope that helps.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!