Before creating an OpenGL context on Windows, we need to call SetPixelFormat for the Window's device context. Its function prototype is as follows:
BOOL WINAPI SetPixelFormat(
     HDC hdc,
     int iPixelFormat,
     const PIXELFORMATDESCRIPTOR *ppfd);
When creating a fixed function context, we get a supported pixel format index by calling ChoosePixelFormat with our desired pixel format, so the value that really matters is the value passed as the iPixelFormat argument. And when creating a modern GL context, we still need to call SetPixelFormat according to the docs
"Once you have a pixel format number, you can set it just like any pixel format with
SetPixelFormat."
This is even though the PIXELFORMATDESCRIPTOR structure is not really relevant. In this case, I've just been passing NULL. 
Does it matter what I pass as the third parameter to SetPixelFormat? If so, when?
Well yes and no. The PFD struct is mainly used for ChoosePixelFormat, unless you're using wglChoosePixelFormatARB of course. As far as I recall SetPixelFormat relies on iPixelFormat and passing the PFD struct is just a nice "extra" or meta data in other words.
The SetPixelFormat documentation is a bit cryptic but does actually mention this:
Pointer to a
PIXELFORMATDESCRIPTORstructure 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 theSetPixelFormatfunction.
So first you setup a PFD and define what your pixel format requires. Then calling ChoosePixelFormat finds a matching pixel format and returns the index. Calling SetPixelFormat then applies this pixel format using the index to the device context. The PFD in relation to SetPixelFormat is just meta data.
All in all I would recommend passing it anyways, just to be on the safe side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With