Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: [W32 OpenGL] second call to SetPixelFormat fails

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2003
    Posts
    9

    [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.
    Code :
    // 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!");
    ...

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jun 2003
    Posts
    181

    Re: [W32 OpenGL] second call to SetPixelFormat fails

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2003
    Posts
    9

    Re: [W32 OpenGL] second call to SetPixelFormat fails

    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.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    612

    Re: [W32 OpenGL] second call to SetPixelFormat fails

    pfd.dwFlags = PFD_DRAW_TO_BITMAP|PFD_SUPPORT_OPENGL|PFD_DRAW_TO_ WINDOW ; ?

    should it really contain draw_to_window?

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2003
    Posts
    9

    Re: [W32 OpenGL] second call to SetPixelFormat fails

    hi!
    it makes no difference: setpixelformat fails
    jan

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2003
    Posts
    9

    Re: [W32 OpenGL] second call to SetPixelFormat fails

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •