Jump to content
  • Advertisement

Archived

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

stooge_dev

sprites in windows

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

This code draws a bitmap to the screen with the transparent pixels skipped. It works, except the background shows through the image that is drawn. How can I fix this?
int DrawSprite(HDC hdc, HBITMAP hbmColour,int x, int y, COLORREF crTransparent)
{
	HDC hdcMem, hdcMem2;
	HBITMAP hbmMask, hOldBitmap, hOldBitmap2;
	BITMAP bm;
	GetObject(hbmColour, sizeof(BITMAP), &bm);
	hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);

	hdcMem = CreateCompatibleDC(hdc);
	hdcMem2 = CreateCompatibleDC(hdc);

	hOldBitmap = SelectObject(hdcMem, hbmColour);
	hOldBitmap2 = SelectObject(hdcMem2, hbmMask);

	SetBkColor(hdcMem, crTransparent);

	BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

	BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT);

   BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCAND);

	BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);

   SelectObject(hdcMem, hOldBitmap);
   SelectObject(hdcMem2, hOldBitmap2);
	DeleteDC(hdcMem);
	DeleteDC(hdcMem2);
   DeleteObject(hbmMask);
	return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you need an offscreen buffer, google for double buffering

Share this post


Link to post
Share on other sites
That''s what is supposed to be accomplished by transparancy.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
You can get the program from here and click on space invader clone. As you'll see the star is showing through the red area of the ship. This gives the star a red tint instead of making it hidden under the ship.

[edited by - stooge_dev on August 11, 2003 6:07:30 PM]

Share this post


Link to post
Share on other sites
no. all of what they said is incorrect. the colors look starced and its semi transparent? yeah thats a flaw with the bitblt function in windows. EVERY blitted sprite has to have a mask, and if you are using the masks correctly, then check your copy method. i dont think SRCINVERT is the right one, try SRCPAINT.

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!