Demos (master): Fix GL_VERSION checks.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Tue Jun 7 17:45:53 UTC 2011


Module: Demos
Branch: master
Commit: 7e152554bd922769f1e41c5fe5264f936cc5e149
URL:    http://cgit.freedesktop.org/mesa/demos/commit/?id=7e152554bd922769f1e41c5fe5264f936cc5e149

Author: José Fonseca <jfonseca at vmware.com>
Date:   Tue Jun  7 18:45:22 2011 +0100

Fix GL_VERSION checks.

Several demos were mistakenly dismissing version 3.

Simply use GLEW version check mechanism everywhere.

---

 src/demos/fslight.c       |    6 ++----
 src/demos/spriteblast.c   |    3 +--
 src/glsl/multinoise.c     |    4 +---
 src/glsl/shadow_sampler.c |    6 ++----
 src/glsl/texaaline.c      |    7 ++-----
 src/objviewer/objview.c   |   11 +++++------
 src/perf/glmain.c         |   10 +++-------
 src/tests/drawbuffers.c   |    7 +++----
 src/tests/drawbuffers2.c  |    3 +--
 src/tests/shader_api.c    |    5 +----
 src/trivial/fs-tri.c      |    6 ++----
 11 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/src/demos/fslight.c b/src/demos/fslight.c
index 191a4e4..773108a 100644
--- a/src/demos/fslight.c
+++ b/src/demos/fslight.c
@@ -462,11 +462,9 @@ Init(void)
       "   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
       "   normal = gl_NormalMatrix * gl_Normal;\n"
       "}\n";
-   const char *version;
 
-   version = (const char *) glGetString(GL_VERSION);
-   if (version[0] == '1') {
-      printf("This program requires OpenGL 2.x or higher, found %s\n", version);
+   if (!GLEW_VERSION_2_0) {
+      printf("This program requires OpenGL 2.x or higher\n");
       exit(1);
    }
 
diff --git a/src/demos/spriteblast.c b/src/demos/spriteblast.c
index 20c428c..0361f28 100644
--- a/src/demos/spriteblast.c
+++ b/src/demos/spriteblast.c
@@ -111,10 +111,9 @@ static GLboolean HaveShaders = GL_FALSE;
 static void
 makeFragShader(void)
 {
-   const char *version = (const char *) glGetString(GL_VERSION);
    GLint stat;
 
-   HaveShaders = (version[0] >= '2' && version[1] == '.');
+   HaveShaders = GLEW_VERSION_2_0;
    if (!HaveShaders)
       return;
 
diff --git a/src/glsl/multinoise.c b/src/glsl/multinoise.c
index 410f0ab..b5ed14c 100644
--- a/src/glsl/multinoise.c
+++ b/src/glsl/multinoise.c
@@ -223,11 +223,9 @@ CheckLink(GLuint prog)
 static void
 Init(void)
 {
-   const char *version;
    GLint i;
 
-   version = (const char *) glGetString(GL_VERSION);
-   if (version[0] != '2' || version[1] != '.') {
+   if (!GLEW_VERSION_2_0) {
       printf("Warning: this program expects OpenGL 2.0\n");
       /*exit(1);*/
    }
diff --git a/src/glsl/shadow_sampler.c b/src/glsl/shadow_sampler.c
index 6b9bb67..b830030 100644
--- a/src/glsl/shadow_sampler.c
+++ b/src/glsl/shadow_sampler.c
@@ -260,7 +260,6 @@ Init(void)
       "   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
       "   gl_TexCoord[0] = gl_MultiTexCoord0; \n"
       "}\n";
-   const char *version;
 
 #if USE_RECT
    if (!glutExtensionSupported("GL_ARB_texture_rectangle")) {
@@ -269,9 +268,8 @@ Init(void)
    }
 #endif
 
-   version = (const char *) glGetString(GL_VERSION);
-   if (version[0] * 10 + version[2] <= 20) {
-      printf("This program requires OpenGL 2.x, found %s\n", version);
+   if (!GLEW_VERSION_2_0) {
+      printf("This program requires OpenGL 2.x\n");
       exit(1);
    }
    printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
diff --git a/src/glsl/texaaline.c b/src/glsl/texaaline.c
index e096da6..315800a 100644
--- a/src/glsl/texaaline.c
+++ b/src/glsl/texaaline.c
@@ -321,15 +321,12 @@ MakeMipmap(void)
 static void
 Init(void)
 {
-   const char *version;
-
    (void) MakeTexture;
    (void) ramp4;
    (void) ramp2;
 
-   version = (const char *) glGetString(GL_VERSION);
-   if (version[0] != '2' || version[1] != '.') {
-      printf("This program requires OpenGL 2.x, found %s\n", version);
+   if (!GLEW_VERSION_2_0) {
+      printf("This program requires OpenGL 2.x\n");
       exit(1);
    }
 
diff --git a/src/objviewer/objview.c b/src/objviewer/objview.c
index a323a96..64c4a9f 100644
--- a/src/objviewer/objview.c
+++ b/src/objviewer/objview.c
@@ -435,22 +435,21 @@ Motion(int x, int y)
 static void
 DoFeatureChecks(void)
 {
-   char *version = (char *) glGetString(GL_VERSION);
-   if (version[0] == '1') {
+   if (!GLEW_VERSION_2_0) {
       /* check for individual extensions */
-      if (!glutExtensionSupported("GL_ARB_texture_cube_map")) {
+      if (!GLEW_ARB_texture_cube_map) {
          printf("Sorry, GL_ARB_texture_cube_map is required.\n");
          exit(1);
       }
-      if (!glutExtensionSupported("GL_ARB_vertex_shader")) {
+      if (!GLEW_ARB_vertex_shader) {
          printf("Sorry, GL_ARB_vertex_shader is required.\n");
          exit(1);
       }
-      if (!glutExtensionSupported("GL_ARB_fragment_shader")) {
+      if (!GLEW_ARB_fragment_shader) {
          printf("Sorry, GL_ARB_fragment_shader is required.\n");
          exit(1);
       }
-      if (!glutExtensionSupported("GL_ARB_vertex_buffer_object")) {
+      if (!GLEW_ARB_vertex_buffer_object) {
          printf("Sorry, GL_ARB_vertex_buffer_object is required.\n");
          exit(1);
       }
diff --git a/src/perf/glmain.c b/src/perf/glmain.c
index d252024..81c1173 100644
--- a/src/perf/glmain.c
+++ b/src/perf/glmain.c
@@ -119,13 +119,9 @@ PerfShaderProgram(const char *vertShader, const char *fragShader)
    GLuint prog;
    GLint stat;
 
-   {
-      const char *version = (const char *) glGetString(GL_VERSION);
-      if ((version[0] != '2' && 
-           version[0] != '3') || version[1] != '.') {
-         fprintf(stderr, "Error: GL version 2.x or better required\n");
-         exit(1);
-      }
+   if (!GLEW_VERSION_2_0) {
+      fprintf(stderr, "Error: GL version 2.x or better required\n");
+      exit(1);
    }
 
    prog = glCreateProgram();
diff --git a/src/tests/drawbuffers.c b/src/tests/drawbuffers.c
index 991bf8d..fa2f8a7 100644
--- a/src/tests/drawbuffers.c
+++ b/src/tests/drawbuffers.c
@@ -156,18 +156,17 @@ Key(unsigned char key, int x, int y)
 static void
 CheckExtensions(void)
 {
-   const char *version = (const char *) glGetString(GL_VERSION);
    GLint numBuf;
 
-   if (!glutExtensionSupported("GL_EXT_framebuffer_object")) {
+   if (!GLEW_EXT_framebuffer_object) {
       printf("Sorry, GL_EXT_framebuffer_object is required!\n");
       exit(1);
    }
-   if (!glutExtensionSupported("GL_ARB_draw_buffers")) {
+   if (!GLEW_ARB_draw_buffers) {
       printf("Sorry, GL_ARB_draw_buffers is required!\n");
       exit(1);
    }
-   if (version[0] != '2') {
+   if (!GLEW_VERSION_2_0) {
       printf("Sorry, OpenGL 2.0 is required!\n");
       exit(1);
    }
diff --git a/src/tests/drawbuffers2.c b/src/tests/drawbuffers2.c
index 267b135..5bcf0b2 100644
--- a/src/tests/drawbuffers2.c
+++ b/src/tests/drawbuffers2.c
@@ -204,7 +204,6 @@ CheckExtensions(void)
       "GL_EXT_draw_buffers2"
    };
 
-   const char *version = (const char *) glGetString(GL_VERSION);
    GLint numBuf;
    GLint i;
 
@@ -214,7 +213,7 @@ CheckExtensions(void)
          exit(1);
       }
    }
-   if (version[0] != '2') {
+   if (!GLEW_VERSION_2_0) {
       printf("Sorry, OpenGL 2.0 is required!\n");
       exit(1);
    }
diff --git a/src/tests/shader_api.c b/src/tests/shader_api.c
index e30ee18..fa7741d 100644
--- a/src/tests/shader_api.c
+++ b/src/tests/shader_api.c
@@ -321,14 +321,11 @@ static void run_test(const char *name, void (*callback)(void))
 
 int main(int argc, char **argv)
 {
-   const char *version;
-
    glutInit(&argc, argv);
    glutCreateWindow("Mesa bug demo");
    glewInit();
 
-   version = (const char *) glGetString(GL_VERSION);
-   if (version[0] == '1') {
+   if (!GLEW_VERSION_2_0) {
       printf("Sorry, this test requires OpenGL 2.x GLSL support\n");
       exit(0);
    }
diff --git a/src/trivial/fs-tri.c b/src/trivial/fs-tri.c
index 8d75476..3022b09 100644
--- a/src/trivial/fs-tri.c
+++ b/src/trivial/fs-tri.c
@@ -155,11 +155,9 @@ Init(void)
       "   normal = gl_NormalMatrix * gl_Normal;\n"
       "}\n";
 #endif
-   const char *version;
 
-   version = (const char *) glGetString(GL_VERSION);
-   if (version[0] != '2' || version[1] != '.') {
-      printf("This program requires OpenGL 2.x, found %s\n", version);
+   if (!GLEW_VERSION_2_0) {
+      printf("This program requires OpenGL 2.x\n");
       exit(1);
    }
 




More information about the mesa-commit mailing list