Thanks Dark Photon:
I’m not there yet.
I’ve downloaded both GLFW and GLEW, and built both from source.
Windows search facility can’t find “GetPixelFormatAttrib” or “ChoosePixelFormat” when searching either folder these were built in.
I don’t mind re-inventing the wheel, that can be educational and stimulate a lot of questions.
Like these:
I’m now defining my pixel format attribute array like this:
const int experimntal_attributes[] =
{
WGL_DRAW_TO_WINDOW_ARB, 1,
WGL_SUPPORT_OPENGL_ARB, 1,
WGL_DOUBLE_BUFFER_ARB, 1,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, find_attribute_value(hdc, WGL_COLOR_BITS_ARB, 64, 8),
WGL_ALPHA_BITS_ARB, find_attribute_value(hdc, WGL_ALPHA_BITS_ARB, 64, 8),
// WGL_DEPTH_BITS_ARB, 24,
WGL_DEPTH_BITS_ARB, find_attribute_value(hdc, WGL_DEPTH_BITS_ARB, 64, 8),
WGL_STENCIL_BITS_ARB, find_attribute_value(hdc, WGL_STENCIL_BITS_ARB, 64, 8),
WGL_SAMPLE_BUFFERS_ARB, find_attribute_value(hdc, WGL_SAMPLE_BUFFERS_ARB, 1, 1),
WGL_SAMPLES_ARB, find_attribute_value(hdc, WGL_SAMPLES_ARB, 64, 8),
0
};
My goal is to find the pixel format attributes the installed card can use, so for testing I started looking at 64 bits and dropped values until wglChoosePixelFormatARB() was satisfied with the value for the attribute. I’ll start with realistic values for production code.
Here’s find_attribute_value():
int find_attribute_value(HDC hdc, int attribute_id, int initial_attribute_value,
int step_down_value)
{
bool pixel_format_is_valid = false;
int return_val = 0;
int attribute_value = initial_attribute_value;
int number_of_formats_found = 0;
int pixel_format[] = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
};
BOOL choose_format_result = false;
#ifdef _DEBUG
std::string attribute_name;
pixel_format_attribute_ARB_id_to_text(attribute_id, &attribute_name);
#endif
int pixel_format_attrib_list[] = { attribute_id, attribute_value, 0 };
if (step_down_value > 0)
{
choose_format_result = wglChoosePixelFormatARB(hdc,
pixel_format_attrib_list,
// iPixelFormatAttribList, // Integer attribute pairs
NULL, // Floating attribute pairs
10, // Max num of formats that can be stored next argument.
pixel_format, // List of acceptable formats go here.
(UINT*)&number_of_formats_found); // Number of formats saved in list.
if (choose_format_result && (number_of_formats_found > 0))
{
pixel_format_is_valid = true;
}
while (!pixel_format_is_valid & (attribute_value > 0))
{
attribute_value -= step_down_value;
// Create a loop scoped format attribute list.
int pixel_format_attrib_list[] = { attribute_id, attribute_value, 0 };
choose_format_result = wglChoosePixelFormatARB(hdc,
pixel_format_attrib_list, // Integer attribute pairs
NULL, // Floating attribute pairs
10, // Max num of formats that can be stored next argument.
pixel_format, // List of acceptable formats go here.
(UINT*)&number_of_formats_found); // Number of formats saved in list.
if (choose_format_result && (number_of_formats_found > 0))
{
pixel_format_is_valid = true;
}
}
return_val = attribute_value;
}
return return_val;
}
Any suggestions for this code are, of course, appreciated.
The function works when I hard code the WGL_DEPTH_BITS_ARB to 24. Notice that’s been commented out. We’ll get back to that later.
I’m using this page as a reference, although this page says these are not really user references:
OpenGL application programmers should not expect an extension’s specification to fully justify why the functionality exists or how an OpenGL application would go about using the functionality.
But it’s all I can find, so it’s all I can use.
Here are some questions about wglChoosePixelFormatARB():
BOOL wglChoosePixelFormatARB(HDC hdc,
const int *piAttribIList,
const FLOAT *pfAttribFList,
UINT nMaxFormats,
int *piFormats,
UINT *nNumFormats);
What’s with all the different formats that are returned for one attribute?
When a valid number for WGL_COLOR_BITS_ARB was found the piFormats array had 10 items in it, from 1 to 10, with 0 for the 11th element. When I set nMaxFormats to 40 and made piFormats 41 elements long the array had elements from 1 to 40.
When the WGL_ALPHA_BITS_ARB value settled on 8 the array of formats was 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0.
WGL_DEPTH_BITS_ARB settled on 32, the array was 200, 202, 204, 206, 208, 210, 0, 0, 0, 0, 0. nNumFormats is 6.
WGL_STENCIL_BITS_ARB came out as 8 with an array of 3, 4, 9, 10, 15, 16, 21, 22, 27, 28, 0.
WGL_SAMPLES_ARB was 16, the array was 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 0.
What are the numbers in the piFormats array telling me? Anything I should be doing with them?
The way I’m using it, the WGL_DEPTH_BITS_ARB returns 32 but the when the full pixel format attribute array is passed to it wglChoosePixelFormatARB() says no format’s were found. The OpenGL setup works when I pass a depth of 24.
Do I need to find a format number that each of these attribute - value pairs have in common, then use the corresponding value for each attribute and use those for a final call to wglChoosePixelFormatARB()?
I assume I’m the only person who has ever been confused by what I’m seeing.
I’ll have a lot more questions after I understand what’s going on here.
I’d appreciate an explanation. Please type slowly and use small words.
Thanks
Larry