Hi, developers!
I researched the source code of the Allegro library. In the master branch there is no code that controls the loading of the OpenGL version using the parameters ALLEGRO_OPENGL_MAJOR_VERSION and ALLEGRO_OPENGL_MINOR_VERSION! If I'm wrong, correct me.
I believe you use them with al_set_new_display_option.
grep harder man.
e:\LIBS\LIBS81Build\allegro5\src>grep -r -E -I -n ALLEGRO_OPENGL_MAJOR_VERSION .*.* .\win/wgl_disp.c:963: ALLEGRO_OPENGL_MAJOR_VERSION, 0); .\x/xglx_config.c:536: ALLEGRO_OPENGL_MAJOR_VERSION, 0);
Strange, "qtcreator" did not find this rows. Maybe this code snippet is not used? But still, in the MinGW-64 environment, my code (https://github.com/bigov/daft-lib/blob/master/OpenGL/allegro.glad/a_win.cpp) does not work as expected:
I see message: "OpenGL Version: 3.0".
If line N18 only is changed so:
that I see: "OpenGL Version: 4.5". I can't setup OpenGL-3.2 context!
I can confirm your problem. I too get the most current version of allegro, even when requesting or requiring otherwise.
It has to do with the _al_get_suggested_display_option function I would think, possibly returning the wrong values, because when I debugged it major was still zero.
Thanks for your reply. I opened a request on https://github.com/liballeg/allegro5/issues/948
I did some more debugging, and there are a couple of problems. First here is my session with gdb :
Thread 1 hit Breakpoint 1, create_display_internals (wgl_disp=0x2d99ba0) at E:\LIBS\LIBS81Build\allegro5\src\win\wgl_disp.c:967 967 if ((disp->flags & ALLEGRO_OPENGL_3_0) || major != 0) { (gdb) set major = 3 (gdb) set minor = 2 (gdb) continue Continuing. Thread 1 hit Breakpoint 2, _al_ogl_manage_extensions (gl_disp=0x2d99ba0) at E:\LIBS\LIBS81Build\allegro5\src\opengl\extensions.c:731 731 if (!_al_ogl_version_3_only(gl_disp->flags)) { (gdb) step _al_ogl_version_3_only (flags=21) at E:\LIBS\LIBS81Build\allegro5\src\opengl\extensions.c:172 172 const int mask = ALLEGRO_OPENGL_3_0 | ALLEGRO_OPENGL_FORWARD_COMPATIBLE; (gdb) n 173 return (flags & mask) == mask; (gdb) 174 } (gdb) _al_ogl_manage_extensions (gl_disp=0x2d99ba0) at E:\LIBS\LIBS81Build\allegro5\src\opengl\extensions.c:731 731 if (!_al_ogl_version_3_only(gl_disp->flags)) { (gdb) n 732 ALLEGRO_DEBUG("OpenGL Extensions:\n"); (gdb) 733 print_extensions((char const *)glGetString(GL_EXTENSIONS)); (gdb) step [New Thread 12072.0x370] Thread 1 hit Breakpoint 3, print_extensions (extension=0x0) at E:\LIBS\LIBS81Build\allegro5\src\opengl\extensions.c:187 187 ASSERT(extension); (gdb)
First, _al_get_suggested_display_option has a bug. Second, glGetString(GL_EXTENSIONS) is returning NULL.
The code for getting display options is here :
The two functions do something slightly different. One uses (int64_t)1 << option) to access extras->suggested and required. The first uses (1 << option). ALLEGRO_OPENGL_MAJOR_VERSION has a value of 33 and ALLEGRO_OPENGL_MINOR_VERSION has a value of 34. Which means 1 << 33 gets bit shifted off of the universe and therefore fails.
I also saw that there was a bug. The truth is not as detailed as you. Great job!
There are more problems.
For one, _al_get_suggested_display_option uses display->extra_settings, and al_get_new_display_option uses tls->new_display_settings, which are completely different.
I changed create_display_internals to use al_get_new_display_option and now it correctly sets a 3.2 OpenGL context, but fails inside the call to glGetString as if the render context was bad.
EDIT
glGetString returns 1280 INVALID_ENUM for getLastError. Don't know what that means. OpenGL 3.2 is being set and made current.
glGetString(GL_EXTENSIONS) is not valid OpenGL 3.
EDIT
How am I supposed to know that? They don't list version numbers on any docs I've seen.
https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetString.xml
https://www.khronos.org/opengl/wiki/GLAPI/glGetString
I also tried to work around with GL get string I and it didn't work either.
EDIT2
glGetStringi doesn't exist. It's a macro for _al_glGetStringi, which is NULL.
This is using modified code to use print_extensions_3_0, which uses allegro's stored gl function pointer, which is null.
I'm assuming this needs to be filled in somehow?
You may be calling it too early, before the display was created.
Not me, this is allegro code that was there long before I got there.
https://github.com/liballeg/allegro5/blob/master/src/opengl/extensions.c#L733
Basically all the OpenGL functions are loaded dynamically (using glx) after the display is created. If there's code calling an OpenGL function before that then that's indeed a bug.
See my link in the edit.
In your link you can see how OpenGL.so is loaded in the lines right afterwards... What if you just move it down a few lines?
The question is how to handle the different versions of opengl.
If the function is an extension, we need to check to see if the extension is supported. In OpenGL versions before 3.0, this was done by calling glGetString(GL_EXTENSIONS). This returned a large string of space-separated extension names. This was abandoned, deprecated in 3.0 and removed in 3.1, because it frequently caused parsing problems for users. Some users also tried to use strcpy to copy the string to a fixed-size buffer, which could easily cause a buffer overrun if the string had too many extensions.
In modern, post GL 3.0 code, the correct way to query which extensions are supported is to use glGetIntegerv(GL_NUM_EXTENSIONS) to get the number of extensions, and then use glGetStringi(GL_EXTENSIONS, i), where i is a number between 0 and the number of extensions - 1. Because glGetStringi is not a GL 1.1 function, you will need to load this function before using it on Windows machines.
Which means we can't always rely on the old buggy code to work. It's amazing it did. I think if we use the new way it will work. I'll try moving it down, but it's part of _al_opengl_manage_extensions().
A few minor revisions and all should be fixed. It's not a far reaching fix though, as there are design problems with _al_get_suggested_display_option that conflict with al_get_new_display_option. That needs to be investigated more thoroughly.
Here's an example program that demonstrates the new patch :
EDIT Removed patch. Not ready yet.
EDIT
It seems I have fixed the problem with glGetString(GL_EXTENSIONS) being used on contexts greater than or equal to 3.
There is another problem though, and that is that the members of the display options are not being filled in with ALLEGRO_OPENGL_MAJOR_VERSION and ALLEGRO_OPENGL_MINOR_VERSION. That should be fixed now too.
My latest pull request is here :
https://github.com/EdgarReynaldo/allegro5/pull/1