What's the point of the third parameter in SetPixelFormat () for creating the OpenGL context?
Before creating an OpenGL context on Windows, we need to call SetPixelFormat
Window for the device context. Its function prototype looks like this:
BOOL WINAPI SetPixelFormat(
HDC hdc,
int iPixelFormat,
const PIXELFORMATDESCRIPTOR *ppfd);
When creating the fixed functional context, we get the index of the supported pixel format by calling ChoosePixelFormat
with our desired pixel format, so the value that actually matters is the value passed as an argument iPixelFormat
. And when creating a modern GL context, we still need to name SetPixelFormat
according to the docs
"Once you have a pixel format number, you can set it just like any pixel format using
SetPixelFormat
."
This is even though the structure is PIXELFORMATDESCRIPTOR
not up to date. In this case, I just got through NULL
.
Doesn't matter what I pass as the third parameter to SetPixelFormat
? If so, when?
source to share
Well yes and no. The PFD structure is mostly used for ChoosePixelFormat
, if you don't wglChoosePixelFormatARB
, of course. As far as I remember, SetPixelFormat
relies on iPixelFormat
, and the PFD structure passing is just "extra" or metadata in other words.
The documentation is a SetPixelFormat
bit cryptic, but it actually mentions this:
Pointer to a structure
PIXELFORMATDESCRIPTOR
that contains the specification of the logical pixel format. The system metafile component uses this structure to write the logical pixel format specification. The structure has no other effect on the behavior of the functionSetPixelFormat
.
So first you set up the PFD and determine what your pixel format requires. The call then ChoosePixelFormat
finds the appropriate pixel format and returns the index. The call SetPixelFormat
then applies this pixel format using the index for the device context. PFD in relation to SetPixelFormat
is just metadata.
All in all, I would recommend passing it over anyway, just to be safe.
source to share