Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GroZZleR

Transparent Blitting with the GDI.

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''ve read a couple of articles on transparent blitting using the GDI, and I''ve come to the following conclusions. 1. TransparentBlit is no good because it has memory leaks on Win 95 / 98. 2. You can create a seperate black and white image of the sprite and then bitmask out the transparency. Neither of these solutions are viable for me, as I really don''t want to go through the hassle of creating seperate images and loading them and such, just for a little transparency on some sprites. The other solution I came up with, was creating the bitmasked bitmaps dynamically when the file is loaded and storing that off just in-case. I thought this might be the most viable solution, but am unsure of how to approach the problem. Any suggestions or other methods?

Share this post


Link to post
Share on other sites
Advertisement
You could load your bitmaps in as 32-bit images and specify 0 for the alpha value of any pixels with the mask color. Then you can use AlphaBlend() to blit the image.

Share this post


Link to post
Share on other sites
If using transparentblit is not an option for you and you don''t want to make black/white copies(bitmasks) of everything by hand, then creating a dynamic bitmask is a viable option although creating it on the fly each time you need it isn''t a good idea. I may have misread but possibly dynamicly create a bitmask once when you load the image and use it later. This will slow down load times but unless you are using huge amounts of graphics, it shouldn''t be too bad. Of course, there is always the option of using DirectDraw along with GDI which is pretty straight forward and also allows hardware transparent blitting without the need for bitmasks and works just fine on win95 - winxp. Setting up DirectDraw isn''t very difficult and for simple 2d stuff, it will save you many headaches that straight GDI will give you such as the transparent blitting thing.

Evillive2
E-Mail

Share this post


Link to post
Share on other sites
I''m working on a pure GDI wrapper, so its not a viable option for me to use DirectDraw. I''ve used DirectDraw before and currently am in my engine, but this is more of a side-project for fun =)

Any tutorials / leads on how to dynamically generate the bitmask? The only thing I could think of would be to GetPixel the bitmap and replace all instances of the colorref that we''re going for (ie, pink) to black (or is it white? I don''t remember now). And then change everything else to white.

GetPixel is excuitiaingly slow, and I''m not even sure I can use it on a DDB.

Share this post


Link to post
Share on other sites
Make the part of the bitmap you want to be transparent pure black, RGB(0,0,0). Then when you call BitBlt pass SRCPAINT as the raster operation code, which will logically OR the pure black parts of the bitmap out.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!