summaryrefslogtreecommitdiff
path: root/progs/glsl
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2008-09-28 18:28:05 +0200
committerNicolai Haehnle <nhaehnle@gmail.com>2008-09-28 18:47:13 +0200
commit3dba9178ec5dbf8183a5ceee701c9a36606ad464 (patch)
tree51276417f55673bb44810780d222516c84672a3e /progs/glsl
parent857362ef14fc4f175a9d425a74f9ca2b691971d6 (diff)
parent2e5d717007ba6515b094b9af8ed869130185a308 (diff)
Merge branch 'master' into develop
Conflicts: src/mesa/drivers/dri/r300/r300_tex.c src/mesa/drivers/dri/r300/r300_texstate.c src/mesa/drivers/dri/r300/radeon_context.c src/mesa/drivers/dri/r300/radeon_context.h
Diffstat (limited to 'progs/glsl')
-rw-r--r--progs/glsl/CH06-brick.frag (renamed from progs/glsl/CH06-brick.frag.txt)0
-rw-r--r--progs/glsl/CH06-brick.vert (renamed from progs/glsl/CH06-brick.vert.txt)0
-rw-r--r--progs/glsl/CH11-bumpmap.frag (renamed from progs/glsl/CH11-bumpmap.frag.txt)0
-rw-r--r--progs/glsl/CH11-bumpmap.vert (renamed from progs/glsl/CH11-bumpmap.vert.txt)0
-rw-r--r--progs/glsl/CH11-toyball.frag (renamed from progs/glsl/CH11-toyball.frag.txt)0
-rw-r--r--progs/glsl/CH11-toyball.vert (renamed from progs/glsl/CH11-toyball.vert.txt)0
-rw-r--r--progs/glsl/CH18-mandel.frag (renamed from progs/glsl/CH18-mandel.frag.txt)0
-rw-r--r--progs/glsl/CH18-mandel.vert (renamed from progs/glsl/CH18-mandel.vert.txt)0
-rw-r--r--progs/glsl/Makefile16
-rw-r--r--progs/glsl/brick.c4
-rw-r--r--progs/glsl/bump.c4
-rw-r--r--progs/glsl/convolution.frag21
-rw-r--r--progs/glsl/convolution.vert5
-rw-r--r--progs/glsl/convolutions.c469
-rw-r--r--progs/glsl/cubemap.frag (renamed from progs/glsl/cubemap.frag.txt)0
-rw-r--r--progs/glsl/mandelbrot.c4
-rw-r--r--progs/glsl/multitex.c4
-rw-r--r--progs/glsl/multitex.frag (renamed from progs/glsl/multitex.frag.txt)4
-rw-r--r--progs/glsl/multitex.vert (renamed from progs/glsl/multitex.vert.txt)0
-rw-r--r--progs/glsl/pointcoord.c205
-rw-r--r--progs/glsl/reflect.vert (renamed from progs/glsl/reflect.vert.txt)0
-rw-r--r--progs/glsl/shadowtex.frag (renamed from progs/glsl/shadowtex.frag.txt)0
-rw-r--r--progs/glsl/simple.vert (renamed from progs/glsl/simple.vert.txt)0
-rw-r--r--progs/glsl/texdemo1.c8
-rw-r--r--progs/glsl/toyball.c4
-rw-r--r--progs/glsl/trirast.c2
-rw-r--r--progs/glsl/twoside.c52
27 files changed, 771 insertions, 31 deletions
diff --git a/progs/glsl/CH06-brick.frag.txt b/progs/glsl/CH06-brick.frag
index 06ef04e3af..06ef04e3af 100644
--- a/progs/glsl/CH06-brick.frag.txt
+++ b/progs/glsl/CH06-brick.frag
diff --git a/progs/glsl/CH06-brick.vert.txt b/progs/glsl/CH06-brick.vert
index e95e6f42f0..e95e6f42f0 100644
--- a/progs/glsl/CH06-brick.vert.txt
+++ b/progs/glsl/CH06-brick.vert
diff --git a/progs/glsl/CH11-bumpmap.frag.txt b/progs/glsl/CH11-bumpmap.frag
index 063576f5a3..063576f5a3 100644
--- a/progs/glsl/CH11-bumpmap.frag.txt
+++ b/progs/glsl/CH11-bumpmap.frag
diff --git a/progs/glsl/CH11-bumpmap.vert.txt b/progs/glsl/CH11-bumpmap.vert
index d3d19f62ac..d3d19f62ac 100644
--- a/progs/glsl/CH11-bumpmap.vert.txt
+++ b/progs/glsl/CH11-bumpmap.vert
diff --git a/progs/glsl/CH11-toyball.frag.txt b/progs/glsl/CH11-toyball.frag
index 90ec1c27fc..90ec1c27fc 100644
--- a/progs/glsl/CH11-toyball.frag.txt
+++ b/progs/glsl/CH11-toyball.frag
diff --git a/progs/glsl/CH11-toyball.vert.txt b/progs/glsl/CH11-toyball.vert
index b7da3ac839..b7da3ac839 100644
--- a/progs/glsl/CH11-toyball.vert.txt
+++ b/progs/glsl/CH11-toyball.vert
diff --git a/progs/glsl/CH18-mandel.frag.txt b/progs/glsl/CH18-mandel.frag
index a472d81252..a472d81252 100644
--- a/progs/glsl/CH18-mandel.frag.txt
+++ b/progs/glsl/CH18-mandel.frag
diff --git a/progs/glsl/CH18-mandel.vert.txt b/progs/glsl/CH18-mandel.vert
index c4ca66405d..c4ca66405d 100644
--- a/progs/glsl/CH18-mandel.vert.txt
+++ b/progs/glsl/CH18-mandel.vert
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index e3f205cdb9..850b6bdbd1 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -13,11 +13,13 @@ PROGS = \
bitmap \
brick \
bump \
+ convolutions \
deriv \
mandelbrot \
multitex \
noise \
points \
+ pointcoord \
texdemo1 \
toyball \
twoside \
@@ -89,6 +91,13 @@ bump: bump.o shaderutil.o
$(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@
+convolutions.o: convolutions.c readtex.h
+ $(CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c
+
+convolutions: convolutions.o readtex.o
+ $(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
@@ -124,6 +133,13 @@ points: points.o shaderutil.o
$(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
+
+pointcoord: pointcoord.o readtex.o shaderutil.o
+ $(CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@
+
+
texdemo1.o: texdemo1.c readtex.h extfuncs.h shaderutil.h
$(CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c
diff --git a/progs/glsl/brick.c b/progs/glsl/brick.c
index 4be266622b..526ef0e2e3 100644
--- a/progs/glsl/brick.c
+++ b/progs/glsl/brick.c
@@ -16,8 +16,8 @@
#include "shaderutil.h"
-static char *FragProgFile = "CH06-brick.frag.txt";
-static char *VertProgFile = "CH06-brick.vert.txt";
+static char *FragProgFile = "CH06-brick.frag";
+static char *VertProgFile = "CH06-brick.vert";
/* program/shader objects */
static GLuint fragShader;
diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c
index e42421d489..a2e0916861 100644
--- a/progs/glsl/bump.c
+++ b/progs/glsl/bump.c
@@ -16,8 +16,8 @@
#include "shaderutil.h"
-static char *FragProgFile = "CH11-bumpmap.frag.txt";
-static char *VertProgFile = "CH11-bumpmap.vert.txt";
+static char *FragProgFile = "CH11-bumpmap.frag";
+static char *VertProgFile = "CH11-bumpmap.vert";
/* program/shader objects */
static GLuint fragShader;
diff --git a/progs/glsl/convolution.frag b/progs/glsl/convolution.frag
new file mode 100644
index 0000000000..e49b8acf54
--- /dev/null
+++ b/progs/glsl/convolution.frag
@@ -0,0 +1,21 @@
+
+const int KernelSize = 9;
+
+//texture offsets
+uniform vec2 Offset[KernelSize];
+//convolution kernel
+uniform vec4 KernelValue[KernelSize];
+uniform sampler2D srcTex;
+uniform vec4 ScaleFactor;
+uniform vec4 BaseColor;
+
+void main(void)
+{
+ int i;
+ vec4 sum = vec4(0.0);
+ for (i = 0; i < KernelSize; ++i) {
+ vec4 tmp = texture2D(srcTex, gl_TexCoord[0].st + Offset[i]);
+ sum += tmp * KernelValue[i];
+ }
+ gl_FragColor = sum * ScaleFactor + BaseColor;
+}
diff --git a/progs/glsl/convolution.vert b/progs/glsl/convolution.vert
new file mode 100644
index 0000000000..752c54671c
--- /dev/null
+++ b/progs/glsl/convolution.vert
@@ -0,0 +1,5 @@
+void main() {
+ gl_FrontColor = gl_Color;
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
diff --git a/progs/glsl/convolutions.c b/progs/glsl/convolutions.c
new file mode 100644
index 0000000000..13c7eab0ea
--- /dev/null
+++ b/progs/glsl/convolutions.c
@@ -0,0 +1,469 @@
+/**
+ * Convolution with GLSL.
+ * Note: uses GL_ARB_shader_objects, GL_ARB_vertex_shader, GL_ARB_fragment_shader,
+ * not the OpenGL 2.0 shader API.
+ * Author: Zack Rusin
+ */
+
+#define GL_GLEXT_PROTOTYPES
+#include "readtex.h"
+
+#include <GL/glut.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <math.h>
+
+enum Filter {
+ GAUSSIAN_BLUR,
+ SHARPEN,
+ MEAN_REMOVAL,
+ EMBOSS,
+ EDGE_DETECT,
+ NO_FILTER,
+ LAST
+};
+#define QUIT LAST
+
+struct BoundingBox {
+ float minx, miny, minz;
+ float maxx, maxy, maxz;
+};
+struct Texture {
+ GLuint id;
+ GLfloat x;
+ GLfloat y;
+ GLint width;
+ GLint height;
+ GLenum format;
+};
+
+static const char *textureLocation = "../images/girl2.rgb";
+
+static GLfloat viewRotx = 0.0, viewRoty = 0.0, viewRotz = 0.0;
+static struct BoundingBox box;
+static struct Texture texture;
+static GLuint program;
+static GLint menuId;
+static enum Filter filter = GAUSSIAN_BLUR;
+
+
+static void checkError(int line)
+{
+ GLenum err = glGetError();
+ if (err) {
+ printf("GL Error %s (0x%x) at line %d\n",
+ gluErrorString(err), (int) err, line);
+ }
+}
+
+static void loadAndCompileShader(GLuint shader, const char *text)
+{
+ GLint stat;
+
+ glShaderSourceARB(shader, 1, (const GLchar **) &text, NULL);
+
+ glCompileShaderARB(shader);
+
+ glGetObjectParameterivARB(shader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetInfoLogARB(shader, 1000, &len, log);
+ fprintf(stderr, "Problem compiling shader: %s\n", log);
+ exit(1);
+ }
+ else {
+ printf("Shader compiled OK\n");
+ }
+}
+
+static void readShader(GLuint shader, const char *filename)
+{
+ const int max = 100*1000;
+ int n;
+ char *buffer = (char*) malloc(max);
+ FILE *f = fopen(filename, "r");
+ if (!f) {
+ fprintf(stderr, "Unable to open shader file %s\n", filename);
+ exit(1);
+ }
+
+ n = fread(buffer, 1, max, f);
+ printf("Read %d bytes from shader file %s\n", n, filename);
+ if (n > 0) {
+ buffer[n] = 0;
+ loadAndCompileShader(shader, buffer);
+ }
+
+ fclose(f);
+ free(buffer);
+}
+
+
+static void
+checkLink(GLuint prog)
+{
+ GLint stat;
+ glGetObjectParameterivARB(prog, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetInfoLogARB(prog, 1000, &len, log);
+ fprintf(stderr, "Linker error:\n%s\n", log);
+ }
+ else {
+ fprintf(stderr, "Link success!\n");
+ }
+}
+
+static void fillConvolution(GLint *k,
+ GLfloat *scale,
+ GLfloat *color)
+{
+ switch(filter) {
+ case GAUSSIAN_BLUR:
+ k[0] = 1; k[1] = 2; k[2] = 1;
+ k[3] = 2; k[4] = 4; k[5] = 2;
+ k[6] = 1; k[7] = 2; k[8] = 1;
+
+ *scale = 1./16.;
+ break;
+ case SHARPEN:
+ k[0] = 0; k[1] = -2; k[2] = 0;
+ k[3] = -2; k[4] = 11; k[5] = -2;
+ k[6] = 0; k[7] = -2; k[8] = 0;
+
+ *scale = 1./3.;
+ break;
+ case MEAN_REMOVAL:
+ k[0] = -1; k[1] = -1; k[2] = -1;
+ k[3] = -1; k[4] = 9; k[5] = -1;
+ k[6] = -1; k[7] = -1; k[8] = -1;
+
+ *scale = 1./1.;
+ break;
+ case EMBOSS:
+ k[0] = -1; k[1] = 0; k[2] = -1;
+ k[3] = 0; k[4] = 4; k[5] = 0;
+ k[6] = -1; k[7] = 0; k[8] = -1;
+
+ *scale = 1./1.;
+ color[0] = 0.5;
+ color[1] = 0.5;
+ color[2] = 0.5;
+ color[3] = 0.5;
+ break;
+ case EDGE_DETECT:
+ k[0] = 1; k[1] = 1; k[2] = 1;
+ k[3] = 0; k[4] = 0; k[5] = 0;
+ k[6] = -1; k[7] = -1; k[8] = -1;
+
+ *scale = 1.;
+ color[0] = 0.5;
+ color[1] = 0.5;
+ color[2] = 0.5;
+ color[3] = 0.5;
+ break;
+ case NO_FILTER:
+ k[0] = 0; k[1] = 0; k[2] = 0;
+ k[3] = 0; k[4] = 1; k[5] = 0;
+ k[6] = 0; k[7] = 0; k[8] = 0;
+
+ *scale = 1.;
+ break;
+ default:
+ assert(!"Unhandled switch value");
+ }
+}
+
+static void setupConvolution()
+{
+ GLint *kernel = (GLint*)malloc(sizeof(GLint) * 9);
+ GLfloat scale;
+ GLfloat *vecKer = (GLfloat*)malloc(sizeof(GLfloat) * 9 * 4);
+ GLuint loc;
+ GLuint i;
+ GLfloat baseColor[4];
+ baseColor[0] = 0;
+ baseColor[1] = 0;
+ baseColor[2] = 0;
+ baseColor[3] = 0;
+
+ fillConvolution(kernel, &scale, baseColor);
+ /*vector of 4*/
+ for (i = 0; i < 9; ++i) {
+ vecKer[i*4 + 0] = kernel[i];
+ vecKer[i*4 + 1] = kernel[i];
+ vecKer[i*4 + 2] = kernel[i];
+ vecKer[i*4 + 3] = kernel[i];
+ }
+
+ loc = glGetUniformLocationARB(program, "KernelValue");
+ glUniform4fvARB(loc, 9, vecKer);
+ loc = glGetUniformLocationARB(program, "ScaleFactor");
+ glUniform4fARB(loc, scale, scale, scale, scale);
+ loc = glGetUniformLocationARB(program, "BaseColor");
+ glUniform4fARB(loc, baseColor[0], baseColor[1],
+ baseColor[2], baseColor[3]);
+
+ free(vecKer);
+ free(kernel);
+}
+
+static void createProgram(const char *vertProgFile,
+ const char *fragProgFile)
+{
+ GLuint fragShader = 0, vertShader = 0;
+
+ program = glCreateProgram();
+ if (vertProgFile) {
+ vertShader = glCreateShader(GL_VERTEX_SHADER);
+ readShader(vertShader, vertProgFile);
+ glAttachShader(program, vertShader);
+ }
+
+ if (fragProgFile) {
+ fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ readShader(fragShader, fragProgFile);
+ glAttachShader(program, fragShader);
+ }
+
+ glLinkProgramARB(program);
+ checkLink(program);
+
+ glUseProgramObjectARB(program);
+
+ /*
+ assert(glIsProgram(program));
+ assert(glIsShader(fragShader));
+ assert(glIsShader(vertShader));
+ */
+
+ checkError(__LINE__);
+ {/*texture*/
+ GLuint texLoc = glGetUniformLocationARB(program, "srcTex");
+ glUniform1iARB(texLoc, 0);
+ }
+ {/*setup offsets */
+ float offsets[] = { 1.0 / texture.width, 1.0 / texture.height,
+ 0.0 , 1.0 / texture.height,
+ -1.0 / texture.width, 1.0 / texture.height,
+ 1.0 / texture.width, 0.0,
+ 0.0 , 0.0,
+ -1.0 / texture.width, 0.0,
+ 1.0 / texture.width, -1.0 / texture.height,
+ 0.0 , -1.0 / texture.height,
+ -1.0 / texture.width, -1.0 / texture.height };
+ GLuint offsetLoc = glGetUniformLocationARB(program, "Offset");
+ glUniform2fvARB(offsetLoc, 9, offsets);
+ }
+ setupConvolution();
+
+ checkError(__LINE__);
+}
+
+
+static void readTexture(const char *filename)
+{
+ GLubyte *data;
+
+ texture.x = 0;
+ texture.y = 0;
+
+ glGenTextures(1, &texture.id);
+ glBindTexture(GL_TEXTURE_2D, texture.id);
+ glTexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D,
+ GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ data = LoadRGBImage(filename, &texture.width, &texture.height,
+ &texture.format);
+ if (!data) {
+ printf("Error: couldn't load texture image '%s'\n", filename);
+ exit(1);
+ }
+ printf("Texture %s (%d x %d)\n",
+ filename, texture.width, texture.height);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+ texture.width, texture.height, 0, texture.format,
+ GL_UNSIGNED_BYTE, data);
+}
+
+static void menuSelected(int entry)
+{
+ switch (entry) {
+ case QUIT:
+ exit(0);
+ break;
+ default:
+ filter = (enum Filter)entry;
+ }
+ setupConvolution();
+
+ glutPostRedisplay();
+}
+
+static void menuInit()
+{
+ menuId = glutCreateMenu(menuSelected);
+
+ glutAddMenuEntry("Gaussian blur", GAUSSIAN_BLUR);
+ glutAddMenuEntry("Sharpen", SHARPEN);
+ glutAddMenuEntry("Mean removal", MEAN_REMOVAL);
+ glutAddMenuEntry("Emboss", EMBOSS);
+ glutAddMenuEntry("Edge detect", EDGE_DETECT);
+ glutAddMenuEntry("None", NO_FILTER);
+
+ glutAddMenuEntry("Quit", QUIT);
+
+ glutAttachMenu(GLUT_RIGHT_BUTTON);
+}
+
+static void init()
+{
+ if (!glutExtensionSupported("GL_ARB_shader_objects") ||
+ !glutExtensionSupported("GL_ARB_vertex_shader") ||
+ !glutExtensionSupported("GL_ARB_fragment_shader")) {
+ 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));
+
+ menuInit();
+ readTexture(textureLocation);
+ createProgram("convolution.vert", "convolution.frag");
+
+ glEnable(GL_TEXTURE_2D);
+ glClearColor(1.0, 1.0, 1.0, 1.0);
+ /*glShadeModel(GL_SMOOTH);*/
+ glShadeModel(GL_FLAT);
+}
+
+static void reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ box.minx = 0;
+ box.maxx = width;
+ box.miny = 0;
+ box.maxy = height;
+ box.minz = 0;
+ box.maxz = 1;
+ glOrtho(box.minx, box.maxx, box.miny, box.maxy, -999999, 999999);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+static void keyPress(unsigned char key, int x, int y)
+{
+ switch(key) {
+ case 27:
+ exit(0);
+ default:
+ return;
+ }
+ glutPostRedisplay();
+}
+
+static void
+special(int k, int x, int y)
+{
+ switch (k) {
+ case GLUT_KEY_UP:
+ viewRotx += 2.0;
+ break;
+ case GLUT_KEY_DOWN:
+ viewRotx -= 2.0;
+ break;
+ case GLUT_KEY_LEFT:
+ viewRoty += 2.0;
+ break;
+ case GLUT_KEY_RIGHT:
+ viewRoty -= 2.0;
+ break;
+ default:
+ return;
+ }
+ glutPostRedisplay();
+}
+
+
+static void draw()
+{
+ GLfloat center[2];
+ GLfloat anchor[2];
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glLoadIdentity();
+ glPushMatrix();
+
+ center[0] = box.maxx/2;
+ center[1] = box.maxy/2;
+ anchor[0] = center[0] - texture.width/2;
+ anchor[1] = center[1] - texture.height/2;
+
+ glTranslatef(center[0], center[1], 0);
+ glRotatef(viewRotx, 1.0, 0.0, 0.0);
+ glRotatef(viewRoty, 0.0, 1.0, 0.0);
+ glRotatef(viewRotz, 0.0, 0.0, 1.0);
+ glTranslatef(-center[0], -center[1], 0);
+
+ glTranslatef(anchor[0], anchor[1], 0);
+ glBegin(GL_TRIANGLE_STRIP);
+ {
+ glColor3f(1., 0., 0.);
+ glTexCoord2f(0, 0);
+ glVertex3f(0, 0, 0);
+
+ glColor3f(0., 1., 0.);
+ glTexCoord2f(0, 1.0);
+ glVertex3f(0, texture.height, 0);
+
+ glColor3f(1., 0., 0.);
+ glTexCoord2f(1.0, 0);
+ glVertex3f(texture.width, 0, 0);
+
+ glColor3f(0., 1., 0.);
+ glTexCoord2f(1, 1);
+ glVertex3f(texture.width, texture.height, 0);
+ }
+ glEnd();
+
+ glPopMatrix();
+
+ glFlush();
+
+ glutSwapBuffers();
+}
+
+int main(int argc, char **argv)
+{
+ glutInit(&argc, argv);
+
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize(400, 400);
+ glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE);
+
+ if (!glutCreateWindow("Image Convolutions")) {
+ fprintf(stderr, "Couldn't create window!\n");
+ exit(1);
+ }
+
+ init();
+
+ glutReshapeFunc(reshape);
+ glutKeyboardFunc(keyPress);
+ glutSpecialFunc(special);
+ glutDisplayFunc(draw);
+
+
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/glsl/cubemap.frag.txt b/progs/glsl/cubemap.frag
index 9c27648aaf..9c27648aaf 100644
--- a/progs/glsl/cubemap.frag.txt
+++ b/progs/glsl/cubemap.frag
diff --git a/progs/glsl/mandelbrot.c b/progs/glsl/mandelbrot.c
index fa67a3c2ca..e6361b429b 100644
--- a/progs/glsl/mandelbrot.c
+++ b/progs/glsl/mandelbrot.c
@@ -16,8 +16,8 @@
#include "shaderutil.h"
-static char *FragProgFile = "CH18-mandel.frag.txt";
-static char *VertProgFile = "CH18-mandel.vert.txt";
+static char *FragProgFile = "CH18-mandel.frag";
+static char *VertProgFile = "CH18-mandel.vert";
/* program/shader objects */
static GLuint fragShader;
diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c
index 5574ed4139..096d40f64d 100644
--- a/progs/glsl/multitex.c
+++ b/progs/glsl/multitex.c
@@ -35,8 +35,8 @@
static const char *Demo = "multitex";
-static const char *VertFile = "multitex.vert.txt";
-static const char *FragFile = "multitex.frag.txt";
+static const char *VertFile = "multitex.vert";
+static const char *FragFile = "multitex.frag";
static const char *TexFiles[2] =
{
diff --git a/progs/glsl/multitex.frag.txt b/progs/glsl/multitex.frag
index 86045306af..a2633ceba7 100644
--- a/progs/glsl/multitex.frag.txt
+++ b/progs/glsl/multitex.frag
@@ -9,7 +9,7 @@ uniform sampler2D tex2;
void main()
{
- vec4 t1 = texture2D(tex1, gl_TexCoord[0].xy, 0.0);
- vec4 t2 = texture2D(tex2, gl_TexCoord[1].xy, 0.0);
+ vec4 t1 = texture2D(tex1, gl_TexCoord[0].xy);
+ vec4 t2 = texture2D(tex2, gl_TexCoord[1].xy);
gl_FragColor = mix(t1, t2, t2.w);
}
diff --git a/progs/glsl/multitex.vert.txt b/progs/glsl/multitex.vert
index 5518ca1ddd..5518ca1ddd 100644
--- a/progs/glsl/multitex.vert.txt
+++ b/progs/glsl/multitex.vert
diff --git a/progs/glsl/pointcoord.c b/progs/glsl/pointcoord.c
new file mode 100644
index 0000000000..b240077c25
--- /dev/null
+++ b/progs/glsl/pointcoord.c
@@ -0,0 +1,205 @@
+/**
+ * Test GLSL 1.20 gl_PointCoord fragment program attribute.
+ * Brian Paul
+ * 11 Aug 2007
+ */
+
+
+#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 GLint WinWidth = 300, WinHeight = 300;
+static char *FragProgFile = NULL;
+static char *VertProgFile = NULL;
+static GLuint fragShader;
+static GLuint vertShader;
+static GLuint program;
+static GLint win = 0;
+static GLint tex0;
+static GLenum Filter = GL_NEAREST;
+
+
+static void
+Redisplay(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* draw one point/sprite */
+ glPushMatrix();
+ glPointSize(60);
+ glBegin(GL_POINTS);
+ glVertex2f(WinWidth / 2.0f, WinHeight / 2.0f);
+ glEnd();
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, width, 0, height, -1, 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ WinWidth = width;
+ WinHeight = 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 27:
+ CleanUp();
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+
+static void
+MakeTexture(void)
+{
+#define SZ 16
+ GLubyte image[SZ][SZ][4];
+ GLuint i, j;
+
+ for (i = 0; i < SZ; i++) {
+ for (j = 0; j < SZ; j++) {
+ if ((i + j) & 1) {
+ image[i][j][0] = 0;
+ image[i][j][1] = 0;
+ image[i][j][2] = 0;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = j * 255 / (SZ-1);
+ image[i][j][1] = i * 255 / (SZ-1);
+ image[i][j][2] = 0;
+ image[i][j][3] = 255;
+ }
+ }
+ }
+
+ glActiveTexture(GL_TEXTURE0); /* unit 0 */
+ glBindTexture(GL_TEXTURE_2D, 42);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SZ, SZ, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+#undef SZ
+}
+
+
+static void
+Init(void)
+{
+ static const char *fragShaderText =
+ "#version 120 \n"
+ "uniform sampler2D tex0; \n"
+ "void main() { \n"
+ " gl_FragColor = texture2D(tex0, gl_PointCoord.xy, 0.0); \n"
+ "}\n";
+ static const char *vertShaderText =
+ "void main() {\n"
+ " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ "}\n";
+
+ if (!ShadersSupported())
+ exit(1);
+
+ GetExtensionFuncs();
+
+ vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
+ fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
+ program = LinkShaders(vertShader, fragShader);
+
+ glUseProgram_func(program);
+
+ tex0 = glGetUniformLocation_func(program, "tex0");
+ printf("Uniforms: tex0: %d\n", tex0);
+
+ glUniform1i_func(tex0, 0); /* tex unit 0 */
+
+ /*assert(glGetError() == 0);*/
+
+ glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
+
+ printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+
+ assert(glIsProgram_func(program));
+ assert(glIsShader_func(fragShader));
+ assert(glIsShader_func(vertShader));
+
+ MakeTexture();
+
+ glEnable(GL_POINT_SPRITE);
+
+ 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(WinWidth, WinHeight);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Redisplay);
+ ParseOptions(argc, argv);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/glsl/reflect.vert.txt b/progs/glsl/reflect.vert
index 402be38bf7..402be38bf7 100644
--- a/progs/glsl/reflect.vert.txt
+++ b/progs/glsl/reflect.vert
diff --git a/progs/glsl/shadowtex.frag.txt b/progs/glsl/shadowtex.frag
index a6a80da47f..a6a80da47f 100644
--- a/progs/glsl/shadowtex.frag.txt
+++ b/progs/glsl/shadowtex.frag
diff --git a/progs/glsl/simple.vert.txt b/progs/glsl/simple.vert
index a0abe0dc0b..a0abe0dc0b 100644
--- a/progs/glsl/simple.vert.txt
+++ b/progs/glsl/simple.vert
diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c
index 3dd19eaf4b..41010746ee 100644
--- a/progs/glsl/texdemo1.c
+++ b/progs/glsl/texdemo1.c
@@ -35,11 +35,11 @@
static const char *Demo = "texdemo1";
-static const char *ReflectVertFile = "reflect.vert.txt";
-static const char *CubeFragFile = "cubemap.frag.txt";
+static const char *ReflectVertFile = "reflect.vert";
+static const char *CubeFragFile = "cubemap.frag";
-static const char *SimpleVertFile = "simple.vert.txt";
-static const char *SimpleTexFragFile = "shadowtex.frag.txt";
+static const char *SimpleVertFile = "simple.vert";
+static const char *SimpleTexFragFile = "shadowtex.frag";
static const char *GroundImage = "../images/tile.rgb";
diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c
index b870435f66..2daaedd6df 100644
--- a/progs/glsl/toyball.c
+++ b/progs/glsl/toyball.c
@@ -16,8 +16,8 @@
#include "shaderutil.h"
-static char *FragProgFile = "CH11-toyball.frag.txt";
-static char *VertProgFile = "CH11-toyball.vert.txt";
+static char *FragProgFile = "CH11-toyball.frag";
+static char *VertProgFile = "CH11-toyball.vert";
/* program/shader objects */
static GLuint fragShader;
diff --git a/progs/glsl/trirast.c b/progs/glsl/trirast.c
index 67cbac0546..89df64fc71 100644
--- a/progs/glsl/trirast.c
+++ b/progs/glsl/trirast.c
@@ -190,7 +190,7 @@ Init(void)
"}\n";
static const char *vertShaderText =
"void main() {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+ " gl_Position = ftransform(); \n"
"}\n";
if (!ShadersSupported())
diff --git a/progs/glsl/twoside.c b/progs/glsl/twoside.c
index 77977be536..672a00491e 100644
--- a/progs/glsl/twoside.c
+++ b/progs/glsl/twoside.c
@@ -28,7 +28,7 @@ static GLuint program;
static GLint win = 0;
static GLboolean anim = 0*GL_TRUE;
static GLboolean DetermineInFragProg = GL_TRUE;
-static GLfloat Yrot = 0.0f;
+static GLfloat Xrot = 30.0f;
static GLint u_fragface;
static GLenum FrontWinding = GL_CCW;
static int prevTime = 0;
@@ -41,7 +41,8 @@ static const GLfloat Green[4] = {0, 1, 0, 0};
static void
Redisplay(void)
{
- float xmin = -1, xmax = 1, ymin = -1, ymax = 1;
+ int i;
+ float radius = 2;
glFrontFace(FrontWinding);
@@ -54,18 +55,22 @@ Redisplay(void)
glEnable(GL_VERTEX_PROGRAM_TWO_SIDE);
}
- glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
- glRotatef(Yrot, 0, 1, 0);
+ glRotatef(Xrot, 1, 0, 0);
- glBegin(GL_POLYGON);
+ /* Draw a tristrip ring */
+ glBegin(GL_TRIANGLE_STRIP);
glColor4fv(Red);
glSecondaryColor3fv_func(Green);
- glVertex2f(xmin, ymin);
- glVertex2f(xmax, ymin);
- glVertex2f(xmax, ymax);
- glVertex2f(xmin, ymax);
+ for (i = 0; i < 20; i++) {
+ float a = i / 19.0 * M_PI * 2.0;
+ float x = radius * cos(a);
+ float y = radius * sin(a);
+ glVertex3f(x, -1, y);
+ glVertex3f(x, +1, y);
+ }
glEnd();
glPopMatrix();
@@ -86,7 +91,7 @@ Idle(void)
}
prevTime = curTime;
- Yrot += dt * 0.1;
+ Xrot += dt * 0.1;
glutPostRedisplay();
}
@@ -98,7 +103,7 @@ Reshape(int width, int height)
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glFrustum(-ar, ar, -1, 1, 5, 15);
+ glFrustum(-ar, ar, -1, 1, 3, 25);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -10);
@@ -141,12 +146,16 @@ Key(unsigned char key, int x, int y)
DetermineInFragProg = GL_FALSE;
break;
case 'r':
- Yrot = 0;
+ /* reset */
+ Xrot = 30;
anim = 0;
glutIdleFunc(NULL);
break;
case 's':
- Yrot += 5;
+ Xrot += 5;
+ break;
+ case 'S':
+ Xrot -= 5;
break;
case 'w':
if (FrontWinding == GL_CCW) {
@@ -173,12 +182,24 @@ Init(void)
static const char *fragShaderText =
"uniform bool fragface; \n"
"void main() { \n"
+#if 0
" if (!fragface || gl_FrontFacing) { \n"
" gl_FragColor = gl_Color; \n"
" } \n"
" else { \n"
" gl_FragColor = 0.8 * gl_SecondaryColor; \n"
" } \n"
+#else
+ " bool f = gl_FrontFacing; \n"
+ " if (f) { \n"
+ " gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0); \n"
+ " } \n"
+ " else { \n"
+ " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0); \n"
+ " } \n"
+ " //float g = float(gl_FrontFacing) * 0.5 + 0.5; \n"
+ " //gl_FragColor = vec4(g); \n"
+#endif
"} \n";
static const char *vertShaderText =
"uniform bool fragface; \n"
@@ -218,6 +239,8 @@ Init(void)
assert(glIsProgram_func(program));
assert(glIsShader_func(fragShader));
assert(glIsShader_func(vertShader));
+
+ glEnable(GL_DEPTH_TEST);
}
@@ -246,6 +269,7 @@ Usage(void)
printf(" a - toggle animation\n");
printf(" s - step rotation\n");
printf(" w - toggle CW, CCW front-face winding\n");
+ printf("NOTE: red = front face, green = back face.\n");
}
@@ -255,7 +279,7 @@ main(int argc, char *argv[])
glutInit(&argc, argv);
glutInitWindowPosition( 0, 0);
glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
glutKeyboardFunc(Key);