Jump to content

How to convert my code for double buffering?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Overv

Overv

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

I want to start game programming soon and I'm now starting with the rendering part. I'll begin with using GDI and I may later port the whole thing to DirectDraw/Direct3D, but now I want it to work with double duffering :D

My rendering function currently looks like this:

int render(HWND hwnd)

{

	//Variables

	BITMAP bmAvatar;

	PAINTSTRUCT psInfo;

	

	//Prepare painting

	HDC hdc = BeginPaint(hwnd, &psInfo);

	HDC hdcMem = CreateCompatibleDC(hdc);


	//Load picture

	HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_Avatar);

	GetObject(g_Avatar, sizeof(bmAvatar), &bmAvatar);


	//Draw stuff

	BitBlt(hdc, mx, my, bmAvatar.bmWidth, bmAvatar.bmHeight, hdcMem, 0, 0, SRCCOPY);


	//Destroy it all again

	SelectObject(hdcMem, hbmOld);

	DeleteDC(hdcMem);


	//Stop painting

	EndPaint(hwnd, &psInfo);

	

	return 1;

}

So, how do I add double buffering to this? If you need more information, just say so :)

#2
Steve.L

Steve.L

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 444 posts
I don't think too many people here work with graphic design and rendering here... You'll probably have to do your own research on this one.

I'm probably not supposed to do this, but you will probably find more information on this topic here:
CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions

#3
Overv

Overv

    Newbie

  • Members
  • Pip
  • 2 posts
Heh, I already also made a topic there, because this forum seemed a little "off". Anyway, I fixed the problem by first rendering everything to a bitmap in memory and then copy the whole thing to the screen and also disabling background drawing which was the main reason for flickering.

Thanks anyway :)