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 5 of 5

Thread: WGL - Anybody Bother Passing PIXELFORMATDESCRIPTOR To SetPixelFormat()?

  1. #1
    Intern Contributor
    Join Date
    Jan 2017
    Posts
    54

    WGL - Anybody Bother Passing PIXELFORMATDESCRIPTOR To SetPixelFormat()?

    Hi Folks:

    Thanks to posters in this forum, I've been happily rendering my first model in an application's splash screen for several weeks.

    I lifted the code to setup WGL from this tutorial.

    Tonight I had occasion to look at the OpenGL setup code and noticed that I had initialized the PIXELFORMATDESCRIPTOR value for pre OpenGL 3 code, but not for the code run for newer OpenGL.

    The code runs fine. It runs fine now that I'm passing NULL for the argument.

    SetPixelFormat()'s documentation here says this about the PIXELFORMATDESCRIPTOR argument:

    Pointer to a PIXELFORMATDESCRIPTOR structure that contains the logical pixel format specification. The system's metafile component uses this structure to record the logical pixel format specification. The structure has no other effect upon the behavior of the SetPixelFormat function.
    I don't know enough about Windows or OpenGL to know the meaning of that statement. It does sound dismissive.

    Does anybody do anything with this SetPixelFormat() argument for current OpenGL?

    Thanks
    Larry
    Last edited by larryl; 05-02-2017 at 01:12 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,599
    Both FreeGLUT and GLFW pass the information to SetPixelFormat(). FreeGLUT just passes the same pointer it passed to ChoosePixelFormat(), while GLFW uses DescribePixelFormat() to populate the structure.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,227
    Quote Originally Posted by larryl View Post
    Tonight I had occasion to look at the OpenGL setup code and noticed that I had initialized the PIXELFORMATDESCRIPTOR value for pre OpenGL 3 code, but not for the code run for newer OpenGL.

    The code runs fine. It runs fine now that I'm passing NULL for the argument.

    SetPixelFormat()'s documentation here says this about the PIXELFORMATDESCRIPTOR argument ... Does anybody do anything with this SetPixelFormat() argument for current OpenGL?
    Yes. Here on Win7, I'm providing a non-NULL (initialized structure pointer) argument to this parameter populated with the same pointer value just passed to ChoosePixelFormat()/DescribePixelFormat() and it's working fine.

    That said, the pixel format that's actually used for app rendering is one queried via wglChoosePixelFormatARB(), not ChoosePixelFormat()/DescribePixelFormat().

    More detail (in case that made no sense) : In OpenGL code written in the last 10-15 years targeting Windows (which uses WGL as the window system interface), what you're likely to see is WGL_ARB_pixel_format used as an override for the under-capable Windows built-in ChoosePixelFormat() / DescribePixelFormat() calls. That is, something like:

    1) Determine the pixel format with ChoosePixelFormat() / DescribePixelFormat()
    2) If WGL_ARB_pixel_format is supported...
    a) Create a dummy GL context and bind it
    b) Query function pointers for wglGetPixelFormat*ARB() / wglChoosePixelFormatARB()
    c) Determine the pixel format we really want with wglGetPixelFormat*ARB() / wglChoosePixelFormatARB().
    d) Delete the dummy context
    3) Now create the GL context our app will use, using the selected pixel format.

    In other words, #1 is just dummy work needed to create the dummy GL context to query to the function pointers that you want to use to query/set the pixel format your app "really" wants to render in.

    For more on this, see these pages in the OpenGL Wiki:

    * Creating an OpenGL Context (WGL)
    * Platform specifics: Windows
    * Tutorial: OpenGL 3.1 The First Triangle (C++/Win)
    Last edited by Dark Photon; 05-02-2017 at 06:50 AM.

  4. #4
    Intern Contributor
    Join Date
    Jan 2017
    Posts
    54
    Thanks Guys:

    I'll go ahead and put valid stuff in the record.

    Larry

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,227
    Quote Originally Posted by larryl View Post
    Thanks Guys:

    I'll go ahead and put valid stuff in the record.
    I wouldn't sweat the contents much. In the case where the pixel format index comes from wglGetPixelFormat*ARB() / wglChoosePixelFormatARB(), there really is no appropriate PIXELFORMATDESCRIPTOR. So it makes sense that it'd be ignored. This section in the OpenGL wiki supports that:

    * https://www.khronos.org/opengl/wiki/...)#Pixel_Format
    Quote Originally Posted by Creating_an_OpenGL_Context_(WGL)#Pixel_Format
    Once you have the pixel format number, you can set it into the DC with SetPixelFormat. This function takes the DC, the pixel format number, and a PFD struct pointer. Don't get excited about being able to supply the PFD struct; it doesn't read any important information out of it to set the pixel format into the context.

Posting Permissions

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