Problem:
wglChoosePixelFormatARB supersedes ChoosePixelFormat.
Pixelformats are grouped into four:
1. Accelerated pixel formats that are displayable
2. Accelerated pixel formats that are displayable and which have extended attributes
3. Generic pixel formats
4. Accelerated pixel formats that are non displayable.
ChoosePixelFormat can only return pixelformats from group 1 and group 3, while wglChoosePixelFormatARB
can return from all the groups. Hence, wglChoosePixelFormatARB is needed when you want sRGB framebuffers
and multisampling.
wglChoosePixelFormatARB uses an int array to describe different attributes, while ChoosePixelFormat uses a
PIXELFORMATDESCRIPTOR structure. Since wglChoosePixelFormatARB’s attribute list can describe more
information, it is incompatible with PIXELFORMATDESCRIPTOR.
All this considered, what goes into the PIXELFORMATDESCRIPTOR argument when you call SetPixelFormat
with a pixelformat index from wglChoosePixelFormatARB? Do one set the PIXELFORMATDESCRIPTOR to zero,
or should DescribePixelFormat() be called on the returned pixelformat index?
NOTE: Both schemes seem to “work”, I just want to do the most correct thing, so my application won’t suddenly stop working in the future.
static void CreateGL3Context(HDC& hdc, HGLRC& hglrc)
{
int pixfmt;
unsigned int numpf;
PIXELFORMATDESCRIPTOR pd;
const int piAttribIList[] = {
WGL_DRAW_TO_WINDOW_ARB, TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_SUPPORT_OPENGL_ARB, TRUE,
WGL_DOUBLE_BUFFER_ARB, TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, 24,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0,0
};
const int cca_list[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0,0
};
wglChoosePixelFormatARB(hdc, piAttribIList, NULL, 1, &pixfmt, &numpf);
/* Is this the best solution? */
DescribePixelFormat(hdc, pixfmt, sizeof(PIXELFORMATDESCRIPTOR), &pd);
SetPixelFormat(hdc,pixfmt,&pd); //<-- requires an "old" and inferior descriptor even if we're not using that anymore
hglrc=wglCreateContextAttribsARB(hdc,NULL, cca_list);
wglMakeCurrent(hdc,hglrc);
}