Sign in to follow this  

Need the simplest possible way to draw textures with alpha

This topic is 3595 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, i have a simple 2d game i am making, I am using ortho mode, and have the depth buffer disabled. I also have several 2d sprites, all squares, but i want to be able to draw them ontop of each other. The pixels are either transparent, ie alpha = 0, or completely opaque, alpha = 255 (as sourced from the bitmap image). What is the easiest possible way to draw these ontop of each other. Right now drawing one ontop of the other will result in black being draw to where the alpha, transparent, pixels should have been.

Share this post


Link to post
Share on other sites
You should be able to use alpha testing for this:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.f);
(Note: Syntax not guaranteed to be correct.)

You might also want to look into alpha blending, in case you want to have translucent sprites at some point in the future.

Share this post


Link to post
Share on other sites
I recommend Lonesocks library, SOIL. http://www.lonesock.net/soil.html

It loads and applies textures for you. I currently use .tga files, since they support transparency, and GIMP can export them well.

Then, just set the correct mode as JYK said and tada alpha blended textures.


REALLY IMPORTANT NOTE:

you need to re-order your sprites so they are drawn in the order of their distance from the camera, as OPenGL won't automatically do this, and will cause lots of problems whereby two overlapping semitransparent polygons have the wrong thing behind them. Luckily you are doing it in 2d and so its far easier. Turn off depth testing, then draw your sprites starting with the background and so on in descending order of their distance from the screen.

Share this post


Link to post
Share on other sites

This topic is 3595 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this