Skip to content

Commit

Permalink
Backends: OpenGL3: Add compatibility of GL_VERSION for GL 2.x
Browse files Browse the repository at this point in the history
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
See ocornut/imgui#3530
  • Loading branch information
grauw committed Feb 9, 2023
1 parent f223e08 commit 5eb20f8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions template/gl3w.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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 "<major>.<minor>"
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;
}
Expand All @@ -232,7 +238,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;
Expand Down

0 comments on commit 5eb20f8

Please sign in to comment.