From e06515eaa09f2baf73532cc678c0f51c0039d581 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:35:02 +0300 Subject: [PATCH] Improve OpenGL version parsing from string --- src/opengl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index 67b5e728..957e4d24 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -32,6 +32,7 @@ #include #include +#include //======================================================================== @@ -42,13 +43,16 @@ static void parseGLVersion(int* major, int* minor, int* rev) { GLuint _major, _minor = 0, _rev = 0; const GLubyte* version; - const GLubyte* ptr; - const char* glesPrefix = "OpenGL ES "; version = glGetString(GL_VERSION); if (!version) return; +#if 0 + // Old version detection code. This doesn't work very well + const GLubyte* ptr; + const char* glesPrefix = "OpenGL ES "; + if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0) { // The version string on OpenGL ES has a prefix before the version @@ -76,6 +80,12 @@ static void parseGLVersion(int* major, int* minor, int* rev) _rev = 10 * _rev + (*ptr - '0'); } } +#endif + + // Find version from OpenGL string + for (; version && + !sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev); + ++version); // Store result *major = _major;