Jump to content
  • Advertisement
Sign in to follow this  
Darobat

How would I make this double buffer?

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

Greetings. How would I make this function for drawing bitmaps a double buffered function, so that it doesnt filcker. How would I then display the scene? Thanks.
BOOL BMP::Draw(UINT TransColor)
{
	BITMAP BM;
	HBITMAP BmpOld;

	if(hDC == NULL)	// Make sure we are painting
	{
		MessageBox(NULL, "Invalid HDC", "Error", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	hDCMem = CreateCompatibleDC(hDC);
	BmpOld = (HBITMAP)SelectObject(hDCMem, Bitmap);
	GetObject(Bitmap, sizeof BM, &BM);

	// Draw it either with or without transparency
	if(TransColor == 0)
		BitBlt(hDC, X, Y, Width, Height, hDCMem, 0, 0, SRCCOPY);
	else
		TransparentBlt(hDC, X, Y, Width, Height, hDCMem, 
			0, 0, Width, Height, TransColor);

	SelectObject(hDCMem, BmpOld);
	DeleteObject(hDCMem);
	return TRUE;
}

Share this post


Link to post
Share on other sites
Advertisement
You dont do it in that function.

Presumably hDC is aquired from BeingPaint or GetDC.

You must create another compatible bitmap for the back buffer the size of your window/screen and a compatible DC.(lets call it it hDC2) All your BMP::Draw functions must blit to this hDC2.

When you are totaly finished drawing you Blit from hDC2 to hDC and then release hDC. Therefore there should only be one vlit to hDC (The window DC) at the end.

(Personaly id keep hDC2 and your compatible backbuffer bitmap ready. Create them the first time they are needed. But dont delete them till your app is finished. And obviosuly dont create them more that the first time)

Share this post


Link to post
Share on other sites

HDC memDC = CreateCompatibleDC(hdc);//our screen buffer
HBITMAP bmp = CreateCompatibleBitmap(hdc, 640, 480); //a bitmap for our buffer
SelectObject(memDC, bmp);//put bitmap in buffer

//do all blitting/drawing to memDC, and when you are done...

BitBlt(hdc, 0, 0, 640,480, memDC, 0, 0, SRCCOPY);//draw buffer to sreen
DeleteDC(memDC);



hope that helps

Share this post


Link to post
Share on other sites
If i was to change my Draw function so it would blt to memDC, and then in WM_PAINT Called BitBlt(hdc, 0, 0, 640,480, memDC, 0, 0, SRCCOPY);, would that work?

Share this post


Link to post
Share on other sites
Quote:
Original post by Darobat
If i was to change my Draw function so it would blt to memDC, and then in WM_PAINT Called BitBlt(hdc, 0, 0, 640,480, memDC, 0, 0, SRCCOPY);, would that work?
Yes, if I understand you correctly.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!