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
#include <GL/glu.h>
#include <GL/glut.h>
#include "shaderutil.h"
+#include "readtex.h"
typedef enum
}
+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.
*/
/* 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;
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;
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