OpenGL and 2D Masking
I created a 2D demo a while ago. It was pretty simple with just a sprite walking around. To make him transparent, I had to use a seperate sprite map that was black. I am assuming this is called masking. I got use to DirectDraw/Direct3D's way of doing 2D. There was no "seperate image," as it was an offscreen surface. I would just tell it not to blit a certain color to the back buffer. It did the trick. Is there anything like that in OpenGL? I'd hate having two seperate images just in hope for transparency purposes.
You can use blending. If you have, say a png file with an alpha channel, then you can:
But if the images overlap you get weird colors, so to get rid of that you have to use masking still.
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
I'm not really sure what I'm talking about, but I hope that was what you meant.
In The Gimp, I remember you can set a transparent color to an image. If that's predetermined, and you load the image into the program, would a masking image now be unncessary?
That will make the image transparent if you use blending, but to make sure the images overlap properly, you have to use masking. NeHe has some tutorials over blending and masking, if you haven't already checked them out.
Here in the game I'm working on, you can see what can happen if you don't mask an image.
See how the asteroids overlap.
Wow, that's just incredibly annoying ;) I tried PNG, tried my theory, and it didn't turn out nice. I guess I'm just use to working with directx surfaces. OpenGL seems to have another take on this. I always hated masking because if I make one change in the art, I have to remember to do it for the mask.
I came across this small PNG library... it uses no masking :)
Hmm, cool library. Did you remember to use the function
glBlendFunc(GL_SRC_ALPHA, GL_ONE); ?
Because that one works for me.
Am I stuck with masking though? I just find it really annoying. I don't know why OpenGL can't just ask what the RGB color is to ignore, and it would draw the image without that color.