Results 1 to 5 of 5

Thread: SetPixelFormat() fails

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    Vilnius, LT, Lithuania
    Posts
    6

    SetPixelFormat() fails

    Hello, I met with strange situation because it worked fain before.
    When it tries to set pixel format by using the SetPixelFormat() my MFC dialog stops responding and I neet to restart my PC for properly working of other applications.
    Please a look at the code:


    int OpenGLWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if(CWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here
    m_hDC = ::GetDC(m_hWnd);

    if (SetPixelFormat(m_hDC)==FALSE)
    return -1;

    if (CreateGLContext(m_hDC)==FALSE)
    return -1;

    }


    BOOL OpenGLWnd::SetPixelFormat(HDC hdc)
    {


    PIXELFORMATDESCRIPTOR pfd = {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW |
    PFD_SUPPORT_OPENGL |
    PFD_DOUBLEBUFFER |
    PFD_TYPE_RGBA,
    24,
    0, 0, 0, 0, 0, 0,
    0,
    0,
    0,
    0, 0, 0, 0,
    32,
    0,
    0,
    PFD_MAIN_PLANE,
    0,//2,
    0,
    0,
    0
    };



    int pixelFormat;


    if((pixelFormat = ::ChoosePixelFormat(hdc, &pfd)) == 0)
    {
    pixelFormat = 1;
    if(DescribePixelFormat(m_hDC, pixelFormat, // Obtains information about the pixel format identified by iPixelFormat of the device associated with hdc
    sizeof(PIXELFORMATDESCRIPTOR), &pfd)==0)
    return FALSE;

    }

    if (::SetPixelFormat(hdc, pixelFormat, &pfd) == FALSE)
    {
    return FALSE;
    }

    return TRUE;
    }

    BOOL OpenGLWnd::CreateGLContext(HDC hdc)
    {

    if((m_hrc = ::wglCreateContext(hdc)) == NULL)
    return FALSE;

    if(::wglMakeCurrent(hdc, m_hrc) == FALSE)
    return FALSE;

    return TRUE;
    }

    the OpenGLWnd class has been derived from CWnd.
    I use Windows NT 4.0 SP6. However this problem appears on other OS as well.
    Thank you in advance,
    Romanas Puisa
    Romanas Puisa

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: SetPixelFormat() fails

    Hi !

    It would be much more helpful if you could say where it stops, use the debugger to singlestep through the code and look where it stops working.

    Mikael

  3. #3
    Member Newbie
    Join Date
    Apr 2002
    Location
    Split, Croatia
    Posts
    43

    Re: SetPixelFormat() fails

    It seems that your PIXELFORMATDESCRIPTOR is
    not set right.
    After PFD_DOUBLEBUFFER should be coma,
    PFD_TYPE_RGBA is value for iPixelType member of structure.
    Aslo make sure that your card supports 32 bit
    Z-buffer.
    Hope this helps,
    mproso

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    Vilnius, LT, Lithuania
    Posts
    6

    Re: SetPixelFormat() fails

    I think you are not right regarding to the comma placing. If you closely take a look at it once more you'll see it set right. It seems you had been confused by OR operators.
    If I mistake please point out where.
    Thank you for spearing time at this problem.
    Romanas Puisa

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    Vilnius, LT, Lithuania
    Posts
    6

    Re: SetPixelFormat() fails

    Sorry you was right. I made mistake regarding the coma placing. I had used the PFD_TYPE_RGBA in incorrect position.
    I think it will help to solve the problem.
    Romanas Puisa

Similar Threads

  1. [W32 OpenGL] second call to SetPixelFormat fails
    By aiscape in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-28-2003, 03:56 AM
  2. SetPixelFormat Fails
    By gunsboy in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-19-2002, 10:07 AM
  3. 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
  4. SetPixelFormat()
    By skippyj777 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-13-2000, 04:31 PM
  5. SetPixelFormat
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-11-2000, 03:55 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