Trying to use PFD_DRAW_TO_BITMAP for my window

Started by
1 comment, last by aewarnick 19 years ago
I want to test out how slow drawing to a bitmap and blitting will be using PFD_DRAW_TO_BITMAP instead of PFD_DOUBLEBUFFER but I'm having trouble when the window needs resized. When I try to resize I always get an unknown exception. It has something to do with copying the context because when I don't do It everything works fine UNTIL I resize. Here is some code:
//Everything in here is fine.
HGLRC SetUpOpenGL(HDC hdc, bool doubleBuffed, byte depthBits= 0)
		{
			DoubleBuffed= doubleBuffed;
			PIXELFORMATDESCRIPTOR pfd;
			memset( & pfd, 0, sizeof(pfd));
			pfd.nSize= sizeof(pfd);
			pfd.nVersion= 1;
			pfd.dwFlags= PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI;
			pfd.iPixelType= PFD_TYPE_RGBA;
			pfd.cDepthBits= depthBits;
			pfd.cColorBits= 24;
			int pf= ChoosePixelFormat(hdc, & pfd);
			if(!pf) MessageBox(0, "ChoosePixelFormat", "Error", 0);
			if(!SetPixelFormat(hdc, pf, & pfd))
				MessageBox(0, "SetPixelFormat", "Error", 0);
			HGLRC hgl= wglCreateContext(hdc);
			wglMakeCurrent(hdc, hgl);
}

//In WM_SIZE.  Both wglCopyContext pass.
HGLRC cur= wglGetCurrentContext();
if(hGL!=cur)
    wglMakeCurrent(memDC->hDC, hGL);
if(!wglCopyContext(hGL, App::glDummyHgl, GL_ALL_ATTRIB_BITS)) MB("no copy");
DisableOpenGL(); //makes no context current and deletes hGL
CreateBackBuffer(); //creates the bitmap for back buffing rendering
hGL= SetUpOpenGL(memDC->hDC, 1); //memDC selected the bitmap above into a dc
wglMakeCurrent(App::glDummyDC.hDC, App::glDummyHgl);
if(!wglCopyContext(App::glDummyHgl, hGL, GL_ALL_ATTRIB_BITS)) MB("no second");
wglMakeCurrent(memDC->hDC, hGL);



The reason I'm using wglCopyContext is because my textures are deleted along with the context. Is there something I should know about wglCopyContext or did I do something else wrong? [Edited by - aewarnick on April 9, 2005 5:49:52 PM]
*C++*->
Advertisement
You neednt delete your gl context every time you resize. All that you are required to do is to resize your memDC using windows commands. Now what you need to do is this:

call CreateCompatibleBitmap specifying your memDC and the new size.
call SelectObject selecting the new bitmap.
call DeleteObject on the old bitmap object.

That should solve it

A side note: It is faster to use PFD_DRAW_TO_WINDOW with double buffering.
Fixed it.

I know it's faster to avoid all gdi calls but I wanted to test this out.

Now a question about why it is so slow. It does not seem to be hardware accelerated at all! Am I right?
*C++*->

This topic is closed to new replies.

Advertisement