Archived

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

Strewth

HDC & BitBlt

Recommended Posts

Strewth    146
Hello all, I''m having some problems which I suspect are pointer related. So what i''m doing is the game app''s Draw function is telling the background to draw itself on the back buffer HDC, and then flipping that on to the front buffer. However this isn''t happening. If I dummy it up so that the code in CBackground''s Draw function occurs in CGameApplication''s Draw function then everything works ok. Is the hdc being passed to CBackground->Draw() not being updated? Here''s my code for the relevant sections:
bool CGameApplication::Draw()
{
	// Draw background - m_pBackground is CBackground, m_pBackBuffer is HDC, both members of CGameApplication

	m_pBackground->Draw(m_pBackBuffer);

	// Draw sprites


	// Flip to front buffer

	BitBlt(m_pFrontBuffer, 0, 0, 1024, 768, m_pBackBuffer, 0, 0, SRCCOPY);

	return true;
}

bool CBackground::Draw(HDC hdc)
{
	HDC hdcBitmap;
	HBITMAP hBmpOld;
	BITMAP tmpBmp;

	hdcBitmap = CreateCompatibleDC(hdc);
	hBmpOld = (HBITMAP)SelectObject(hdcBitmap, (HBITMAP)m_hBackground);
	
	GetObject(m_hBackground, sizeof(tmpBmp), &tmpBmp);
	BitBlt(hdc, 0, 0, tmpBmp.bmWidth, tmpBmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
	SelectObject(hdcBitmap, hBmpOld);
	DeleteDC(hdcBitmap);

	return true;
}

Share this post


Link to post
Share on other sites
Strewth    146
Also, I''ve noticed that if I pass in m_pFrontBuffer to CBackground->Draw() then the background is displayed properly.

I''ve been searching google for more info about using HDCs this way and it sounds like I shouldn''t pass them around to functions, is that correct?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
if you searched a little bit harder you would have realized that the win GDI graphics functions are terribly slow. learn SDL, you get the speed without having to worry about device contexts. trust me, ive been there. Another Advantage: you wont have to use black sillouetted masks, ie 1 sprite = 1 blit.

Share this post


Link to post
Share on other sites
Colin Jeanne    1114
You can most certainly pass HDC objects to functions.

Are your GDI functions failing? If so, what does GetLastError() return? What do you see in place of the background? Just black? If so, are you sure that the m_pBackBuffer is the correct bit depth (remember that memory HDC''s start with a monochrome 1x1 bitmap)?



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites
Strewth    146
Thanks for the replies.

I checked if GetLastError() returned anything and its not returning any errors.

It just seems that whatever I do to the hdc being passed into the Draw function is lost when it returns to the calling function.

Very frustrating!

Share this post


Link to post
Share on other sites