summaryrefslogtreecommitdiffstats
path: root/progs/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'progs/glsl')
-rw-r--r--progs/glsl/.gitignore4
-rw-r--r--progs/glsl/CH11-bumpmap.frag2
-rw-r--r--progs/glsl/Makefile87
-rw-r--r--progs/glsl/convolutions.c27
-rw-r--r--progs/glsl/identity.c208
-rw-r--r--progs/glsl/texdemo1.c4
6 files changed, 280 insertions, 52 deletions
diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore
index 1e0aecebef4..6cc7edc0195 100644
--- a/progs/glsl/.gitignore
+++ b/progs/glsl/.gitignore
@@ -1,16 +1,20 @@
bitmap
brick
bump
+convolutions
deriv
extfuncs.h
+identity
mandelbrot
multitex
noise
+pointcoord
points
readtex.c
readtex.h
shaderutil.c
shaderutil.h
+skinning
texdemo1
toyball
trirast
diff --git a/progs/glsl/CH11-bumpmap.frag b/progs/glsl/CH11-bumpmap.frag
index 063576f5a3c..e12c5d374cd 100644
--- a/progs/glsl/CH11-bumpmap.frag
+++ b/progs/glsl/CH11-bumpmap.frag
@@ -24,7 +24,7 @@ void main()
float d, f;
d = p.x * p.x + p.y * p.y;
- f = 1.0 / sqrt(d + 1.0);
+ f = inversesqrt(d + 1.0);
if (d >= BumpSize)
{ p = vec2(0.0); f = 1.0; }
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index 7c3e750882f..5419dfc7f46 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -15,6 +15,7 @@ PROGS = \
bump \
convolutions \
deriv \
+ identity \
fragcoord \
mandelbrot \
multitex \
@@ -25,7 +26,8 @@ PROGS = \
texdemo1 \
toyball \
twoside \
- trirast
+ trirast \
+ texdemo1
##### RULES #####
@@ -36,7 +38,7 @@ PROGS = \
# make executable from .c file:
.c: $(LIB_DEP)
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
##### TARGETS #####
@@ -58,7 +60,7 @@ readtex.h: $(TOP)/progs/util/readtex.h
cp $< .
readtex.o: readtex.c readtex.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) readtex.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) readtex.c
shaderutil.c: $(TOP)/progs/util/shaderutil.c
@@ -68,43 +70,57 @@ shaderutil.h: $(TOP)/progs/util/shaderutil.h
cp $< .
shaderutil.o: shaderutil.c shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c
bitmap.o: bitmap.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c
bitmap: bitmap.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bitmap.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bitmap.o shaderutil.o $(LIBS) -o $@
brick.o: brick.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) brick.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) brick.c
brick: brick.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) brick.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) brick.o shaderutil.o $(LIBS) -o $@
bump.o: bump.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) bump.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bump.c
bump: bump.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@
convolutions.o: convolutions.c readtex.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c
convolutions: convolutions.o readtex.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) convolutions.o readtex.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) convolutions.o readtex.o $(LIBS) -o $@
deriv.o: deriv.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) deriv.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) deriv.c
deriv: deriv.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@
+
+
+identity.o: identity.c extfuncs.h shaderutil.h
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) identity.c
+
+identity: identity.o shaderutil.o
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) identity.o shaderutil.o $(LIBS) -o $@
+
+
+fragcoord.o: fragcoord.c extfuncs.h shaderutil.h
+ $(CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c
+
+fragcoord: fragcoord.o shaderutil.o
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@
fragcoord.o: fragcoord.c extfuncs.h shaderutil.h
@@ -115,75 +131,72 @@ fragcoord: fragcoord.o shaderutil.o
mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c
mandelbrot: mandelbrot.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) mandelbrot.o shaderutil.o $(LIBS) -o $@
-
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) mandelbrot.o shaderutil.o $(LIBS) -o $@
multitex.o: multitex.c extfuncs.h readtex.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) multitex.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) multitex.c
multitex: multitex.o readtex.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) multitex.o readtex.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) multitex.o readtex.o shaderutil.o $(LIBS) -o $@
noise.o: noise.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) noise.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) noise.c
noise: noise.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@
points.o: points.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) points.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) points.c
points: points.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) points.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) points.o shaderutil.o $(LIBS) -o $@
pointcoord.o: pointcoord.c readtex.h extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) pointcoord.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) pointcoord.c
pointcoord: pointcoord.o readtex.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@
skinning.o: skinning.c readtex.h extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) skinning.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) skinning.c
skinning: skinning.o readtex.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) skinning.o readtex.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) skinning.o readtex.o shaderutil.o $(LIBS) -o $@
texdemo1.o: texdemo1.c readtex.h extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c
texdemo1: texdemo1.o readtex.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o shaderutil.o $(LIBS) -o $@
toyball.o: toyball.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) toyball.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) toyball.c
toyball: toyball.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) toyball.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) toyball.o shaderutil.o $(LIBS) -o $@
twoside.o: twoside.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) twoside.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) twoside.c
twoside: twoside.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) twoside.o shaderutil.o $(LIBS) -o $@
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) twoside.o shaderutil.o $(LIBS) -o $@
trirast.o: trirast.c extfuncs.h shaderutil.h
- $(CC) -c -I$(INCDIR) $(CFLAGS) trirast.c
+ $(APP_CC) -c -I$(INCDIR) $(CFLAGS) trirast.c
trirast: trirast.o shaderutil.o
- $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@
-
-
+ $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@
diff --git a/progs/glsl/convolutions.c b/progs/glsl/convolutions.c
index c5caa8ffedf..ac71c68235e 100644
--- a/progs/glsl/convolutions.c
+++ b/progs/glsl/convolutions.c
@@ -61,15 +61,15 @@ static void loadAndCompileShader(GLuint shader, const char *text)
{
GLint stat;
- glShaderSourceARB(shader, 1, (const GLchar **) &text, NULL);
+ glShaderSource(shader, 1, (const GLchar **) &text, NULL);
- glCompileShaderARB(shader);
+ glCompileShader(shader);
- glGetObjectParameterivARB(shader, GL_COMPILE_STATUS, &stat);
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
if (!stat) {
GLchar log[1000];
GLsizei len;
- glGetInfoLogARB(shader, 1000, &len, log);
+ glGetShaderInfoLog(shader, 1000, &len, log);
fprintf(stderr, "Problem compiling shader: %s\n", log);
exit(1);
}
@@ -105,11 +105,11 @@ static void
checkLink(GLuint prog)
{
GLint stat;
- glGetObjectParameterivARB(prog, GL_LINK_STATUS, &stat);
+ glGetProgramiv(prog, GL_LINK_STATUS, &stat);
if (!stat) {
GLchar log[1000];
GLsizei len;
- glGetInfoLogARB(prog, 1000, &len, log);
+ glGetProgramInfoLog(prog, 1000, &len, log);
fprintf(stderr, "Linker error:\n%s\n", log);
}
else {
@@ -200,12 +200,12 @@ static void setupConvolution()
}
loc = glGetUniformLocationARB(program, "KernelValue");
- glUniform4fvARB(loc, 9, vecKer);
+ glUniform4fv(loc, 9, vecKer);
loc = glGetUniformLocationARB(program, "ScaleFactor");
- glUniform4fARB(loc, scale, scale, scale, scale);
+ glUniform4f(loc, scale, scale, scale, scale);
loc = glGetUniformLocationARB(program, "BaseColor");
- glUniform4fARB(loc, baseColor[0], baseColor[1],
- baseColor[2], baseColor[3]);
+ glUniform4f(loc, baseColor[0], baseColor[1],
+ baseColor[2], baseColor[3]);
free(vecKer);
free(kernel);
@@ -229,10 +229,10 @@ static void createProgram(const char *vertProgFile,
glAttachShader(program, fragShader);
}
- glLinkProgramARB(program);
+ glLinkProgram(program);
checkLink(program);
- glUseProgramObjectARB(program);
+ glUseProgram(program);
/*
assert(glIsProgram(program));
@@ -256,7 +256,7 @@ static void createProgram(const char *vertProgFile,
0.0 , -1.0 / texture.height,
-1.0 / texture.width, -1.0 / texture.height };
GLuint offsetLoc = glGetUniformLocationARB(program, "Offset");
- glUniform2fvARB(offsetLoc, 9, offsets);
+ glUniform2fv(offsetLoc, 9, offsets);
}
setupConvolution();
@@ -331,6 +331,7 @@ static void init()
fprintf(stderr, "Sorry, this program requires GL_ARB_shader_objects, GL_ARB_vertex_shader, and GL_ARB_fragment_shader\n");
exit(1);
}
+
fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
diff --git a/progs/glsl/identity.c b/progs/glsl/identity.c
new file mode 100644
index 00000000000..37579eb3469
--- /dev/null
+++ b/progs/glsl/identity.c
@@ -0,0 +1,208 @@
+/**
+ * Test very basic glsl functionality (identity vertex and fragment shaders).
+ * Brian Paul & Stephane Marchesin
+ */
+
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#include "extfuncs.h"
+#include "shaderutil.h"
+
+
+static char *FragProgFile = NULL;
+static char *VertProgFile = NULL;
+static GLuint fragShader;
+static GLuint vertShader;
+static GLuint program;
+static GLint win = 0;
+static GLboolean anim = GL_FALSE;
+static GLfloat xRot = 0.0f, yRot = 0.0f;
+static int w,h;
+
+
+static void
+Redisplay(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glBegin(GL_TRIANGLES);
+ glColor3f(.8,0,0);
+ glVertex3f(-0.9, -0.9, 0.0);
+ glColor3f(0,.9,0);
+ glVertex3f( 0.9, -0.9, 0.0);
+ glColor3f(0,0,.7);
+ glVertex3f( 0.0, 0.9, 0.0);
+ glEnd();
+
+ glutSwapBuffers();
+}
+
+
+static void
+Idle(void)
+{
+ yRot = glutGet(GLUT_ELAPSED_TIME) * 0.1;
+ glutPostRedisplay();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ w = width;
+ h = height;
+}
+
+
+static void
+CleanUp(void)
+{
+ glDeleteShader_func(fragShader);
+ glDeleteShader_func(vertShader);
+ glDeleteProgram_func(program);
+ glutDestroyWindow(win);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+
+ switch(key) {
+ case ' ':
+ case 'a':
+ anim = !anim;
+ if (anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case 27:
+ CleanUp();
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+SpecialKey(int key, int x, int y)
+{
+ const GLfloat step = 3.0f;
+
+ (void) x;
+ (void) y;
+
+ switch(key) {
+ case GLUT_KEY_UP:
+ xRot -= step;
+ break;
+ case GLUT_KEY_DOWN:
+ xRot += step;
+ break;
+ case GLUT_KEY_LEFT:
+ yRot -= step;
+ break;
+ case GLUT_KEY_RIGHT:
+ yRot += step;
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+Init(void)
+{
+ static const char *fragShaderText =
+ "void main() {\n"
+ " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
+ "}\n";
+ static const char *vertShaderText =
+ "void main() {\n"
+ " gl_Position = gl_Vertex;\n"
+ "}\n";
+
+ if (!ShadersSupported())
+ exit(1);
+
+ GetExtensionFuncs();
+
+ if (FragProgFile)
+ fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
+ else
+ fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
+
+ if (VertProgFile)
+ vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
+ else
+ vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
+
+ program = LinkShaders(vertShader, fragShader);
+
+ glUseProgram_func(program);
+
+ /*assert(glGetError() == 0);*/
+
+ glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
+ glEnable(GL_DEPTH_TEST);
+
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+
+ assert(glIsProgram_func(program));
+ assert(glIsShader_func(fragShader));
+ assert(glIsShader_func(vertShader));
+
+ glColor3f(1, 0, 0);
+}
+
+
+static void
+ParseOptions(int argc, char *argv[])
+{
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-fs") == 0) {
+ FragProgFile = argv[i+1];
+ }
+ else if (strcmp(argv[i], "-vs") == 0) {
+ VertProgFile = argv[i+1];
+ }
+ }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition( 0, 0);
+ glutInitWindowSize(200, 200);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Redisplay);
+ if (anim)
+ glutIdleFunc(Idle);
+ ParseOptions(argc, argv);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c
index 41010746eea..96ddca1f32d 100644
--- a/progs/glsl/texdemo1.c
+++ b/progs/glsl/texdemo1.c
@@ -49,6 +49,7 @@ static GLfloat TexXrot = 0, TexYrot = 0;
static GLfloat Xrot = 20.0, Yrot = 20.0, Zrot = 0.0;
static GLfloat EyeDist = 10;
static GLboolean Anim = GL_TRUE;
+static int win = 0;
static struct uniform_info ReflectUniforms[] = {
@@ -159,6 +160,7 @@ key(unsigned char k, int x, int y)
EyeDist = 90;
break;
case 27:
+ glutDestroyWindow(win);
exit(0);
}
glutPostRedisplay();
@@ -423,7 +425,7 @@ main(int argc, char *argv[])
glutInit(&argc, argv);
glutInitWindowSize(500, 400);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutCreateWindow(Demo);
+ win = glutCreateWindow(Demo);
glutReshapeFunc(Reshape);
glutKeyboardFunc(key);
glutSpecialFunc(specialkey);