progs/glsl: Prevent possible string overflow.
[mesa.git] / progs / glsl / texdemo1.c
index 96ddca1f32d2a6a5eb02b6e58b5cf3f5bea3655f..2076e6aef94508ea214f16cc5406a5b0dccf7ea1 100644 (file)
@@ -28,9 +28,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <GL/glew.h>
 #include "GL/glut.h"
 #include "readtex.h"
-#include "extfuncs.h"
 #include "shaderutil.h"
 
 static const char *Demo = "texdemo1";
@@ -53,14 +53,14 @@ static int win = 0;
 
 
 static struct uniform_info ReflectUniforms[] = {
-   { "cubeTex",  1, GL_INT, { 0, 0, 0, 0 }, -1 },
-   { "lightPos", 3, GL_FLOAT, { 10, 10, 20, 0 }, -1 },
+   { "cubeTex",  1, GL_SAMPLER_CUBE, { 0, 0, 0, 0 }, -1 },
+   { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 },
    END_OF_UNIFORMS
 };
 
 static struct uniform_info SimpleUniforms[] = {
-   { "tex2d",    1, GL_INT,   { 1, 0, 0, 0 }, -1 },
-   { "lightPos", 3, GL_FLOAT, { 10, 10, 20, 0 }, -1 },
+   { "tex2d",    1, GL_SAMPLER_2D, { 1, 0, 0, 0 }, -1 },
+   { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 },
    END_OF_UNIFORMS
 };
 
@@ -97,7 +97,7 @@ draw(void)
       /* sphere w/ reflection map */
       glPushMatrix();
          glTranslatef(0, 1, 0);
-         glUseProgram_func(Program1);
+         glUseProgram(Program1);
 
          /* setup texture matrix */
          glActiveTexture(GL_TEXTURE0);
@@ -116,7 +116,7 @@ draw(void)
       glPopMatrix();
 
       /* ground */
-      glUseProgram_func(Program2);
+      glUseProgram(Program2);
       glTranslatef(0, -1.0, 0);
       DrawGround(5);
 
@@ -380,9 +380,10 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile,
    fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, fragProgFile);
    program = LinkShaders(vertShader, fragShader);
 
-   glUseProgram_func(program);
+   glUseProgram(program);
 
-   InitUniforms(program, uniforms);
+   SetUniformValues(program, uniforms);
+   PrintUniforms(uniforms);
 
    return program;
 }
@@ -399,16 +400,11 @@ InitPrograms(void)
 static void
 Init(GLboolean useImageFiles)
 {
-   const char *version = (const char *) glGetString(GL_VERSION);
-
-   if (version[0] != '2' || version[1] != '.') {
-      printf("Warning: this program expects OpenGL 2.0\n");
-      /*exit(1);*/
+   if (!ShadersSupported()) {
+      exit(1);
    }
    printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
 
-   GetExtensionFuncs();
-
    InitTextures(useImageFiles);
    InitPrograms();
 
@@ -426,6 +422,7 @@ main(int argc, char *argv[])
    glutInitWindowSize(500, 400);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    win = glutCreateWindow(Demo);
+   glewInit();
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(key);
    glutSpecialFunc(specialkey);