From b0c181666412f45c199548b1e96a786e69aa76d5 Mon Sep 17 00:00:00 2001 From: Laurens Holst Date: Thu, 9 Feb 2023 21:56:04 +0100 Subject: [PATCH] Backends: OpenGL3: Fixed loader compatibility with GL_VERSION for GL 2.x (#6154, #4445, #3530) GL_MAJOR_VERSION and GL_MINOR_VERSION are available on GL 3.0 and above. So we have to parse GL_VERSION under GL 2.x Reference https://www.khronos.org/opengl/wiki/OpenGL_Context#Context_information_queries Regressed since 459de65477423360176447e79df2f3a785b71f3d See https://github.com/ocornut/imgui/pull/3530 --- backends/imgui_impl_opengl3_loader.h | 10 ++++++++-- docs/CHANGELOG.txt | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backends/imgui_impl_opengl3_loader.h b/backends/imgui_impl_opengl3_loader.h index 5b6615e9495a..2ebb2cf05f49 100644 --- a/backends/imgui_impl_opengl3_loader.h +++ b/backends/imgui_impl_opengl3_loader.h @@ -685,7 +685,13 @@ static int parse_version(void) return GL3W_ERROR_INIT; glGetIntegerv(GL_MAJOR_VERSION, &version.major); glGetIntegerv(GL_MINOR_VERSION, &version.minor); - if (version.major < 3) + if (version.major == 0 && version.minor == 0) + { + // Query GL_VERSION in desktop GL 2.x, the string will start with "." + const char* gl_version = (const char*)glGetString(GL_VERSION); + sscanf(gl_version, "%d.%d", &version.major, &version.minor); + } + if (version.major < 2) return GL3W_ERROR_OPENGL_VERSION; return GL3W_OK; } @@ -709,7 +715,7 @@ int imgl3wInit2(GL3WGetProcAddressProc proc) int imgl3wIsSupported(int major, int minor) { - if (major < 3) + if (major < 2) return 0; if (version.major == major) return version.minor >= minor; diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bb0bf5768224..fb9df81e2104 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -116,7 +116,8 @@ All changes: - Backends: GLFW: Added ImGui_ImplGlfw_SetCallbacksChainForAllWindows() to instruct backend to chain callbacks even for secondary viewports/windows. User callbacks may need to test the 'window' parameter. (#6142) -- Backends: WebGPU: Fix building for latest WebGPU specs (remove implicit layout generation). +- Backends: OpenGL3: Fixed GL loader compatibility with 2.x profiles. (#6154, #4445, #3530) [@grauw] +- Backends: WebGPU: Fixed building for latest WebGPU specs (remove implicit layout generation). (#6117, #4116, #3632) [@tonygrue, @bfierz] - Examples: refactored SDL2+GL and GLFW+GL examples to compile with Emscripten. (#2492, #2494, #3699, #3705) [@ocornut, @nicolasnoble]