[W32 OpenGL] second call to SetPixelFormat fails

hello!
i want to copy an opengl scene on a bitmap, but SetPixelFormat fails. it returns 0, getlasterror returns 0 too. rendering on the screen runs fine. m_pDC is the cdc of the cview object.
does anybody know whats wrong?
thanks, jan.

// copy-function
unsigned cx = 200, cy = 200;
CDC *pMemDC = new CDC();
HGLRC hRC;
CBitmap bmp;
CRect rect;
if(!pMemDC->CreateCompatibleDC(m_pDC))
AfxMessageBox(“CreateCompatibleDC failed!”);
GetWindowRect(&rect);
bmp.CreateCompatibleBitmap(pMemDC, cx, cy);
CBitmap *pOldBitmap = pMemDC->SelectObject(&bmp);

// Rendering
wglMakeCurrent(0,0);

PIXELFORMATDESCRIPTOR pfd ;
memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR)) ;
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR) ;
pfd.nVersion = 1 ;
pfd.dwFlags = PFD_DRAW_TO_BITMAP |PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW ;
pfd.iPixelType = PFD_TYPE_RGBA ;
pfd.cColorBits = 32 ;
pfd.cDepthBits = 16 ;
pfd.iLayerType = PFD_MAIN_PLANE ;

int nPixelFormat = ChoosePixelFormat(pMemDC->GetSafeHdc(), &pfd);
if (!nPixelFormat)
AfxMessageBox("ChoosePixelFormat Failed %d
",GetLastError());

nPixelFormat = SetPixelFormat(pMemDC->GetSafeHdc(), nPixelFormat, &pfd);
if(!nPixelFormat)
AfxMessageBox(“SetPixelFormat Failed!”);

Perhaps it’s related to this?

Setting the pixel format of a window more than once can lead to significant complications for the Window Manager and for multithread applications, so it is not allowed. An application can only set the pixel format of a window one time. Once a window’s pixel format is set, it cannot be changed.

hi al_bob!
thank you, but what could be a solution for this problem? the creation of a tmp window? what about the people, that want to display a print preview, do they have the same problems?
jan.

pfd.dwFlags = PFD_DRAW_TO_BITMAP|PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW ; ?

should it really contain draw_to_window?

hi!
it makes no difference: setpixelformat fails
jan

I solved this problem by setting these bits and shifts:


BYTE cRedBits;
BYTE cRedShift;
BYTE cGreenBits;
BYTE cGreenShift;
BYTE cBlueBits;
BYTE cBlueShift;
BYTE cAlphaBits;
BYTE cAlphaShift;

Greets, jan.