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
    Senior Member Regular Contributor
    Join Date
    Jun 2003
    Posts
    177

    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
    Senior Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    595

    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.

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2010, 11:47 PM
  2. Replies: 2
    Last Post: 04-19-2005, 08:47 AM
  3. SetPixelFormat Fails
    By gunsboy in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-19-2002, 10:07 AM
  4. SetPixelFormat() fails
    By Condor in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-28-2002, 11:34 PM
  5. SetPixelFormat fails the second time it's called
    By CGameProgrammer in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 02-16-2001, 12:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean