From 4e7907e6ddb151b315161240534fbaaa1052eb81 Mon Sep 17 00:00:00 2001 From: xndcn Date: Thu, 15 Oct 2020 11:39:08 +0800 Subject: [PATCH] Backends: OpenGL3: Add compatibility of GL_VERSION for GL 2.x 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 --- backends/imgui_impl_opengl3.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index ed1513045764..54294691cf35 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -147,9 +147,16 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { // Query for GL version (e.g. 320 for GL 3.2) #if !defined(IMGUI_IMPL_OPENGL_ES2) - GLint major, minor; + GLint major = 0, minor = 0; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); + if (major == 0 && minor == 0) + { + // Query GL_VERSION in desktop GL 2.x, the string will start with "." + const GLubyte* version = glGetString(GL_VERSION); + major = version[0] - '0'; + minor = version[2] - '0'; + } g_GlVersion = (GLuint)(major * 100 + minor * 10); #else g_GlVersion = 200; // GLES 2