Jump to content
  • Advertisement
Sign in to follow this  
RunningInt

Drawing a transparent sprite using alpha blending

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

Trying to draw a texture so that part of the texture is transparent. Got it to work with a mask, but not keen on storing both a mask texture and the image texture. Can I use a single texture with an alpha channel for the same purpose instead? I can build textures using image data with an alpha channel:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 64, 64, GL_RGBA, GL_UNSIGNED_BYTE, texturedata);

To initialise the alpha blending:
glBindTexture(GL_TEXTURE_2D,textureid);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.5f);


But when the texture is displayed it is fully opaque (ie no transparency) even though alpha values vary across the image. Have I missed something important out?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by RunningInt
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 64, 64, GL_RGBA, GL_UNSIGNED_BYTE, texturedata);
Setting the internalformat parameter to 3 corresponds to GL_RGB, so it will not create a texture with an alpha channel. You should use 4 or GL_RGBA*.

* It's actually "safer" to set the internal format so that it specifies the bit depth of the texture you want as well, because on some drivers it may see GL_RGBA and choose a 16-bit rgba format because all you're requesting is 4 color channels. So, for example, if you want 32-bit rgba you should specify it with GL_RGBA8.

EDIT: Note to self: RGBA is 4 color channels [embarrass]

Share this post


Link to post
Share on other sites
ah thanks, this was very helpful. For some reason i presumed the second parameter was the number of levels of mipmaps to make. Also helpful about the use of GL_RGBA8

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!