summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/glsl/brick.shtest10
-rw-r--r--progs/glsl/mandelbrot.shtest23
-rw-r--r--progs/glsl/shtest.c99
-rw-r--r--progs/glsl/toyball.shtest30
4 files changed, 108 insertions, 54 deletions
diff --git a/progs/glsl/brick.shtest b/progs/glsl/brick.shtest
index c806a0fc54..8a2152692e 100644
--- a/progs/glsl/brick.shtest
+++ b/progs/glsl/brick.shtest
@@ -1,8 +1,8 @@
vs CH06-brick.vert
fs CH06-brick.frag
-uniform LightPosition 0.1 0.1 9.0
-uniform BrickColor 0.8 0.2 0.2
-uniform MortarColor 0.6 0.6 0.6
-uniform BrickSize 1.0 0.3
-uniform BrickPct 0.9 0.8
+uniform LightPosition GL_FLOAT_VEC3 0.1 0.1 9.0
+uniform BrickColor GL_FLOAT_VEC3 0.8 0.2 0.2
+uniform MortarColor GL_FLOAT_VEC3 0.6 0.6 0.6
+uniform BrickSize GL_FLOAT_VEC2 1.0 0.3
+uniform BrickPct GL_FLOAT_VEC2 0.9 0.8
diff --git a/progs/glsl/mandelbrot.shtest b/progs/glsl/mandelbrot.shtest
index f5cca2295f..4f4e5c747e 100644
--- a/progs/glsl/mandelbrot.shtest
+++ b/progs/glsl/mandelbrot.shtest
@@ -1,14 +1,13 @@
vs CH18-mandel.vert
fs CH18-mandel.frag
-uniform LightPosition 0.1 0.1 9.0
-uniform SpecularContribution 0.5
-uniform DiffuseContribution 0.5
-uniform Shininess 20.0
-uniform Iterations 12
-uniform Zoom 0.125
-uniform Xcenter -1.5
-uniform Ycenter .005
-uniform InnerColor 1 0 0
-uniform OuterColor1 0 1 0
-uniform OuterColor2 0 0 1
-
+uniform LightPosition GL_FLOAT_VEC3 0.1 0.1 9.0
+uniform SpecularContribution GL_FLOAT 0.5
+uniform DiffuseContribution GL_FLOAT 0.5
+uniform Shininess GL_FLOAT 20.0
+uniform Iterations GL_FLOAT 12
+uniform Zoom GL_FLOAT 0.125
+uniform Xcenter GL_FLOAT -1.5
+uniform Ycenter GL_FLOAT .005
+uniform InnerColor GL_FLOAT_VEC3 1 0 0
+uniform OuterColor1 GL_FLOAT_VEC3 0 1 0
+uniform OuterColor2 GL_FLOAT_VEC3 0 0 1
diff --git a/progs/glsl/shtest.c b/progs/glsl/shtest.c
index 7eb7202274..09b2593841 100644
--- a/progs/glsl/shtest.c
+++ b/progs/glsl/shtest.c
@@ -35,6 +35,7 @@
#include <GL/glu.h>
#include <GL/glut.h>
#include "shaderutil.h"
+#include "readtex.h"
typedef enum
@@ -361,6 +362,69 @@ InitUniforms(const struct config_file *conf,
}
+static void
+LoadTexture(GLint unit, const char *texFileName)
+{
+ GLint imgWidth, imgHeight;
+ GLenum imgFormat;
+ GLubyte *image = NULL;
+ GLuint tex;
+ GLenum filter = GL_LINEAR;
+
+ image = LoadRGBImage(texFileName, &imgWidth, &imgHeight, &imgFormat);
+ if (!image) {
+ printf("Couldn't read %s\n", texFileName);
+ exit(1);
+ }
+
+ printf("Load Texture: unit %d: %s %d x %d\n",
+ unit, texFileName, imgWidth, imgHeight);
+
+ glActiveTexture(GL_TEXTURE0 + unit);
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ gluBuild2DMipmaps(GL_TEXTURE_2D, 4, imgWidth, imgHeight,
+ imgFormat, GL_UNSIGNED_BYTE, image);
+ free(image);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+}
+
+
+static GLenum
+TypeFromName(const char *n)
+{
+ static const struct {
+ const char *name;
+ GLenum type;
+ } types[] = {
+ { "GL_FLOAT", GL_FLOAT },
+ { "GL_FLOAT_VEC2", GL_FLOAT_VEC2 },
+ { "GL_FLOAT_VEC3", GL_FLOAT_VEC3 },
+ { "GL_FLOAT_VEC4", GL_FLOAT_VEC4 },
+ { "GL_INT", GL_INT },
+ { "GL_INT_VEC2", GL_INT_VEC2 },
+ { "GL_INT_VEC3", GL_INT_VEC3 },
+ { "GL_INT_VEC4", GL_INT_VEC4 },
+ { "GL_SAMPLER_2D", GL_SAMPLER_2D },
+ { NULL, 0 }
+ };
+ GLuint i;
+
+ for (i = 0; types[i].name; i++) {
+ if (strcmp(types[i].name, n) == 0)
+ return types[i].type;
+ }
+ abort();
+ return GL_NONE;
+}
+
+
+
/**
* Read a config file.
*/
@@ -381,7 +445,7 @@ ReadConfigFile(const char *filename, struct config_file *conf)
/* ugly but functional parser */
while (!feof(f)) {
fgets(line, sizeof(line), f);
- if (line[0]) {
+ if (!feof(f) && line[0]) {
if (strncmp(line, "vs ", 3) == 0) {
VertShaderFile = strdup(line + 3);
VertShaderFile[strlen(VertShaderFile) - 1] = 0;
@@ -390,32 +454,23 @@ ReadConfigFile(const char *filename, struct config_file *conf)
FragShaderFile = strdup(line + 3);
FragShaderFile[strlen(FragShaderFile) - 1] = 0;
}
+ else if (strncmp(line, "texture ", 8) == 0) {
+ char texFileName[100];
+ int unit, k;
+ k = sscanf(line + 8, "%d %s", &unit, texFileName);
+ assert(k == 2);
+ LoadTexture(unit, texFileName);
+ }
else if (strncmp(line, "uniform ", 8) == 0) {
- char name[1000];
+ char name[1000], typeName[100];
int k;
- float v1, v2, v3, v4;
+ float v1 = 0.0F, v2 = 0.0F, v3 = 0.0F, v4 = 0.0F;
GLenum type;
- k = sscanf(line + 8, "%s %f %f %f %f", name, &v1, &v2, &v3, &v4);
+ k = sscanf(line + 8, "%s %s %f %f %f %f", name, typeName,
+ &v1, &v2, &v3, &v4);
- switch (k) {
- case 1:
- type = GL_NONE;
- abort();
- break;
- case 2:
- type = GL_FLOAT;
- break;
- case 3:
- type = GL_FLOAT_VEC2;
- break;
- case 4:
- type = GL_FLOAT_VEC3;
- break;
- case 5:
- type = GL_FLOAT_VEC4;
- break;
- }
+ type = TypeFromName(typeName);
strcpy(conf->uniforms[conf->num_uniforms].name, name);
conf->uniforms[conf->num_uniforms].value[0] = v1;
diff --git a/progs/glsl/toyball.shtest b/progs/glsl/toyball.shtest
index 2852ab043e..887663abd3 100644
--- a/progs/glsl/toyball.shtest
+++ b/progs/glsl/toyball.shtest
@@ -1,17 +1,17 @@
vs CH11-toyball.vert
fs CH11-toyball.frag
-uniform LightDir 0.57737 0.57735 0.57735 0.0
-uniform HVector 0.32506 0.32506 0.88808 0.0
-uniform BallCenter 0.0 0.0 0.0 1.0
-uniform SpecularColor 0.4 0.4 0.4 60.0
-uniform Red 0.6 0.0 0.0 1.0
-uniform Blue 0.0 0.3 0.6 1.0
-uniform Yellow 0.6 0.5 0.0 1.0
-uniform HalfSpace0 1.0 0.0 0.0 0.2
-uniform HalfSpace1 .309016994 0.951056516 0.0 0.2
-uniform HalfSpace2 -0.809016994 0.587785252 0.0 0.2
-uniform HalfSpace3 -0.809016994 -0.587785252 0.0 0.2
-uniform HalfSpace4 .309116994 -0.951056516 0.0 0.2
-uniform InOrOutInit -3.0
-uniform StripeWidth 0.3
-uniform FWidth .005
+uniform LightDir GL_FLOAT_VEC4 0.57737 0.57735 0.57735 0.0
+uniform HVector GL_FLOAT_VEC4 0.32506 0.32506 0.88808 0.0
+uniform BallCenter GL_FLOAT_VEC4 0.0 0.0 0.0 1.0
+uniform SpecularColor GL_FLOAT_VEC4 0.4 0.4 0.4 60.0
+uniform Red GL_FLOAT_VEC4 0.6 0.0 0.0 1.0
+uniform Blue GL_FLOAT_VEC4 0.0 0.3 0.6 1.0
+uniform Yellow GL_FLOAT_VEC4 0.6 0.5 0.0 1.0
+uniform HalfSpace0 GL_FLOAT_VEC4 1.0 0.0 0.0 0.2
+uniform HalfSpace1 GL_FLOAT_VEC4 .309016994 0.951056516 0.0 0.2
+uniform HalfSpace2 GL_FLOAT_VEC4 -0.809016994 0.587785252 0.0 0.2
+uniform HalfSpace3 GL_FLOAT_VEC4 -0.809016994 -0.587785252 0.0 0.2
+uniform HalfSpace4 GL_FLOAT_VEC4 .309116994 -0.951056516 0.0 0.2
+uniform InOrOutInit GL_FLOAT -3.0
+uniform StripeWidth GL_FLOAT 0.3
+uniform FWidth GL_FLOAT .005