• Advertisement

Archived

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

WinGDI Blitting Problem

This topic is 5977 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 created a Buffer image with CreateCompatibleBitmap() but can only blit the background to the buffer. Smaller images only produce a broken white image on the buffer. I can blit the background to the buffer, the buffer to the screen and the blocks to the screen but not the blocks to the buffer, for some reason. Can anyone help me? Blitting code
  
void Draw_Blocks()
{

	if(!BitBlt(hdcBuffer, 0, 0, 224, 364, hdcBackground, 0, 0, SRCCOPY))
	{
		MessageBox(NULL, "Failed to blit background.", "Tetris++", MB_OK);
		PostQuitMessage(0);
	}

	if(!BitBlt(hdcBuffer, 0, 0, 32, 32, hdcBlocks, 0, 0, SRCCOPY))
	{
		MessageBox(NULL, "Failed to blit blocks.", "Tetris++", MB_OK);
		PostQuitMessage(0);
	}

}

void Draw_Screen()
{

	if(!BitBlt(WindowDC, 0, 0, 224, 364, hdcBuffer, 0, 0, SRCCOPY))
	{
		MessageBox(NULL, "Failed to blit to screen.", "Tetris++", MB_OK);
		PostQuitMessage(0);
	}

}
  
the loading code
  
HBITMAP hBlocks = NULL;
RECT	rBlocks ;
HDC	hdcBlocks = CreateCompatibleDC(0);

HBITMAP hBackground = NULL;
RECT	rBackground;
HDC	hdcBackground = CreateCompatibleDC(0);

HBITMAP hBuffer = NULL;
RECT	rBuffer;
HDC	hdcBuffer = CreateCompatibleDC(0);

//////////////////////////////////////


bool LoadGraphic(HBITMAP &Bitmap, HDC &hdcBitmap, RECT &rImage, HINSTANCE &hInstance, LPCSTR File) // is called twice, to load the background and then the blocks

{
	Bitmap = 0;

	Bitmap = (HBITMAP) LoadImage(hInstance, File, IMAGE_BITMAP, NULL, NULL, LR_LOADFROMFILE);

	if(Bitmap == 0)
		return false;

	SelectObject(hdcBitmap, Bitmap);

	return true;
	
}

bool Load_Buffer(HBITMAP &Bitmap, HDC &hdcBitmap, RECT &rBitmap)
{
	Bitmap = 0;

	Bitmap = CreateCompatibleBitmap(hdcBitmap, rBitmap.right, rBitmap.bottom);

	if(Bitmap == 0)
		return false;

	SelectObject(hdcBitmap, Bitmap);

	return true;
}

///////////////////// in the precache event before the loop ///////


WindowDC = GetDC(hwnd);


	if(!LoadGraphic(hBackground, hdcBackground, rBackground, hinstance, "Background.bmp"))
	{
		MessageBox(hwnd, "Failed loading background.", "Tetris++", MB_OK);
		PostQuitMessage(0);
	}

	if(!LoadGraphic(hBlocks, hdcBlocks, rBlocks, hinstance, "tiles.bmp"))
	{
		MessageBox(hwnd, "Failed loading blocks.", "Tetris++", MB_OK);
		PostQuitMessage(0);
	}

	rBuffer.left = 0;
	rBuffer.right = 224;
	rBuffer.top = 0;
	rBuffer.bottom = 368;
	
	if(!Load_Buffer(hBuffer, hdcBuffer, rBuffer))
	{
		MessageBox(hwnd, "Failed loading buffer.", "Tetris++", MB_OK);
		PostQuitMessage(0);
	}
  
The vars are global and the images do get loaded, it''s just that I can''t blit the blocks to the buffer, only the background. If any further information is required, just ask and I''ll shall post it up, this has me completely stumped.

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement