PDA

View Full Version : [W32 OpenGL] second call to SetPixelFormat fails



aiscape
08-26-2003, 12:41 PM
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\r\n",GetLastError());

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

al_bob
08-26-2003, 01:10 PM
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.

aiscape
08-26-2003, 01:41 PM
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.

Mazy
08-26-2003, 11:56 PM
pfd.dwFlags = PFD_DRAW_TO_BITMAP|PFD_SUPPORT_OPENGL|PFD_DRAW_TO_ WINDOW ; ?

should it really contain draw_to_window?

aiscape
08-27-2003, 02:27 AM
hi!
it makes no difference: setpixelformat fails http://www.opengl.org/discussion_boards/ubb/frown.gif
jan

aiscape
08-28-2003, 02:56 AM
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.