I want draw a graphic in the memory, needn’t to display.I use CreateCompatibleDC() to create a hDC, but while I use SetPixelFormat() to set the pixelformat for the hDC, the function fails. what is the problem? Can anyone help me?
My codes are follow:
void CGLTest::Init()
{
PIXELFORMATDESCRIPTOR pfd;
int n;
HGLRC hrc;
//SourceDC is a global variable, type is CDC
//tempHDC is a global variable, type is HDC
SourceDC.CreateCompatibleDC(NULL);
tempHDC=SourceDC.GetSafeHdc();
if(!bSetupPixelFormat())
return;
n=::GetPixelFormat(tempHDC);
: [img]http://www.opengl.org/discussion_boards/ubb/biggrin.gif[/img]escribePixelFormat(tempHDC, n, sizeof(pfd), &pfd);
hrc=wglCreateContext(tempHDC);
wglMakeCurrent(tempHDC,hrc);
}
BOOL CGLTest::bSetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_DRAW_TO_BITMAP|PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
int pixelformat;
if((pixelformat=ChoosePixelFormat(tempHDC,&pfd))==0)
{
MessageBox("ChoosePixelFormat falled");
return FALSE;
}
if(SetPixelFormat(tempHDC,pixelformat,&pfd)==FALSE)
{
MessageBox("SetPixelFormat falled");
return FALSE;
}
return TRUE;
}