PDA

View Full Version : WGL - Anybody Bother Passing PIXELFORMATDESCRIPTOR To SetPixelFormat()?



larryl
05-01-2017, 10:53 PM
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 (http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=2) 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 (http://https://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) 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

GClements
05-01-2017, 11:11 PM
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.

Dark Photon
05-02-2017, 05:28 AM
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 (http://https://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) 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 (https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_pixel_format.txt) 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 (https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_pixel_format.txt) 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 (https://www.khronos.org/opengl/wiki):

* Creating an OpenGL Context (WGL) (https://www.khronos.org/opengl/wiki/Creating_an_OpenGL_Context_(WGL))
* Platform specifics: Windows (https://www.khronos.org/opengl/wiki/Platform_specifics:_Windows)
* Tutorial: OpenGL 3.1 The First Triangle (C++/Win) (https://www.khronos.org/opengl/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_(C++/Win))

larryl
05-03-2017, 03:24 AM
Thanks Guys:

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

Larry

Dark Photon
05-03-2017, 05:15 AM
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/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.