mirror of
https://github.com/glfw/glfw.git
synced 2024-11-29 23:54:37 +00:00
Improve OpenGL version parsing from string
This commit is contained in:
parent
28db982d0a
commit
e06515eaa0
14
src/opengl.c
14
src/opengl.c
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.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;
|
GLuint _major, _minor = 0, _rev = 0;
|
||||||
const GLubyte* version;
|
const GLubyte* version;
|
||||||
const GLubyte* ptr;
|
|
||||||
const char* glesPrefix = "OpenGL ES ";
|
|
||||||
|
|
||||||
version = glGetString(GL_VERSION);
|
version = glGetString(GL_VERSION);
|
||||||
if (!version)
|
if (!version)
|
||||||
return;
|
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)
|
if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0)
|
||||||
{
|
{
|
||||||
// The version string on OpenGL ES has a prefix before the version
|
// 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');
|
_rev = 10 * _rev + (*ptr - '0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Find version from OpenGL string
|
||||||
|
for (; version &&
|
||||||
|
!sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev);
|
||||||
|
++version);
|
||||||
|
|
||||||
// Store result
|
// Store result
|
||||||
*major = _major;
|
*major = _major;
|
||||||
|
Loading…
Reference in New Issue
Block a user