1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Improve OpenGL version parsing from string

This commit is contained in:
Cloudef 2012-04-25 09:35:02 +03:00 committed by Jari Vetoniemi
parent 28db982d0a
commit e06515eaa0

View File

@ -32,6 +32,7 @@
#include <string.h>
#include <limits.h>
#include <stdio.h>
//========================================================================
@ -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;