summaryrefslogtreecommitdiff
path: root/progs/glsl
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-05-21 09:32:38 -0700
committerEric Anholt <eric@anholt.net>2010-05-21 12:20:39 -0700
commit68fc4b415e322f6744299e39864fbc377c6eff74 (patch)
tree4bafffd8b0105174f3c5c0ae327a005be9145990 /progs/glsl
parente4f4489e3fc0b36d72821b55794fb843b2b7fa5f (diff)
Remove demos that have moved to git+ssh://git.freedesktop.org/git/mesa/demos.
The remaining programs are ones I've had difficulty finding a build environment for to make the build system or are unit tests that should probably live next to their code instead. Hopefully people can bring over the build for remaining pieces they care about.
Diffstat (limited to 'progs/glsl')
-rw-r--r--progs/glsl/.gitignore35
-rw-r--r--progs/glsl/CH06-brick.frag36
-rw-r--r--progs/glsl/CH06-brick.vert41
-rw-r--r--progs/glsl/CH11-bumpmap.frag41
-rw-r--r--progs/glsl/CH11-bumpmap.vert38
-rw-r--r--progs/glsl/CH11-bumpmaptex.frag47
-rw-r--r--progs/glsl/CH11-toyball.frag75
-rw-r--r--progs/glsl/CH11-toyball.vert24
-rw-r--r--progs/glsl/CH18-mandel.frag55
-rw-r--r--progs/glsl/CH18-mandel.vert35
-rw-r--r--progs/glsl/Makefile104
-rw-r--r--progs/glsl/SConscript39
-rw-r--r--progs/glsl/array.c258
-rw-r--r--progs/glsl/bitmap.c320
-rw-r--r--progs/glsl/brick.c200
-rw-r--r--progs/glsl/brick.shtest8
-rw-r--r--progs/glsl/bump.c347
-rw-r--r--progs/glsl/convolution.frag21
-rw-r--r--progs/glsl/convolution.vert5
-rw-r--r--progs/glsl/convolutions.c470
-rw-r--r--progs/glsl/cubemap.frag18
-rw-r--r--progs/glsl/deriv.c249
-rw-r--r--progs/glsl/fragcoord.c181
-rw-r--r--progs/glsl/fsraytrace.c412
-rw-r--r--progs/glsl/identity.c204
-rw-r--r--progs/glsl/linktest.c255
-rw-r--r--progs/glsl/mandelbrot.c215
-rw-r--r--progs/glsl/mandelbrot.shtest13
-rw-r--r--progs/glsl/multinoise.c278
-rw-r--r--progs/glsl/multitex.c412
-rw-r--r--progs/glsl/multitex.frag15
-rw-r--r--progs/glsl/multitex.shtest6
-rw-r--r--progs/glsl/multitex.vert14
-rw-r--r--progs/glsl/noise.c216
-rw-r--r--progs/glsl/noise2.c200
-rw-r--r--progs/glsl/pointcoord.c201
-rw-r--r--progs/glsl/points.c257
-rw-r--r--progs/glsl/reflect.vert20
-rw-r--r--progs/glsl/samplers.c375
-rw-r--r--progs/glsl/shadow_sampler.c337
-rw-r--r--progs/glsl/shadowtex.frag21
-rw-r--r--progs/glsl/shtest.c711
-rw-r--r--progs/glsl/simple.vert9
-rw-r--r--progs/glsl/skinning.c280
-rw-r--r--progs/glsl/skinning.frag6
-rw-r--r--progs/glsl/skinning.vert24
-rw-r--r--progs/glsl/texaaline.c372
-rw-r--r--progs/glsl/texdemo1.c438
-rw-r--r--progs/glsl/toyball.c221
-rw-r--r--progs/glsl/toyball.shtest17
-rw-r--r--progs/glsl/trirast.c255
-rw-r--r--progs/glsl/twoside.c305
-rw-r--r--progs/glsl/vert-or-frag-only.c187
-rw-r--r--progs/glsl/vert-tex.c267
-rw-r--r--progs/glsl/vsraytrace.c401
55 files changed, 0 insertions, 9591 deletions
diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore
deleted file mode 100644
index 9d403ec6d6..0000000000
--- a/progs/glsl/.gitignore
+++ /dev/null
@@ -1,35 +0,0 @@
-array
-bitmap
-brick
-bump
-convolutions
-deriv
-extfuncs.h
-fragcoord
-fsraytrace
-identity
-linktest
-mandelbrot
-multinoise
-multitex
-noise
-noise2
-pointcoord
-points
-readtex.c
-readtex.h
-samplers
-samplers_array
-shaderutil.c
-shaderutil.h
-shadow_sampler
-shtest
-skinning
-texaaline
-texdemo1
-toyball
-trirast
-twoside
-vert-or-frag-only
-vert-tex
-vsraytrace
diff --git a/progs/glsl/CH06-brick.frag b/progs/glsl/CH06-brick.frag
deleted file mode 100644
index 06ef04e3af..0000000000
--- a/progs/glsl/CH06-brick.frag
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// Fragment shader for procedural bricks
-//
-// Authors: Dave Baldwin, Steve Koren, Randi Rost
-// based on a shader by Darwyn Peachey
-//
-// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
-//
-// See 3Dlabs-License.txt for license information
-//
-
-uniform vec3 BrickColor, MortarColor;
-uniform vec2 BrickSize;
-uniform vec2 BrickPct;
-
-varying vec2 MCposition;
-varying float LightIntensity;
-
-void main()
-{
- vec3 color;
- vec2 position, useBrick;
-
- position = MCposition / BrickSize;
-
- if (fract(position.y * 0.5) > 0.5)
- position.x += 0.5;
-
- position = fract(position);
-
- useBrick = step(position, BrickPct);
-
- color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y);
- color *= LightIntensity;
- gl_FragColor = vec4(color, 1.0);
-}
diff --git a/progs/glsl/CH06-brick.vert b/progs/glsl/CH06-brick.vert
deleted file mode 100644
index e95e6f42f0..0000000000
--- a/progs/glsl/CH06-brick.vert
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Vertex shader for procedural bricks
-//
-// Authors: Dave Baldwin, Steve Koren, Randi Rost
-// based on a shader by Darwyn Peachey
-//
-// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
-//
-// See 3Dlabs-License.txt for license information
-//
-
-uniform vec3 LightPosition;
-
-const float SpecularContribution = 0.3;
-const float DiffuseContribution = 1.0 - SpecularContribution;
-
-varying float LightIntensity;
-varying vec2 MCposition;
-
-void main()
-{
- vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
- vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
- vec3 lightVec = normalize(LightPosition - ecPosition);
- vec3 reflectVec = reflect(-lightVec, tnorm);
- vec3 viewVec = normalize(-ecPosition);
- float diffuse = max(dot(lightVec, tnorm), 0.0);
- float spec = 0.0;
-
- if (diffuse > 0.0)
- {
- spec = max(dot(reflectVec, viewVec), 0.0);
- spec = pow(spec, 16.0);
- }
-
- LightIntensity = DiffuseContribution * diffuse +
- SpecularContribution * spec;
-
- MCposition = gl_Vertex.xy;
- gl_Position = ftransform();
-}
diff --git a/progs/glsl/CH11-bumpmap.frag b/progs/glsl/CH11-bumpmap.frag
deleted file mode 100644
index e12c5d374c..0000000000
--- a/progs/glsl/CH11-bumpmap.frag
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// Fragment shader for procedural bumps
-//
-// Authors: John Kessenich, Randi Rost
-//
-// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
-//
-// See 3Dlabs-License.txt for license information
-//
-
-varying vec3 LightDir;
-varying vec3 EyeDir;
-
-uniform vec3 SurfaceColor; // = (0.7, 0.6, 0.18)
-uniform float BumpDensity; // = 16.0
-uniform float BumpSize; // = 0.15
-uniform float SpecularFactor; // = 0.5
-
-void main()
-{
- vec3 litColor;
- vec2 c = BumpDensity * gl_TexCoord[0].st;
- vec2 p = fract(c) - vec2(0.5);
-
- float d, f;
- d = p.x * p.x + p.y * p.y;
- f = inversesqrt(d + 1.0);
-
- if (d >= BumpSize)
- { p = vec2(0.0); f = 1.0; }
-
- vec3 normDelta = vec3(p.x, p.y, 1.0) * f;
- litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0);
- vec3 reflectDir = reflect(LightDir, normDelta);
-
- float spec = max(dot(EyeDir, reflectDir), 0.0);
- spec *= SpecularFactor;
- litColor = min(litColor + spec, vec3(1.0));
-
- gl_FragColor = vec4(litColor, 1.0);
-}
diff --git a/progs/glsl/CH11-bumpmap.vert b/progs/glsl/CH11-bumpmap.vert
deleted file mode 100644
index d3d19f62ac..0000000000
--- a/progs/glsl/CH11-bumpmap.vert
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Vertex shader for procedural bumps
-//
-// Authors: Randi Rost, John Kessenich
-//
-// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
-//
-// See 3Dlabs-License.txt for license information
-//
-
-varying vec3 LightDir;
-varying vec3 EyeDir;
-
-uniform vec3 LightPosition;
-
-attribute vec3 Tangent;
-
-void main()
-{
- EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex);
- gl_Position = ftransform();
- gl_TexCoord[0] = gl_MultiTexCoord0;
-
- vec3 n = normalize(gl_NormalMatrix * gl_Normal);
- vec3 t = normalize(gl_NormalMatrix * Tangent);
- vec3 b = cross(n, t);
-
- vec3 v;
- v.x = dot(LightPosition, t);
- v.y = dot(LightPosition, b);
- v.z = dot(LightPosition, n);
- LightDir = normalize(v);
-
- v.x = dot(EyeDir, t);
- v.y = dot(EyeDir, b);
- v.z = dot(EyeDir, n);
- EyeDir = normalize(v);
-}
diff --git a/progs/glsl/CH11-bumpmaptex.frag b/progs/glsl/CH11-bumpmaptex.frag
deleted file mode 100644
index b5dabb4c8a..0000000000
--- a/progs/glsl/CH11-bumpmaptex.frag
+++ /dev/null
@@ -1,47 +0,0 @@
-//
-// Fragment shader for procedural bumps
-//
-// Authors: John Kessenich, Randi Rost
-//
-// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
-//
-// See 3Dlabs-License.txt for license information
-//
-// Texture mapping/modulation added by Brian Paul
-//
-
-varying vec3 LightDir;
-varying vec3 EyeDir;
-
-uniform float BumpDensity; // = 16.0
-uniform float BumpSize; // = 0.15
-uniform float SpecularFactor; // = 0.5
-
-uniform sampler2D Tex;
-
-void main()
-{
- vec3 ambient = vec3(0.25);
- vec3 litColor;
- vec2 c = BumpDensity * gl_TexCoord[0].st;
- vec2 p = fract(c) - vec2(0.5);
-
- float d, f;
- d = p.x * p.x + p.y * p.y;
- f = inversesqrt(d + 1.0);
-
- if (d >= BumpSize)
- { p = vec2(0.0); f = 1.0; }
-
- vec3 SurfaceColor = texture2D(Tex, gl_TexCoord[0].st).xyz;
-
- vec3 normDelta = vec3(p.x, p.y, 1.0) * f;
- litColor = SurfaceColor * (ambient + max(dot(normDelta, LightDir), 0.0));
- vec3 reflectDir = reflect(LightDir, normDelta);
-
- float spec = max(dot(EyeDir, reflectDir), 0.0);
- spec *= SpecularFactor;
- litColor = min(litColor + spec, vec3(1.0));
-
- gl_FragColor = vec4(litColor, 1.0);
-}
diff --git a/progs/glsl/CH11-toyball.frag b/progs/glsl/CH11-toyball.frag
deleted file mode 100644
index 90ec1c27fc..0000000000
--- a/progs/glsl/CH11-toyball.frag
+++ /dev/null
@@ -1,75 +0,0 @@
-//
-// Fragment shader for procedurally generated toy ball
-//
-// Author: Bill Licea-Kane
-//
-// Copyright (c) 2002-2003 ATI Research
-//
-// See ATI-License.txt for license information
-//
-
-varying vec4 ECposition; // surface position in eye coordinates
-varying vec4 ECballCenter; // ball center in eye coordinates
-
-uniform vec4 LightDir; // light direction, should be normalized
-uniform vec4 HVector; // reflection vector for infinite light source
-uniform vec4 SpecularColor;
-uniform vec4 Red, Yellow, Blue;
-
-uniform vec4 HalfSpace0; // half-spaces used to define star pattern
-uniform vec4 HalfSpace1;
-uniform vec4 HalfSpace2;
-uniform vec4 HalfSpace3;
-uniform vec4 HalfSpace4;
-
-uniform float InOrOutInit; // = -3
-uniform float StripeWidth; // = 0.3
-uniform float FWidth; // = 0.005
-
-void main()
-{
- vec4 normal; // Analytically computed normal
- vec4 p; // Point in shader space
- vec4 surfColor; // Computed color of the surface
- float intensity; // Computed light intensity
- vec4 distance; // Computed distance values
- float inorout; // Counter for computing star pattern
-
- p.xyz = normalize(ECposition.xyz - ECballCenter.xyz); // Calculate p
- p.w = 1.0;
-
- inorout = InOrOutInit; // initialize inorout to -3
-
- distance[0] = dot(p, HalfSpace0);
- distance[1] = dot(p, HalfSpace1);
- distance[2] = dot(p, HalfSpace2);
- distance[3] = dot(p, HalfSpace3);
-
- distance = smoothstep(-FWidth, FWidth, distance);
- inorout += dot(distance, vec4(1.0));
-
- distance.x = dot(p, HalfSpace4);
- distance.y = StripeWidth - abs(p.z);
- distance = smoothstep(-FWidth, FWidth, distance);
- inorout += distance.x;
-
- inorout = clamp(inorout, 0.0, 1.0);
-
- surfColor = mix(Yellow, Red, inorout);
- surfColor = mix(surfColor, Blue, distance.y);
-
- // normal = point on surface for sphere at (0,0,0)
- normal = p;
-
- // Per fragment diffuse lighting
- intensity = 0.2; // ambient
- intensity += 0.8 * clamp(dot(LightDir, normal), 0.0, 1.0);
- surfColor *= intensity;
-
- // Per fragment specular lighting
- intensity = clamp(dot(HVector, normal), 0.0, 1.0);
- intensity = pow(intensity, SpecularColor.a);
- surfColor += SpecularColor * intensity;
-
- gl_FragColor = surfColor;
-}
diff --git a/progs/glsl/CH11-toyball.vert b/progs/glsl/CH11-toyball.vert
deleted file mode 100644
index b7da3ac839..0000000000
--- a/progs/glsl/CH11-toyball.vert
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Fragment shader for procedurally generated toy ball
-//
-// Author: Bill Licea-Kane
-//
-// Copyright (c) 2002-2003 ATI Research
-//
-// See ATI-License.txt for license information
-//
-
-varying vec4 ECposition; // surface position in eye coordinates
-varying vec4 ECballCenter; // ball center in eye coordinates
-uniform vec4 BallCenter; // ball center in modelling coordinates
-
-void main()
-{
-//orig: ECposition = gl_ModelViewMatrix * gl_Vertex;
-
- ECposition = gl_TextureMatrix[0] * gl_Vertex;
- ECposition = gl_ModelViewMatrix * ECposition;
-
- ECballCenter = gl_ModelViewMatrix * BallCenter;
- gl_Position = ftransform();
-}
diff --git a/progs/glsl/CH18-mandel.frag b/progs/glsl/CH18-mandel.frag
deleted file mode 100644
index a972d68bcf..0000000000
--- a/progs/glsl/CH18-mandel.frag
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// Fragment shader for drawing the Mandelbrot set
-//
-// Authors: Dave Baldwin, Steve Koren, Randi Rost
-// based on a shader by Michael Rivero
-//
-// Copyright (c) 2002-2005: 3Dlabs, Inc.
-//
-// See 3Dlabs-License.txt for license information
-//
-
-varying vec3 Position;
-varying float LightIntensity;
-
-uniform float MaxIterations;
-uniform float Zoom;
-uniform float Xcenter;
-uniform float Ycenter;
-uniform vec3 InnerColor;
-uniform vec3 OuterColor1;
-uniform vec3 OuterColor2;
-
-void main()
-{
- float real = Position.x * Zoom + Xcenter;
- float imag = Position.y * Zoom + Ycenter;
- float Creal = real; // Change this line...
- float Cimag = imag; // ...and this one to get a Julia set
-
- float r2 = 0.0;
- float iter;
-
-// for (iter = 0.0; iter < MaxIterations && r2 < 4.0; ++iter)
- for (iter = 0.0; iter < 12.0 && r2 < 4.0; ++iter)
- {
- float tempreal = real;
-
- real = (tempreal * tempreal) - (imag * imag) + Creal;
- imag = 2.0 * tempreal * imag + Cimag;
- r2 = (real * real) + (imag * imag);
- }
-
- // Base the color on the number of iterations
-
- vec3 color;
-
- if (r2 < 4.0)
- color = InnerColor;
- else
- color = mix(OuterColor1, OuterColor2, fract(iter * 0.05));
-
- color *= LightIntensity;
-
- gl_FragColor = vec4(color, 1.0);
-}
diff --git a/progs/glsl/CH18-mandel.vert b/progs/glsl/CH18-mandel.vert
deleted file mode 100644
index c4ca66405d..0000000000
--- a/progs/glsl/CH18-mandel.vert
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Vertex shader for drawing the Mandelbrot set
-//
-// Authors: Dave Baldwin, Steve Koren, Randi Rost
-// based on a shader by Michael Rivero
-//
-// Copyright (c) 2002-2005: 3Dlabs, Inc.
-//
-// See 3Dlabs-License.txt for license information
-//
-
-uniform vec3 LightPosition;
-uniform float SpecularContribution;
-uniform float DiffuseContribution;
-uniform float Shininess;
-
-varying float LightIntensity;
-varying vec3 Position;
-
-void main()
-{
- vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
- vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
- vec3 lightVec = normalize(LightPosition - ecPosition);
- vec3 reflectVec = reflect(-lightVec, tnorm);
- vec3 viewVec = normalize(-ecPosition);
- float spec = max(dot(reflectVec, viewVec), 0.0);
- spec = pow(spec, Shininess);
- LightIntensity = DiffuseContribution *
- max(dot(lightVec, tnorm), 0.0) +
- SpecularContribution * spec;
- Position = vec3(gl_MultiTexCoord0 - 0.5) * 5.0;
- gl_Position = ftransform();
-
-} \ No newline at end of file
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
deleted file mode 100644
index 6030c8002f..0000000000
--- a/progs/glsl/Makefile
+++ /dev/null
@@ -1,104 +0,0 @@
-# progs/demos/Makefile
-
-TOP = ../..
-include $(TOP)/configs/current
-
-INCDIR = $(TOP)/include
-
-LIB_DEP = \
- $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) \
- $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) \
- $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME)
-
-LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) \
- -l$(GL_LIB) $(APP_LIB_DEPS)
-
-# using : to avoid APP_CC pointing to CC loop
-CC := $(APP_CC)
-CFLAGS := -I$(INCDIR) $(CFLAGS)
-LDLIBS = $(LIBS)
-
-PROG_SOURCES = \
- array.c \
- bitmap.c \
- brick.c \
- bump.c \
- convolutions.c \
- deriv.c \
- fragcoord.c \
- fsraytrace.c \
- identity.c \
- linktest.c \
- mandelbrot.c \
- multinoise.c \
- multitex.c \
- noise.c \
- noise2.c \
- pointcoord.c \
- points.c \
- samplers.c \
- samplers_array.c \
- shadow_sampler.c \
- shtest.c \
- skinning.c \
- texaaline.c \
- texdemo1.c \
- toyball.c \
- trirast.c \
- twoside.c \
- vert-or-frag-only.c \
- vert-tex.c \
- vsraytrace.c
-
-UTIL_HEADERS = \
- extfuncs.h \
- shaderutil.h \
- readtex.h
-
-UTIL_SOURCES = \
- shaderutil.c \
- readtex.c
-
-UTIL_OBJS = $(UTIL_SOURCES:.c=.o)
-PROG_OBJS = $(PROG_SOURCES:.c=.o)
-PROGS = $(PROG_SOURCES:%.c=%)
-
-##### TARGETS #####
-
-default: $(PROGS)
-
-$(PROG_OBJS): $(UTIL_HEADERS)
-
-$(PROGS): $(UTIL_OBJS)
-
-.o:
- $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
-
-clean:
- -rm -f $(PROGS)
- -rm -f *.o *~
- -rm -f extfuncs.h
- -rm -f shaderutil.*
- -rm -f readtex.*
-
-
-##### Extra dependencies
-
-samplers_array.o: samplers.c
- $(APP_CC) $(CFLAGS) -DSAMPLERS_ARRAY $< -c -o $@
-
-extfuncs.h: $(TOP)/progs/util/extfuncs.h
- cp $< .
-
-readtex.c: $(TOP)/progs/util/readtex.c
- cp $< .
-
-readtex.h: $(TOP)/progs/util/readtex.h
- cp $< .
-
-shaderutil.c: $(TOP)/progs/util/shaderutil.c
- cp $< .
-
-shaderutil.h: $(TOP)/progs/util/shaderutil.h
- cp $< .
-
diff --git a/progs/glsl/SConscript b/progs/glsl/SConscript
deleted file mode 100644
index 02884e5a71..0000000000
--- a/progs/glsl/SConscript
+++ /dev/null
@@ -1,39 +0,0 @@
-Import('*')
-
-progs = [
- 'array',
- 'bitmap',
- 'brick',
- 'bump',
- 'convolutions',
- 'deriv',
- 'fragcoord',
- 'fsraytrace',
- 'identity',
- 'linktest',
- 'mandelbrot',
- 'multinoise',
- 'multitex',
- 'noise',
- 'noise2',
- 'pointcoord',
- 'points',
- 'samplers',
- 'shadow_sampler',
- 'skinning',
- 'texaaline',
- 'texdemo1',
- 'toyball',
- 'trirast',
- 'twoside',
- 'vert-or-frag-only',
- 'vert-tex',
- 'vsraytrace',
-]
-
-for prog in progs:
- progs_env.Program(
- target = prog,
- source = prog + '.c',
- )
-
diff --git a/progs/glsl/array.c b/progs/glsl/array.c
deleted file mode 100644
index 4ed18485ea..0000000000
--- a/progs/glsl/array.c
+++ /dev/null
@@ -1,258 +0,0 @@
-/**
- * Test variable array indexing in a vertex shader.
- * Brian Paul
- * 17 April 2009
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-/**
- * The vertex position.z is used as a (variable) index into an
- * array which returns a new Z value.
- */
-static const char *VertShaderText =
- "uniform sampler2D tex1; \n"
- "uniform float HeightArray[20]; \n"
- "void main() \n"
- "{ \n"
- " vec4 pos = gl_Vertex; \n"
- " int i = int(pos.z * 9.5); \n"
- " pos.z = HeightArray[i]; \n"
- " gl_Position = gl_ModelViewProjectionMatrix * pos; \n"
- " gl_FrontColor = pos; \n"
- "} \n";
-
-static const char *FragShaderText =
- "void main() \n"
- "{ \n"
- " gl_FragColor = gl_Color; \n"
- "} \n";
-
-
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-static GLint win = 0;
-static GLboolean Anim = GL_TRUE;
-static GLboolean WireFrame = GL_TRUE;
-static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f;
-
-
-static void
-Idle(void)
-{
- zRot = 90 + glutGet(GLUT_ELAPSED_TIME) * 0.05;
- glutPostRedisplay();
-}
-
-
-/** z=f(x,y) */
-static float
-fz(float x, float y)
-{
- return fabs(cos(1.5*x) + cos(1.5*y));
-}
-
-
-static void
-DrawMesh(void)
-{
- GLfloat xmin = -2.0, xmax = 2.0;
- GLfloat ymin = -2.0, ymax = 2.0;
- GLuint xdivs = 20, ydivs = 20;
- GLfloat dx = (xmax - xmin) / xdivs;
- GLfloat dy = (ymax - ymin) / ydivs;
- GLfloat ds = 1.0 / xdivs, dt = 1.0 / ydivs;
- GLfloat x, y, s, t;
- GLuint i, j;
-
- y = ymin;
- t = 0.0;
- for (i = 0; i < ydivs; i++) {
- x = xmin;
- s = 0.0;
- glBegin(GL_QUAD_STRIP);
- for (j = 0; j < xdivs; j++) {
- float z0 = fz(x, y), z1 = fz(x, y + dy);
-
- glTexCoord2f(s, t);
- glVertex3f(x, y, z0);
-
- glTexCoord2f(s, t + dt);
- glVertex3f(x, y + dy, z1);
- x += dx;
- s += ds;
- }
- glEnd();
- y += dy;
- t += dt;
- }
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- if (WireFrame)
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glPushMatrix();
- DrawMesh();
- glPopMatrix();
-
- glPopMatrix();
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 2.0;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(Idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'w':
- WireFrame = !WireFrame;
- break;
- case 'z':
- zRot += step;
- break;
- case 'Z':
- zRot -= step;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 2.0;
-
- (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)
-{
- GLfloat HeightArray[20];
- GLint u, i;
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, VertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- /* Setup the HeightArray[] uniform */
- for (i = 0; i < 20; i++)
- HeightArray[i] = i / 20.0;
- u = glGetUniformLocation(program, "HeightArray");
- glUniform1fv(u, 20, HeightArray);
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
- glEnable(GL_DEPTH_TEST);
- glColor3f(1, 1, 1);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(500, 500);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- Init();
- if (Anim)
- glutIdleFunc(Idle);
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/bitmap.c b/progs/glsl/bitmap.c
deleted file mode 100644
index 8b1853d9ab..0000000000
--- a/progs/glsl/bitmap.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/**
- * Implement glRasterPos + glBitmap with textures + shaders.
- * Brian Paul
- * 14 May 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static GLuint FragShader;
-static GLuint VertShader;
-static GLuint Program;
-
-static GLint Win = 0;
-static GLint WinWidth = 500, WinHeight = 500;
-static GLboolean Anim = GL_TRUE;
-static GLboolean Bitmap = GL_FALSE;
-static GLfloat Xrot = 20.0f, Yrot = 70.0f;
-static GLint uTex, uScale;
-static GLuint Textures[2];
-
-#define TEX_WIDTH 16
-#define TEX_HEIGHT 8
-
-
-static void
-BitmapText(const char *s)
-{
- while (*s) {
- glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
- s++;
- }
-}
-
-
-static void
-Redisplay(void)
-{
- static const GLfloat px[3] = { 1.2, 0, 0};
- static const GLfloat nx[3] = {-1.2, 0, 0};
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(Xrot, 1.0f, 0.0f, 0.0f);
- glRotatef(Yrot, 0.0f, 1.0f, 0.0f);
-
- glEnable(GL_LIGHTING);
-
- glPushMatrix();
- glScalef(0.5, 0.5, 0.5);
- glutSolidDodecahedron();
- glPopMatrix();
-
- glDisable(GL_LIGHTING);
-
- glColor3f(0, 1, 0);
- glBegin(GL_LINES);
- glVertex3f(-1, 0, 0);
- glVertex3f( 1, 0, 0);
- glEnd();
-
- glColor3f(1, 1, 0);
-
- if (Bitmap) {
- glRasterPos3fv(px);
- BitmapText("+X");
- glRasterPos3fv(nx);
- BitmapText("-X");
- }
- else {
- glUseProgram(Program);
-
- /* vertex positions (deltas) depend on texture size and window size */
- if (uScale != -1) {
- glUniform2f(uScale,
- 2.0 * TEX_WIDTH / WinWidth,
- 2.0 * TEX_HEIGHT / WinHeight);
- }
-
- /* draw +X */
- glBindTexture(GL_TEXTURE_2D, Textures[0]);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex3fv(px);
- glTexCoord2f(1, 0); glVertex3fv(px);
- glTexCoord2f(1, 1); glVertex3fv(px);
- glTexCoord2f(0, 1); glVertex3fv(px);
- glEnd();
-
- /* draw -X */
- glBindTexture(GL_TEXTURE_2D, Textures[1]);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex3fv(nx);
- glTexCoord2f(1, 0); glVertex3fv(nx);
- glTexCoord2f(1, 1); glVertex3fv(nx);
- glTexCoord2f(0, 1); glVertex3fv(nx);
- glEnd();
-
- glUseProgram(0);
- }
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Idle(void)
-{
- Yrot = glutGet(GLUT_ELAPSED_TIME) * 0.01;
- glutPostRedisplay();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- WinWidth = width;
- WinHeight = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -10.0f);
-}
-
-
-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 'b':
- Bitmap = !Bitmap;
- if (Bitmap)
- printf("Using glBitmap\n");
- else
- printf("Using billboard texture\n");
- break;
- case 27:
- glDeleteShader(FragShader);
- glDeleteShader(VertShader);
- glDeleteProgram(Program);
- glutDestroyWindow(Win);
- exit(0);
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 0.125f;
- 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;
- }
- /*printf("Xrot: %f Yrot: %f\n", Xrot, Yrot);*/
- glutPostRedisplay();
-}
-
-
-static void
-MakeTexImage(const char *p, GLuint texobj)
-{
- GLubyte image[TEX_HEIGHT][TEX_WIDTH];
- GLuint i, j, k;
-
- for (i = 0; i < TEX_HEIGHT; i++) {
- for (j = 0; j < TEX_WIDTH; j++) {
- k = i * TEX_WIDTH + j;
- if (p[k] == ' ') {
- image[i][j] = 0;
- }
- else {
- image[i][j] = 255;
- }
- }
- }
-
- glBindTexture(GL_TEXTURE_2D, texobj);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, TEX_WIDTH, TEX_HEIGHT, 0,
- GL_RED, GL_UNSIGNED_BYTE, image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-}
-
-
-static void
-MakeBitmapTextures(void)
-{
- const char *px =
- " X X "
- " X X X "
- " X X X "
- " XXXXX X "
- " X X X "
- " X X X "
- " X X "
- " X X ";
- const char *nx =
- " X X "
- " X X "
- " X X "
- " XXXXX X "
- " X X "
- " X X "
- " X X "
- " X X ";
- glGenTextures(2, Textures);
- MakeTexImage(px, Textures[0]);
- MakeTexImage(nx, Textures[1]);
-}
-
-
-static void
-Init(void)
-{
- /* Fragment shader: modulate raster color by texture, discard fragments
- * with alpha < 1.0
- */
- static const char *fragShaderText =
- "uniform sampler2D tex2d; \n"
- "void main() {\n"
- " vec4 c = texture2D(tex2d, gl_TexCoord[0].xy); \n"
- " if (c.w < 1.0) \n"
- " discard; \n"
- " gl_FragColor = c * gl_Color; \n"
- "}\n";
- /* Vertex shader: compute new vertex position based on incoming vertex pos,
- * texcoords and special scale factor.
- */
- static const char *vertShaderText =
- "uniform vec2 scale; \n"
- "void main() {\n"
- " vec4 p = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_Position.xy = p.xy + gl_MultiTexCoord0.xy * scale * p.w; \n"
- " gl_Position.zw = p.zw; \n"
- " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
- " gl_FrontColor = gl_Color; \n"
- "}\n";
-
- if (!ShadersSupported())
- exit(1);
-
- VertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- FragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- Program = LinkShaders(VertShader, FragShader);
-
- glUseProgram(Program);
-
- uScale = glGetUniformLocation(Program, "scale");
- uTex = glGetUniformLocation(Program, "tex2d");
- if (uTex != -1) {
- glUniform1i(uTex, 0); /* tex unit 0 */
- }
-
- glUseProgram(0);
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_NORMALIZE);
- glEnable(GL_LIGHT0);
-
- MakeBitmapTextures();
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- Win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- if (Anim)
- glutIdleFunc(Idle);
- Init();
- glutMainLoop();
- return 0;
-}
-
-
diff --git a/progs/glsl/brick.c b/progs/glsl/brick.c
deleted file mode 100644
index 20417aa462..0000000000
--- a/progs/glsl/brick.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/**
- * "Brick" shader demo. Uses the example shaders from chapter 6 of
- * the OpenGL Shading Language "orange" book.
- * 10 Jan 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static char *FragProgFile = "CH06-brick.frag";
-static char *VertProgFile = "CH06-brick.vert";
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-static struct uniform_info Uniforms[] = {
- /* vert */
- { "LightPosition", 1, GL_FLOAT_VEC3, { 0.1, 0.1, 9.0, 0}, -1 },
- /* frag */
- { "BrickColor", 1, GL_FLOAT_VEC3, { 0.8, 0.2, 0.2, 0 }, -1 },
- { "MortarColor", 1, GL_FLOAT_VEC3, { 0.6, 0.6, 0.6, 0 }, -1 },
- { "BrickSize", 1, GL_FLOAT_VEC2, { 1.0, 0.3, 0, 0 }, -1 },
- { "BrickPct", 1, GL_FLOAT_VEC2, { 0.9, 0.8, 0, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-static GLint win = 0;
-
-
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
-
-
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0); glVertex2f(-2, -2);
- glTexCoord2f(1, 0); glVertex2f( 2, -2);
- glTexCoord2f(1, 1); glVertex2f( 2, 2);
- glTexCoord2f(0, 1); glVertex2f(-2, 2);
- glEnd();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
-
- switch(key) {
- case 'z':
- zRot -= 1.0;
- break;
- case 'Z':
- zRot += 1.0;
- 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)
-{
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- SetUniformValues(program, Uniforms);
- PrintUniforms(Uniforms);
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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);
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/brick.shtest b/progs/glsl/brick.shtest
deleted file mode 100644
index 8a2152692e..0000000000
--- a/progs/glsl/brick.shtest
+++ /dev/null
@@ -1,8 +0,0 @@
-vs CH06-brick.vert
-fs CH06-brick.frag
-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/bump.c b/progs/glsl/bump.c
deleted file mode 100644
index 784596448c..0000000000
--- a/progs/glsl/bump.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/**
- * Procedural Bump Mapping demo. Uses the example shaders from
- * chapter 11 of the OpenGL Shading Language "orange" book.
- * 16 Jan 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-#include "readtex.h"
-
-
-static char *FragProgFile = "CH11-bumpmap.frag";
-static char *FragTexProgFile = "CH11-bumpmaptex.frag";
-static char *VertProgFile = "CH11-bumpmap.vert";
-static char *TextureFile = "../images/tile.rgb";
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint fragTexShader;
-static GLuint vertShader;
-static GLuint program;
-static GLuint texProgram;
-
-
-static struct uniform_info Uniforms[] = {
- { "LightPosition", 1, GL_FLOAT_VEC3, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 },
- { "SurfaceColor", 1, GL_FLOAT_VEC3, { 0.8, 0.8, 0.2, 0 }, -1 },
- { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 },
- { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 },
- { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-static struct uniform_info TexUniforms[] = {
- { "LightPosition", 1, GL_FLOAT_VEC3, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 },
- { "Tex", 1, GL_INT, { 0, 0, 0, 0 }, -1 },
- { "BumpDensity", 1, GL_FLOAT, { 10.0, 0, 0, 0 }, -1 },
- { "BumpSize", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 },
- { "SpecularFactor", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-static GLint win = 0;
-
-static GLfloat xRot = 20.0f, yRot = 0.0f, zRot = 0.0f;
-
-static GLint tangentAttrib;
-
-static GLuint Texture;
-
-static GLboolean Anim = GL_FALSE;
-static GLboolean Textured = GL_FALSE;
-
-
-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);
- }
-}
-
-/*
- * Draw a square, specifying normal and tangent vectors.
- */
-static void
-Square(GLfloat size)
-{
- glNormal3f(0, 0, 1);
- glVertexAttrib3f(tangentAttrib, 1, 0, 0);
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0); glVertex2f(-size, -size);
- glTexCoord2f(1, 0); glVertex2f( size, -size);
- glTexCoord2f(1, 1); glVertex2f( size, size);
- glTexCoord2f(0, 1); glVertex2f(-size, size);
- glEnd();
-}
-
-
-static void
-Cube(GLfloat size)
-{
- /* +X */
- glPushMatrix();
- glRotatef(90, 0, 1, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* -X */
- glPushMatrix();
- glRotatef(-90, 0, 1, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* +Y */
- glPushMatrix();
- glRotatef(90, 1, 0, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* -Y */
- glPushMatrix();
- glRotatef(-90, 1, 0, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
-
- /* +Z */
- glPushMatrix();
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* -Z */
- glPushMatrix();
- glRotatef(180, 0, 1, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
-}
-
-
-static void
-Idle(void)
-{
- GLint t = glutGet(GLUT_ELAPSED_TIME);
- yRot = t * 0.05;
- glutPostRedisplay();
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- if (Textured)
- glUseProgram(texProgram);
- else
- glUseProgram(program);
-
- Cube(1.5);
-
- glPopMatrix();
-
- CheckError(__LINE__);
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- float ar = (float) width / (float) height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(fragTexShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glDeleteProgram(texProgram);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 2.0;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- glutIdleFunc(Anim ? Idle : NULL);
- break;
- case 't':
- Textured = !Textured;
- break;
- case 'z':
- zRot += step;
- break;
- case 'Z':
- zRot -= step;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 2.0;
-
- (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)
-{
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(vertShader));
-
- assert(glGetError() == 0);
-
- CheckError(__LINE__);
-
- SetUniformValues(program, Uniforms);
- PrintUniforms(Uniforms);
-
- CheckError(__LINE__);
-
- tangentAttrib = glGetAttribLocation(program, "Tangent");
- printf("Tangent Attrib: %d\n", tangentAttrib);
-
- assert(tangentAttrib >= 0);
-
- CheckError(__LINE__);
-
-
- /*
- * As above, but fragment shader also uses a texture map.
- */
- fragTexShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragTexProgFile);
- texProgram = LinkShaders(vertShader, fragTexShader);
- glUseProgram(texProgram);
- assert(glIsProgram(texProgram));
- assert(glIsShader(fragTexShader));
- SetUniformValues(texProgram, TexUniforms);
- PrintUniforms(TexUniforms);
-
- /*
- * Load tex image.
- */
- glGenTextures(1, &Texture);
- glBindTexture(GL_TEXTURE_2D, Texture);
- LoadRGBMipmaps(TextureFile, GL_RGB);
-
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- glEnable(GL_DEPTH_TEST);
-
- 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];
- }
- else if (strcmp(argv[i], "-vs") == 0) {
- VertProgFile = argv[++i];
- }
- else if (strcmp(argv[i], "-t") == 0) {
- TextureFile = argv[++i];
- }
- }
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/convolution.frag b/progs/glsl/convolution.frag
deleted file mode 100644
index e49b8acf54..0000000000
--- a/progs/glsl/convolution.frag
+++ /dev/null
@@ -1,21 +0,0 @@
-
-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
deleted file mode 100644
index 752c54671c..0000000000
--- a/progs/glsl/convolution.vert
+++ /dev/null
@@ -1,5 +0,0 @@
-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
deleted file mode 100644
index fdfaf568a2..0000000000
--- a/progs/glsl/convolutions.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/**
- * 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
- */
-
-#include <GL/glew.h>
-
-#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;
-
- glShaderSource(shader, 1, (const GLchar **) &text, NULL);
-
- glCompileShader(shader);
-
- glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetShaderInfoLog(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;
- glGetProgramiv(prog, GL_LINK_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetProgramInfoLog(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 = 0.0;
- 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");
- glUniform4fv(loc, 9, vecKer);
- loc = glGetUniformLocationARB(program, "ScaleFactor");
- glUniform4f(loc, scale, scale, scale, scale);
- loc = glGetUniformLocationARB(program, "BaseColor");
- glUniform4f(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);
- }
-
- glLinkProgram(program);
- checkLink(program);
-
- glUseProgram(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");
- glUniform2fv(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:
- break;
- }
- 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();
-
- glutSwapBuffers();
-}
-
-int main(int argc, char **argv)
-{
- glutInit(&argc, argv);
-
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE);
-
- if (!glutCreateWindow("Image Convolutions")) {
- fprintf(stderr, "Couldn't create window!\n");
- exit(1);
- }
-
- glewInit();
- init();
-
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyPress);
- glutSpecialFunc(special);
- glutDisplayFunc(draw);
-
-
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/cubemap.frag b/progs/glsl/cubemap.frag
deleted file mode 100644
index 9c27648aaf..0000000000
--- a/progs/glsl/cubemap.frag
+++ /dev/null
@@ -1,18 +0,0 @@
-// Fragment shader for cube-texture reflection mapping
-// Brian Paul
-
-
-uniform samplerCube cubeTex;
-varying vec3 normal;
-uniform vec3 lightPos;
-
-void main()
-{
- // simple diffuse, specular lighting:
- vec3 lp = normalize(lightPos);
- float dp = dot(lp, normalize(normal));
- float spec = pow(dp, 5.0);
-
- // final color:
- gl_FragColor = dp * textureCube(cubeTex, gl_TexCoord[0].xyz, 0.0) + spec;
-}
diff --git a/progs/glsl/deriv.c b/progs/glsl/deriv.c
deleted file mode 100644
index 588246b71a..0000000000
--- a/progs/glsl/deriv.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * Test OpenGL 2.0 dx/dy functions for texcoords.
- * Brian Paul
- * 2 May 2007
- *
- * NOTE: resize the window to observe how the partial derivatives of
- * the texcoords change.
- */
-
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static char *FragProgFile = NULL;
-static char *VertProgFile = NULL;
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-static GLuint SphereList, RectList, CurList;
-static GLint win = 0;
-static GLboolean anim = GL_TRUE;
-static GLfloat xRot = 0.0f, yRot = 0.0f;
-static GLint WinSize[2];
-static GLint WinSizeUniform = -1;
-
-
-static void
-Redisplay(void)
-{
- glUniform2iv(WinSizeUniform, 1, WinSize);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glCallList(CurList);
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Idle(void)
-{
- yRot = glutGet(GLUT_ELAPSED_TIME) * 0.1;
- glutPostRedisplay();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- WinSize[0] = width;
- WinSize[1] = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(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 'o':
- if (CurList == SphereList)
- CurList = RectList;
- else
- CurList = SphereList;
- 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
-MakeSphere(void)
-{
- GLUquadricObj *obj = gluNewQuadric();
- SphereList = glGenLists(1);
- gluQuadricTexture(obj, GL_TRUE);
- glNewList(SphereList, GL_COMPILE);
- gluSphere(obj, 2.0f, 30, 15);
- glEndList();
- gluDeleteQuadric(obj);
-}
-
-
-static void
-MakeRect(void)
-{
- RectList = glGenLists(1);
- glNewList(RectList, GL_COMPILE);
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0); glVertex2f(-2, -2);
- glTexCoord2f(1, 0); glVertex2f( 2, -2);
- glTexCoord2f(1, 1); glVertex2f( 2, 2);
- glTexCoord2f(0, 1); glVertex2f(-2, 2);
- glEnd();
- glEndList();
-}
-
-
-static void
-Init(void)
-{
- static const char *fragShaderText =
- "uniform ivec2 WinSize; \n"
- "void main() {\n"
- " vec2 d = dFdy(gl_TexCoord[0].xy) * vec2(WinSize); \n"
- " gl_FragColor = vec4(d.x, d.y, 0.0, 1.0);\n"
- " // gl_FragColor = gl_TexCoord[0];\n"
- "}\n";
- static const char *vertShaderText =
- "void main() {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
- "}\n";
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
- WinSizeUniform = glGetUniformLocation(program, "WinSize");
-
- /*assert(glGetError() == 0);*/
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
- glEnable(GL_DEPTH_TEST);
-
- MakeSphere();
- MakeRect();
-
- CurList = SphereList;
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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[])
-{
- WinSize[0] = WinSize[1] = 200;
-
- glutInit(&argc, argv);
- glutInitWindowSize(WinSize[0], WinSize[1]);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- if (anim)
- glutIdleFunc(Idle);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/fragcoord.c b/progs/glsl/fragcoord.c
deleted file mode 100644
index 3dfcec87a5..0000000000
--- a/progs/glsl/fragcoord.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * Test GLSL gl_FragCoord fragment program attribute.
- * Color the quad's fragments according to their window position.
- *
- * Brian Paul
- * 20 Nov 2008
- */
-
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static GLint WinWidth = 200, WinHeight = 200;
-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_TRUE;
-static GLfloat PosX = 0.0, PosY = 0.0;
-
-
-static void
-Idle(void)
-{
- float r = (WinWidth < WinHeight) ? WinWidth : WinHeight;
- float a = glutGet(GLUT_ELAPSED_TIME) * 0.001;
- r *= 0.25;
- PosX = WinWidth / 2 + r * cos(a);
- PosY = WinHeight / 2 + r * sin(a);
-
- glutPostRedisplay();
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT);
-
- glPushMatrix();
- glTranslatef(PosX, PosY, 0.0);
-#if 0
- glBegin(GL_POLYGON);
- glVertex2f(-50, -50);
- glVertex2f( 50, -50);
- glVertex2f( 50, 50);
- glVertex2f(-50, 50);
- glEnd();
-#else
- glutSolidSphere(50, 20, 10);
-#endif
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, 0, height, -55, 55);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- WinWidth = width;
- WinHeight = height;
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
-
- switch(key) {
- case ' ':
- case 'a':
- Anim = !Anim;
- glutIdleFunc(Anim ? Idle : NULL);
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-Init(void)
-{
- static const char *fragShaderText =
- "void main() { \n"
- " vec4 scale = vec4(.005, 0.005, 0.5, 1.0);\n"
- " gl_FragColor = gl_FragCoord * scale; \n"
- "}\n";
- static const char *vertShaderText =
- "void main() {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- "}\n";
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- /*assert(glGetError() == 0);*/
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutIdleFunc(Anim ? Idle : NULL);
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/fsraytrace.c b/progs/glsl/fsraytrace.c
deleted file mode 100644
index af72a99099..0000000000
--- a/progs/glsl/fsraytrace.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */
-/*
- Copyright (c) 2010 Kristóf Ralovich
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-#include <math.h>
-
-static int Win;
-static int WinWidth = 512, WinHeight = 512;
-static int mouseGrabbed = 0;
-static GLuint vertShader;
-static GLuint fragShader;
-static GLuint program;
-static float rot[9] = {1,0,0, 0,1,0, 0,0,1};
-
-static const char* vsSource =
- "varying vec2 rayDir; \n"
- " \n"
- "void main() \n"
- "{ \n"
- " rayDir = gl_MultiTexCoord0.xy - vec2(0.5,0.5); \n"
- " gl_Position = gl_ProjectionMatrix * gl_Vertex; \n"
- "}\n";
-
-static const char* fsSource =
- "const float INF = 9999.9; \n"
- "const float EPSILON = 0.00001; \n"
- "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n"
- "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n"
- " \n"
- "varying vec2 rayDir; \n"
- " \n"
- "uniform mat3 rot; \n"
- " \n"
- "struct Ray \n"
- "{ \n"
- "vec3 orig; \n"
- "vec3 dir; \n"
- "}; \n"
- " \n"
- "struct Sphere \n"
- "{ \n"
- " vec3 c; \n"
- " float r; \n"
- "}; \n"
- " \n"
- "struct Isec \n"
- "{ \n"
- " float t; \n"
- " int idx; \n"
- " vec3 hit; \n"
- " vec3 n; \n"
- "}; \n"
- " \n"
-#ifdef __APPLE__
- "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
- "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
- "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
- "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
-#else
- "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
- "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
- "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
- "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
-#endif
- " \n"
- "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n"
- "// sqrt, let's work around. \n"
- "float \n"
- "sqrt_hack(float f2) \n"
- "{ \n"
- " vec3 v = vec3(f2,0.0,0.0); \n"
- " return length(v); \n"
- "} \n"
- " \n"
- "void \n"
- "intersect(const in Ray ray, \n"
- " const in Sphere sph, \n"
- " const in int idx, \n"
- " inout Isec isec) \n"
- "{ \n"
- " // Project both o and the sphere to the plane perpendicular to d \n"
- " // and containing c. Let x be the point where the ray intersects \n"
- " // the plane. If |x-c| < r, the ray intersects the sphere. \n"
- " vec3 o = ray.orig; \n"
- " vec3 d = ray.dir; \n"
- " vec3 n = -d; \n"
- " vec3 c = sph.c; \n"
- " float r = sph.r; \n"
- " float t = dot(c-o,n)/dot(n,d); \n"
- " vec3 x = o+d*t; \n"
- " float e = length(x-c); \n"
- " if(e > r) \n"
- " { \n"
- " // no intersection \n"
- " return; \n"
- " } \n"
- " \n"
- " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n"
- " // to get the distance between c and the intersection. \n"
- "#ifndef BUGGY_INTEL_GEN4_GLSL \n"
- " float f = sqrt(r*r - e*e); \n"
- "#else \n"
- " float f = sqrt_hack(r*r - e*e); \n"
- "#endif \n"
- " float dist = t - f; \n"
- " if(dist < 0.0) \n"
- " { \n"
- " // inside the sphere \n"
- " return; \n"
- " } \n"
- " \n"
- " if(dist < EPSILON) \n"
- " return; \n"
- " \n"
- " if(dist > isec.t) \n"
- " return; \n"
- " \n"
- " isec.t = dist; \n"
- " isec.idx = idx; \n"
- " \n"
- " isec.hit = ray.orig + ray.dir * isec.t; \n"
- " isec.n = (isec.hit - c) / r; \n"
- "} \n"
- " \n"
- "Isec \n"
- "intersect(const in Ray ray, \n"
- " const in float max_t /*= INF*/) \n"
- "{ \n"
- " Isec nearest; \n"
- " nearest.t = max_t; \n"
- " nearest.idx = -1; \n"
- " \n"
- " intersect(ray, spheres0, 0, nearest); \n"
- " intersect(ray, spheres1, 1, nearest); \n"
- " intersect(ray, spheres2, 2, nearest); \n"
- " intersect(ray, spheres3, 3, nearest); \n"
- " \n"
- " return nearest; \n"
- "} \n"
- " \n"
- "vec4 \n"
- "idx2color(const in int idx) \n"
- "{ \n"
- " vec4 diff; \n"
- " if(idx == 0) \n"
- " diff = vec4(1.0, 0.0, 0.0, 0.0); \n"
- " else if(idx == 1) \n"
- " diff = vec4(0.0, 1.0, 0.0, 0.0); \n"
- " else if(idx == 2) \n"
- " diff = vec4(0.0, 0.0, 1.0, 0.0); \n"
- " else if(idx == 3) \n"
- " diff = vec4(1.0, 1.0, 0.0, 0.0); \n"
- " return diff; \n"
- "} \n"
- " \n"
- "vec4 \n"
- "trace0(const in Ray ray) \n"
- "{ \n"
- " Isec isec = intersect(ray, INF); \n"
- " \n"
- " if(isec.idx == -1) \n"
- " { \n"
- " return backgroundColor; \n"
- " } \n"
- " \n"
- " vec4 diff = idx2color(isec.idx); \n"
- " \n"
- " vec3 N = isec.n; \n"
- " vec3 L = normalize(lightPos-isec.hit); \n"
- " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
- " return dot(N,L)*diff + pow( \n"
- " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
- "} \n"
- " \n"
- "vec4 \n"
- "trace1(const in Ray ray) \n"
- "{ \n"
- " Isec isec = intersect(ray, INF); \n"
- " \n"
- " if(isec.idx == -1) \n"
- " { \n"
- " return backgroundColor; \n"
- " } \n"
- " \n"
- " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n"
- " \n"
- " vec4 reflCol = trace0(reflRay); \n"
- " \n"
- " vec4 diff = idx2color(isec.idx) + reflCol; \n"
- " \n"
- " vec3 N = isec.n; \n"
- " vec3 L = normalize(lightPos-isec.hit); \n"
- " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
- " return dot(N,L)*diff + pow( \n"
- " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
- "} \n"
- " \n"
- "void main() \n"
- "{ \n"
- " const float z = -0.5; \n"
- " const vec3 cameraPos = vec3(0,0,3); \n"
- " Ray r = Ray(cameraPos, normalize(vec3(rayDir, z) * rot)); \n"
- " gl_FragColor = trace1(r); \n"
- "}\n";
-
-static
-float
-deg2rad(const float degree)
-{
- return( degree * 0.017453292519943295769236907684886F);
-}
-
-static void
-rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY)
-{
- const float rad1 = deg2rad(degreesAroundX);
- const float c1 = cosf(rad1);
- const float s1 = sinf(rad1);
- const float rad2 = deg2rad(degreesAroundY);
- const float c2 = cosf(rad2);
- const float s2 = sinf(rad2);
- mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2;
- mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2;
- mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2;
-}
-
-static void
-identity(float* mat3)
-{
- mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F;
- mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F;
- mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F;
-}
-
-static void
-Draw(void)
-{
- GLint location = glGetUniformLocation(program, "rot");
- static const float m = -10.F;
- static const float p = 10.F;
- static const float d = -0.5F;
-
- glUseProgram(program);
- glUniformMatrix3fv(location, 1, 0, rot);
-
- glBegin(GL_QUADS);
- {
- glTexCoord2f(0.0F, 0.0F); glVertex3f(m, m, d);
- glTexCoord2f(1.0F, 0.0F); glVertex3f(p, m, d);
- glTexCoord2f(1.0F, 1.0F); glVertex3f(p, p, d);
- glTexCoord2f(0.0F, 1.0F); glVertex3f(m, p, d);
- }
- glEnd();
- glUseProgram(0);
-
- glutSwapBuffers();
-
- {
- static int frames = 0;
- static int t0 = 0;
- static int t1 = 0;
- float dt;
- frames++;
- t1 = glutGet(GLUT_ELAPSED_TIME);
- dt = (float)(t1-t0)/1000.0F;
- if(dt >= 5.0F)
- {
- float fps = (float)frames / dt;
- printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt);
- frames = 0;
- t0 = t1;
- }
- }
-}
-
-
-static void
-Reshape(int width, int height)
-{
- WinWidth = width;
- WinHeight = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-10, 10, -10, 10, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
- switch (key) {
- case 27:
- glutDestroyWindow(Win);
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static
-void
-drag(int x, int y)
-{
- float scale = 1.5F;
- if(mouseGrabbed)
- {
- static GLfloat xRot = 0, yRot = 0;
- xRot = (float)(x - WinWidth/2) / scale;
- yRot = (float)(y - WinHeight/2) / scale;
- identity(rot);
- rotate_xy(rot, yRot, xRot);
- glutPostRedisplay();
- }
-}
-
-
-static
-void
-mouse(int button, int state, int x, int y)
-{
- mouseGrabbed = (state == GLUT_DOWN);
-}
-
-
-static void
-Init(void)
-{
- glDisable(GL_DEPTH_TEST);
-
- if(!ShadersSupported())
- {
- fprintf(stderr, "Shaders are not supported!\n");
- exit(-1);
- }
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fsSource);
- program = LinkShaders(vertShader, fragShader);
- glUseProgram(0);
-
- if(glGetError() != 0)
- {
- fprintf(stderr, "Shaders were not loaded!\n");
- exit(-1);
- }
-
- if(!glIsShader(vertShader))
- {
- fprintf(stderr, "Vertex shader failed!\n");
- exit(-1);
- }
-
- if(!glIsProgram(program))
- {
- fprintf(stderr, "Shader program failed!\n");
- exit(-1);
- }
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInitWindowSize(WinWidth, WinHeight);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- Win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Draw);
- glutMouseFunc(mouse);
- glutMotionFunc(drag);
- glutIdleFunc(Draw);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/identity.c b/progs/glsl/identity.c
deleted file mode 100644
index 526e9b82c1..0000000000
--- a/progs/glsl/identity.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * 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/glew.h>
-#include <GL/glut.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(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(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);
-
- 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(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(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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);
- glutInitWindowSize(200, 200);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- if (anim)
- glutIdleFunc(Idle);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/linktest.c b/progs/glsl/linktest.c
deleted file mode 100644
index ec3fffbf9c..0000000000
--- a/progs/glsl/linktest.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/**
- * Test linking of multiple compilation units.
- * Brian Paul
- * 28 March 2009
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static GLfloat diffuse[4] = { 0.5f, 1.0f, 0.5f, 1.0f };
-static GLfloat specular[4] = { 0.8f, 0.8f, 0.8f, 1.0f };
-static GLfloat lightPos[4] = { 0.0f, 10.0f, 20.0f, 0.0f };
-static GLfloat delta = 1.0f;
-
-static GLuint VertShader1;
-static GLuint VertShader2;
-static GLuint FragShader1;
-static GLuint FragShader2;
-static GLuint Program;
-
-static GLint uDiffuse;
-static GLint uSpecular;
-static GLint uTexture;
-
-static GLint Win = 0;
-static GLboolean anim = GL_TRUE;
-
-
-
-static const char *FragShaderSource1 =
- "float compute_dotprod(const vec3 normal) \n"
- "{ \n"
- " float dotProd = max(dot(gl_LightSource[0].position.xyz, \n"
- " normalize(normal)), 0.0); \n"
- " return dotProd; \n"
- "} \n";
-
-static const char *FragShaderSource2 =
- "uniform vec4 diffuse;\n"
- "uniform vec4 specular;\n"
- "varying vec3 normal;\n"
- "\n"
- "// external function \n"
- "float compute_dotprod(const vec3 normal); \n"
- "\n"
- "void main() \n"
- "{ \n"
- " float dotProd = compute_dotprod(normal); \n"
- " gl_FragColor = diffuse * dotProd + specular * pow(dotProd, 20.0); \n"
- "} \n";
-
-
-static const char *VertShaderSource1 =
- "vec3 compute_normal() \n"
- "{ \n"
- " return gl_NormalMatrix * gl_Normal; \n"
- "} \n";
-
-static const char *VertShaderSource2 =
- "varying vec3 normal;\n"
- "\n"
- "// external function \n"
- "vec3 compute_normal(); \n"
- "\n"
- "void main() \n"
- "{ \n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
- " normal = compute_normal(); \n"
- "} \n";
-
-
-static void
-normalize(GLfloat *dst, const GLfloat *src)
-{
- GLfloat len = sqrt(src[0] * src[0] + src[1] * src[1] + src[2] * src[2]);
- dst[0] = src[0] / len;
- dst[1] = src[1] / len;
- dst[2] = src[2] / len;
- dst[3] = src[3];
-}
-
-
-static void
-Redisplay(void)
-{
- GLfloat vec[4];
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- /* update light position */
- normalize(vec, lightPos);
- glLightfv(GL_LIGHT0, GL_POSITION, vec);
-
- glutSolidSphere(2.0, 10, 5);
-
- glutSwapBuffers();
-}
-
-
-static void
-Idle(void)
-{
- lightPos[0] += delta;
- if (lightPos[0] > 25.0f || lightPos[0] < -25.0f)
- delta = -delta;
- glutPostRedisplay();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(VertShader1);
- glDeleteShader(VertShader2);
- glDeleteShader(FragShader1);
- glDeleteShader(FragShader2);
- glDeleteProgram(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 'x':
- lightPos[0] -= 1.0f;
- break;
- case 'X':
- lightPos[0] += 1.0f;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-CheckLink(GLuint prog)
-{
- GLint stat;
- glGetProgramiv(prog, GL_LINK_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetProgramInfoLog(prog, 1000, &len, log);
- fprintf(stderr, "Linker error:\n%s\n", log);
- }
-}
-
-
-static void
-Init(void)
-{
- if (!ShadersSupported())
- exit(1);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- VertShader1 = CompileShaderText(GL_VERTEX_SHADER, VertShaderSource1);
- VertShader2 = CompileShaderText(GL_VERTEX_SHADER, VertShaderSource2);
- FragShader1 = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderSource1);
- FragShader2 = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderSource2);
-
- Program = glCreateProgram();
- glAttachShader(Program, VertShader1);
- glAttachShader(Program, VertShader2);
- glAttachShader(Program, FragShader1);
- glAttachShader(Program, FragShader2);
-
- glLinkProgram(Program);
-
- CheckLink(Program);
-
- glUseProgram(Program);
-
- uDiffuse = glGetUniformLocation(Program, "diffuse");
- uSpecular = glGetUniformLocation(Program, "specular");
- uTexture = glGetUniformLocation(Program, "texture");
- printf("DiffusePos %d SpecularPos %d TexturePos %d\n",
- uDiffuse, uSpecular, uTexture);
-
- glUniform4fv(uDiffuse, 1, diffuse);
- glUniform4fv(uSpecular, 1, specular);
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
- glEnable(GL_DEPTH_TEST);
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);
-
- assert(glIsProgram(Program));
- assert(glIsShader(VertShader1));
- assert(glIsShader(VertShader2));
- assert(glIsShader(FragShader1));
- assert(glIsShader(FragShader2));
-
- glColor3f(1, 0, 0);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(300, 300);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- Win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- if (anim)
- glutIdleFunc(Idle);
- Init();
- glutMainLoop();
- return 0;
-}
-
-
diff --git a/progs/glsl/mandelbrot.c b/progs/glsl/mandelbrot.c
deleted file mode 100644
index b05ef37fae..0000000000
--- a/progs/glsl/mandelbrot.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * "Mandelbrot" shader demo. Uses the example shaders from
- * chapter 15 (or 18) of the OpenGL Shading Language "orange" book.
- * 15 Jan 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static char *FragProgFile = "CH18-mandel.frag";
-static char *VertProgFile = "CH18-mandel.vert";
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-
-static struct uniform_info Uniforms[] = {
- /* vert */
- { "LightPosition", 1, GL_FLOAT_VEC3, { 0.1, 0.1, 9.0, 0}, -1 },
- { "SpecularContribution", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 },
- { "DiffuseContribution", 1, GL_FLOAT, { 0.5, 0, 0, 0 }, -1 },
- { "Shininess", 1, GL_FLOAT, { 20.0, 0, 0, 0 }, -1 },
- /* frag */
- { "MaxIterations", 1, GL_FLOAT, { 12, 0, 0, 0 }, -1 },
- { "Zoom", 1, GL_FLOAT, { 0.125, 0, 0, 0 }, -1 },
- { "Xcenter", 1, GL_FLOAT, { -1.5, 0, 0, 0 }, -1 },
- { "Ycenter", 1, GL_FLOAT, { .005, 0, 0, 0 }, -1 },
- { "InnerColor", 1, GL_FLOAT_VEC3, { 1, 0, 0, 0 }, -1 },
- { "OuterColor1", 1, GL_FLOAT_VEC3, { 0, 1, 0, 0 }, -1 },
- { "OuterColor2", 1, GL_FLOAT_VEC3, { 0, 0, 1, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-static GLint win = 0;
-
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
-
-static GLint uZoom, uXcenter, uYcenter;
-static GLfloat zoom = 1.0, xCenter = -1.5, yCenter = 0.0;
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- /* set interactive uniform parameters */
- glUniform1fv(uZoom, 1, &zoom);
- glUniform1fv(uXcenter, 1, &xCenter);
- glUniform1fv(uYcenter, 1, &yCenter);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0); glVertex2f(-1, -1);
- glTexCoord2f(1, 0); glVertex2f( 1, -1);
- glTexCoord2f(1, 1); glVertex2f( 1, 1);
- glTexCoord2f(0, 1); glVertex2f(-1, 1);
- glEnd();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -6.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
-
- switch(key) {
- case 'z':
- zoom *= 0.9;
- break;
- case 'Z':
- zoom /= 0.9;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 0.1 * zoom;
-
- (void) x;
- (void) y;
-
- switch(key) {
- case GLUT_KEY_UP:
- yCenter += step;
- break;
- case GLUT_KEY_DOWN:
- yCenter -= step;
- break;
- case GLUT_KEY_LEFT:
- xCenter -= step;
- break;
- case GLUT_KEY_RIGHT:
- xCenter += step;
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-Init(void)
-{
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- SetUniformValues(program, Uniforms);
- PrintUniforms(Uniforms);
-
- uZoom = glGetUniformLocation(program, "Zoom");
- uXcenter = glGetUniformLocation(program, "Xcenter");
- uYcenter = glGetUniformLocation(program, "Ycenter");
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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);
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/mandelbrot.shtest b/progs/glsl/mandelbrot.shtest
deleted file mode 100644
index 4f4e5c747e..0000000000
--- a/progs/glsl/mandelbrot.shtest
+++ /dev/null
@@ -1,13 +0,0 @@
-vs CH18-mandel.vert
-fs CH18-mandel.frag
-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/multinoise.c b/progs/glsl/multinoise.c
deleted file mode 100644
index d504ba1cc4..0000000000
--- a/progs/glsl/multinoise.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/**
- * Another test for noise() functions (noise1 to noise4 tested independently).
- * 13 Dec 2008
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-
-static const char *VertShaderText =
- "void main() {\n"
- " gl_TexCoord[0].xyz = gl_Vertex.xyz;\n"
- " gl_TexCoord[0].w = gl_MultiTexCoord1.x;\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- "}\n";
-
-static const char *FragShaderText[ 4 ] = {
- "void main()\n"
- "{\n"
- " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].w ) * 0.5 + 0.5;\n"
- " gl_FragColor.a = 1.0;\n"
- "}\n",
- "void main()\n"
- "{\n"
- " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xw ) * 0.5 + 0.5;\n"
- " gl_FragColor.a = 1.0;\n"
- "}\n",
- "void main()\n"
- "{\n"
- " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyw ) * 0.5 + 0.5;\n"
- " gl_FragColor.a = 1.0;\n"
- "}\n",
- "void main()\n"
- "{\n"
- " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyzw ) * 0.5 + 0.5;\n"
- " gl_FragColor.a = 1.0;\n"
- "}\n"
-};
-
-struct uniform_info {
- const char *name;
- GLuint size;
- GLint location;
- GLfloat value[4];
-};
-
-/* program/shader objects */
-static GLuint fragShader[ 4 ];
-static GLuint vertShader;
-static GLuint program[ 4 ];
-
-static GLint win = 0;
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
-static GLfloat Slice = 0.0;
-static GLboolean Anim = GL_FALSE;
-
-
-static void
-Idle(void)
-{
- Slice += 0.01;
- glutPostRedisplay();
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glMultiTexCoord1f( GL_TEXTURE1, Slice );
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glutSolidTeapot( 1.0 );
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- GLint i;
-
- glDeleteShader(vertShader);
- for( i = 0; i < 4; i++ ) {
- glDeleteShader(fragShader[ i ]);
- glDeleteProgram(program[ i ]);
- }
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 0.01;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- glutIdleFunc(Anim ? Idle : NULL);
- break;
- case 's':
- Slice -= step;
- break;
- case 'S':
- Slice += step;
- break;
- case 'z':
- zRot -= 1.0;
- break;
- case 'Z':
- zRot += 1.0;
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- glUseProgram(program[ key - '1' ]);
- 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
-LoadAndCompileShader(GLuint shader, const char *text)
-{
- GLint stat;
-
- glShaderSource(shader, 1, (const GLchar **) &text, NULL);
-
- glCompileShader(shader);
-
- glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetShaderInfoLog(shader, 1000, &len, log);
- fprintf(stderr, "multinoise: problem compiling shader: %s\n", log);
- exit(1);
- }
- else {
- printf("Shader compiled OK\n");
- }
-}
-
-
-static void
-CheckLink(GLuint prog)
-{
- GLint stat;
- glGetProgramiv(prog, GL_LINK_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetProgramInfoLog(prog, 1000, &len, log);
- fprintf(stderr, "Linker error:\n%s\n", log);
- }
- else {
- fprintf(stderr, "Link success!\n");
- }
-}
-
-
-static void
-Init(void)
-{
- const char *version;
- GLint i;
-
- version = (const char *) glGetString(GL_VERSION);
- if (version[0] != '2' || version[1] != '.') {
- printf("Warning: this program expects OpenGL 2.0\n");
- /*exit(1);*/
- }
-
- vertShader = glCreateShader(GL_VERTEX_SHADER);
- LoadAndCompileShader(vertShader, VertShaderText);
-
- for( i = 0; i < 4; i++ ) {
- fragShader[ i ] = glCreateShader(GL_FRAGMENT_SHADER);
- LoadAndCompileShader(fragShader[ i ], FragShaderText[ i ]);
- program[ i ] = glCreateProgram();
- glAttachShader(program[ i ], fragShader[ i ]);
- glAttachShader(program[ i ], vertShader);
- glLinkProgram(program[ i ]);
- CheckLink(program[ i ]);
- }
-
- glUseProgram(program[ 0 ]);
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- glColor3f(1, 0, 0);
-
- glFrontFace( GL_CW );
- glEnable( GL_CULL_FACE );
- glEnable( GL_DEPTH_TEST );
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c
deleted file mode 100644
index 49b32253ee..0000000000
--- a/progs/glsl/multitex.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/**
- * Test multi-texturing with GL shading language.
- *
- * Copyright (C) 2008 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <GL/glew.h>
-#include "GL/glut.h"
-#include "readtex.h"
-#include "shaderutil.h"
-
-static const char *Demo = "multitex";
-
-static const char *VertFile = "multitex.vert";
-static const char *FragFile = "multitex.frag";
-
-static const char *TexFiles[2] =
- {
- "../images/tile.rgb",
- "../images/tree2.rgba"
- };
-
-
-static GLuint Program;
-
-static GLfloat Xrot = 0.0, Yrot = .0, Zrot = 0.0;
-static GLfloat EyeDist = 10;
-static GLboolean Anim = GL_TRUE;
-static GLboolean UseArrays = GL_TRUE;
-static GLboolean UseVBO = GL_TRUE;
-static GLuint VBO = 0;
-
-static GLint VertCoord_attr = -1, TexCoord0_attr = -1, TexCoord1_attr = -1;
-
-
-/* value[0] = tex unit */
-static struct uniform_info Uniforms[] = {
- { "tex1", 1, GL_SAMPLER_2D, { 0, 0, 0, 0 }, -1 },
- { "tex2", 1, GL_SAMPLER_2D, { 1, 0, 0, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-
-static const GLfloat Tex0Coords[4][2] = {
- { 0.0, 0.0 }, { 2.0, 0.0 }, { 2.0, 2.0 }, { 0.0, 2.0 }
-};
-
-static const GLfloat Tex1Coords[4][2] = {
- { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 }
-};
-
-static const GLfloat VertCoords[4][2] = {
- { -3.0, -3.0 }, { 3.0, -3.0 }, { 3.0, 3.0 }, { -3.0, 3.0 }
-};
-
-
-
-static void
-SetupVertexBuffer(void)
-{
- glGenBuffersARB(1, &VBO);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
-
- glBufferDataARB(GL_ARRAY_BUFFER_ARB,
- sizeof(VertCoords) +
- sizeof(Tex0Coords) +
- sizeof(Tex1Coords),
- NULL,
- GL_STATIC_DRAW_ARB);
-
- /* non-interleaved vertex arrays */
-
- glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,
- 0, /* offset */
- sizeof(VertCoords), /* size */
- VertCoords); /* data */
-
- glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,
- sizeof(VertCoords), /* offset */
- sizeof(Tex0Coords), /* size */
- Tex0Coords); /* data */
-
- glBufferSubDataARB(GL_ARRAY_BUFFER_ARB,
- sizeof(VertCoords) +
- sizeof(Tex0Coords), /* offset */
- sizeof(Tex1Coords), /* size */
- Tex1Coords); /* data */
-
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
-}
-
-
-static void
-DrawPolygonArray(void)
-{
- void *vertPtr, *tex0Ptr, *tex1Ptr;
-
- if (UseVBO) {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
- vertPtr = (void *) 0;
- tex0Ptr = (void *) sizeof(VertCoords);
- tex1Ptr = (void *) (sizeof(VertCoords) + sizeof(Tex0Coords));
- }
- else {
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- vertPtr = VertCoords;
- tex0Ptr = Tex0Coords;
- tex1Ptr = Tex1Coords;
- }
-
- if (VertCoord_attr >= 0) {
- glVertexAttribPointer(VertCoord_attr, 2, GL_FLOAT, GL_FALSE,
- 0, vertPtr);
- glEnableVertexAttribArray(VertCoord_attr);
- }
- else {
- glVertexPointer(2, GL_FLOAT, 0, vertPtr);
- glEnableClientState(GL_VERTEX_ARRAY);
- }
-
- glVertexAttribPointer(TexCoord0_attr, 2, GL_FLOAT, GL_FALSE,
- 0, tex0Ptr);
- glEnableVertexAttribArray(TexCoord0_attr);
-
- glVertexAttribPointer(TexCoord1_attr, 2, GL_FLOAT, GL_FALSE,
- 0, tex1Ptr);
- glEnableVertexAttribArray(TexCoord1_attr);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
-}
-
-
-static void
-DrawPolygonVert(void)
-{
- GLuint i;
-
- glBegin(GL_TRIANGLE_FAN);
-
- for (i = 0; i < 4; i++) {
- glVertexAttrib2fv(TexCoord0_attr, Tex0Coords[i]);
- glVertexAttrib2fv(TexCoord1_attr, Tex1Coords[i]);
-
- if (VertCoord_attr >= 0)
- glVertexAttrib2fv(VertCoord_attr, VertCoords[i]);
- else
- glVertex2fv(VertCoords[i]);
- }
-
- glEnd();
-}
-
-
-static void
-draw(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix(); /* modelview matrix */
- glTranslatef(0.0, 0.0, -EyeDist);
- glRotatef(Zrot, 0, 0, 1);
- glRotatef(Yrot, 0, 1, 0);
- glRotatef(Xrot, 1, 0, 0);
-
- if (UseArrays)
- DrawPolygonArray();
- else
- DrawPolygonVert();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-idle(void)
-{
- GLfloat t = 0.05 * glutGet(GLUT_ELAPSED_TIME);
- Yrot = t;
- glutPostRedisplay();
-}
-
-
-static void
-key(unsigned char k, int x, int y)
-{
- (void) x;
- (void) y;
- switch (k) {
- case 'a':
- UseArrays = !UseArrays;
- printf("Arrays: %d\n", UseArrays);
- break;
- case 'v':
- UseVBO = !UseVBO;
- printf("Use VBO: %d\n", UseVBO);
- break;
- case ' ':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'z':
- EyeDist -= 0.5;
- if (EyeDist < 3.0)
- EyeDist = 3.0;
- break;
- case 'Z':
- EyeDist += 0.5;
- if (EyeDist > 90.0)
- EyeDist = 90;
- break;
- case 27:
- exit(0);
- }
- glutPostRedisplay();
-}
-
-
-static void
-specialkey(int key, int x, int y)
-{
- GLfloat step = 2.0;
- (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();
-}
-
-
-/* new window size or exposure */
-static void
-Reshape(int width, int height)
-{
- GLfloat ar = (float) width / (float) height;
- glViewport(0, 0, (GLint)width, (GLint)height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-2.0*ar, 2.0*ar, -2.0, 2.0, 4.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-InitTextures(void)
-{
- GLenum filter = GL_LINEAR;
- int i;
-
- for (i = 0; i < 2; i++) {
- GLint imgWidth, imgHeight;
- GLenum imgFormat;
- GLubyte *image = NULL;
-
- image = LoadRGBImage(TexFiles[i], &imgWidth, &imgHeight, &imgFormat);
- if (!image) {
- printf("Couldn't read %s\n", TexFiles[i]);
- exit(0);
- }
-
- glActiveTexture(GL_TEXTURE0 + i);
- glBindTexture(GL_TEXTURE_2D, 42 + i);
- 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 GLuint
-CreateProgram(const char *vertProgFile, const char *fragProgFile,
- struct uniform_info *uniforms)
-{
- GLuint fragShader, vertShader, program;
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, vertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, fragProgFile);
- assert(vertShader);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- SetUniformValues(program, uniforms);
- PrintUniforms(Uniforms);
-
- assert(ValidateShaderProgram(program));
-
- VertCoord_attr = glGetAttribLocation(program, "VertCoord");
- if (VertCoord_attr > 0) {
- /* We want the VertCoord attrib to have position zero so that
- * the call to glVertexAttrib(0, xyz) triggers vertex processing.
- * Otherwise, if TexCoord0 or TexCoord1 gets position 0 we'd have
- * to set that attribute last (which is a PITA to manage).
- */
- glBindAttribLocation(program, 0, "VertCoord");
- /* re-link */
- glLinkProgram(program);
- /* VertCoord_attr should be zero now */
- VertCoord_attr = glGetAttribLocation(program, "VertCoord");
- assert(VertCoord_attr == 0);
- }
-
- TexCoord0_attr = glGetAttribLocation(program, "TexCoord0");
- TexCoord1_attr = glGetAttribLocation(program, "TexCoord1");
-
- printf("TexCoord0_attr = %d\n", TexCoord0_attr);
- printf("TexCoord1_attr = %d\n", TexCoord1_attr);
- printf("VertCoord_attr = %d\n", VertCoord_attr);
-
- return program;
-}
-
-
-static void
-InitPrograms(void)
-{
- Program = CreateProgram(VertFile, FragFile, Uniforms);
-}
-
-
-static void
-InitGL(void)
-{
- if (!ShadersSupported())
- exit(1);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
- printf("Usage:\n");
- printf(" a - toggle arrays vs. immediate mode rendering\n");
- printf(" v - toggle VBO usage for array rendering\n");
- printf(" z/Z - change viewing distance\n");
- printf(" SPACE - toggle animation\n");
- printf(" Esc - exit\n");
-
- InitTextures();
- InitPrograms();
-
- SetupVertexBuffer();
-
- glEnable(GL_DEPTH_TEST);
-
- glClearColor(.6, .6, .9, 0);
- glColor3f(1.0, 1.0, 1.0);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(500, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutCreateWindow(Demo);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(key);
- glutSpecialFunc(specialkey);
- glutDisplayFunc(draw);
- if (Anim)
- glutIdleFunc(idle);
- InitGL();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/multitex.frag b/progs/glsl/multitex.frag
deleted file mode 100644
index a2633ceba7..0000000000
--- a/progs/glsl/multitex.frag
+++ /dev/null
@@ -1,15 +0,0 @@
-// Multi-texture fragment shader
-// Brian Paul
-
-// Composite second texture over first.
-// We're assuming the 2nd texture has a meaningful alpha channel.
-
-uniform sampler2D tex1;
-uniform sampler2D tex2;
-
-void main()
-{
- 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.shtest b/progs/glsl/multitex.shtest
deleted file mode 100644
index 4b7c3fd4a5..0000000000
--- a/progs/glsl/multitex.shtest
+++ /dev/null
@@ -1,6 +0,0 @@
-vs multitex.vert
-fs multitex.frag
-texture 0 2D ../images/tile.rgb
-texture 1 2D ../images/tree2.rgba
-uniform tex1 GL_SAMPLER_2D 0
-uniform tex2 GL_SAMPLER_2D 1
diff --git a/progs/glsl/multitex.vert b/progs/glsl/multitex.vert
deleted file mode 100644
index 4fae3b73fb..0000000000
--- a/progs/glsl/multitex.vert
+++ /dev/null
@@ -1,14 +0,0 @@
-// Multi-texture vertex shader
-// Brian Paul
-
-
-attribute vec4 TexCoord0, TexCoord1;
-attribute vec4 VertCoord;
-
-void main()
-{
- gl_TexCoord[0] = TexCoord0;
- gl_TexCoord[1] = TexCoord1;
- // note: may use gl_Vertex or VertCoord here for testing:
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
-}
diff --git a/progs/glsl/noise.c b/progs/glsl/noise.c
deleted file mode 100644
index 1148580ff4..0000000000
--- a/progs/glsl/noise.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/**
- * Test noise() functions.
- * 28 Jan 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static const char *VertShaderText =
- "void main() {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
- "}\n";
-
-static const char *FragShaderText =
- "uniform vec4 Scale, Bias;\n"
- "uniform float Slice;\n"
- "void main()\n"
- "{\n"
- " vec4 scale = vec4(5.0);\n"
- " vec4 p;\n"
- " p.xy = gl_TexCoord[0].xy;\n"
- " p.z = Slice;\n"
- " p.w = 0.0;\n"
- " vec4 n = noise4(p * scale);\n"
- " gl_FragColor = n * Scale + Bias;\n"
- "}\n";
-
-
-static struct uniform_info Uniforms[] = {
- { "Scale", 1, GL_FLOAT_VEC4, { 0.5, 0.4, 0.0, 0}, -1 },
- { "Bias", 1, GL_FLOAT_VEC4, { 0.5, 0.3, 0.0, 0}, -1 },
- { "Slice", 1, GL_FLOAT, { 0.5, 0, 0, 0}, -1 },
- END_OF_UNIFORMS
-};
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-static GLint win = 0;
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
-static GLfloat Slice = 0.0;
-static GLboolean Anim = GL_FALSE;
-
-
-static void
-Idle(void)
-{
- Slice += 0.01;
- glutPostRedisplay();
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glUniform1fv(Uniforms[2].location, 1, &Slice);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glBegin(GL_POLYGON);
- glTexCoord2f(0, 0); glVertex2f(-2, -2);
- glTexCoord2f(1, 0); glVertex2f( 2, -2);
- glTexCoord2f(1, 1); glVertex2f( 2, 2);
- glTexCoord2f(0, 1); glVertex2f(-2, 2);
- glEnd();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 0.01;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- glutIdleFunc(Anim ? Idle : NULL);
- break;
- case 's':
- Slice -= step;
- break;
- case 'S':
- Slice += step;
- break;
- case 'z':
- zRot -= 1.0;
- break;
- case 'Z':
- zRot += 1.0;
- 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)
-{
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, VertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- SetUniformValues(program, Uniforms);
- PrintUniforms(Uniforms);
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(vertShader));
-
- glColor3f(1, 0, 0);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/noise2.c b/progs/glsl/noise2.c
deleted file mode 100644
index 7a28f09947..0000000000
--- a/progs/glsl/noise2.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * GLSL noise demo.
- *
- * Michal Krol
- * 20 February 2006
- *
- * Based on the original demo by:
- * Stefan Gustavson (stegu@itn.liu.se) 2004, 2005
- */
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <GL/gl.h>
-#include <GL/glut.h>
-#include <GL/glext.h>
-
-#ifdef WIN32
-#define GETPROCADDRESS(F) wglGetProcAddress(F)
-#else
-#define GETPROCADDRESS(F) glutGetProcAddress(F)
-#endif
-
-static GLhandleARB fragShader;
-static GLhandleARB vertShader;
-static GLhandleARB program;
-
-static GLint uTime;
-
-static GLint t0 = 0;
-static GLint frames = 0;
-
-static GLfloat u_time = 0.0f;
-
-static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
-static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
-static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
-static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
-static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
-static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
-static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
-static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
-static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL;
-
-static void Redisplay (void)
-{
- GLint t;
-
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glUniform1fARB (uTime, 0.5f * u_time);
-
- glPushMatrix ();
- glutSolidSphere (2.0, 20, 10);
- glPopMatrix ();
-
- glutSwapBuffers();
- frames++;
-
- t = glutGet (GLUT_ELAPSED_TIME);
- if (t - t0 >= 5000) {
- GLfloat seconds = (GLfloat) (t - t0) / 1000.0f;
- GLfloat fps = frames / seconds;
- printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps);
- fflush(stdout);
- t0 = t;
- frames = 0;
- }
-}
-
-static void Idle (void)
-{
- u_time += 0.1f;
- glutPostRedisplay ();
-}
-
-static void Reshape (int width, int height)
-{
- glViewport (0, 0, width, height);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- glFrustum (-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity ();
- glTranslatef (0.0f, 0.0f, -15.0f);
-}
-
-static void Key (unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
-
- switch (key)
- {
- case 27:
- exit(0);
- break;
- }
- glutPostRedisplay ();
-}
-
-static void Init (void)
-{
- static const char *fragShaderText =
- "uniform float time;\n"
- "varying vec3 position;\n"
- "void main () {\n"
- " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n"
- "}\n"
- ;
- static const char *vertShaderText =
- "varying vec3 position;\n"
- "void main () {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " position = 4.0 * gl_Vertex.xyz;\n"
- "}\n"
- ;
-
- if (!glutExtensionSupported ("GL_ARB_fragment_shader"))
- {
- printf ("Sorry, this demo requires GL_ARB_fragment_shader\n");
- exit(1);
- }
- if (!glutExtensionSupported ("GL_ARB_shader_objects"))
- {
- printf ("Sorry, this demo requires GL_ARB_shader_objects\n");
- exit(1);
- }
- if (!glutExtensionSupported ("GL_ARB_shading_language_100"))
- {
- printf ("Sorry, this demo requires GL_ARB_shading_language_100\n");
- exit(1);
- }
- if (!glutExtensionSupported ("GL_ARB_vertex_shader"))
- {
- printf ("Sorry, this demo requires GL_ARB_vertex_shader\n");
- exit(1);
- }
-
- glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)
- GETPROCADDRESS("glCreateShaderObjectARB");
- glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)
- GETPROCADDRESS("glShaderSourceARB");
- glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)
- GETPROCADDRESS("glCompileShaderARB");
- glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)
- GETPROCADDRESS("glCreateProgramObjectARB");
- glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)
- GETPROCADDRESS("glAttachObjectARB");
- glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)
- GETPROCADDRESS ("glLinkProgramARB");
- glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)
- GETPROCADDRESS("glUseProgramObjectARB");
-
- glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)
- GETPROCADDRESS("glGetUniformLocationARB");
- glUniform1fARB = (PFNGLUNIFORM1FARBPROC)
- GETPROCADDRESS("glUniform1fARB");
-
- fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
- glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);
- glCompileShaderARB (fragShader);
-
- vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);
- glShaderSourceARB (vertShader, 1, &vertShaderText, NULL);
- glCompileShaderARB (vertShader);
-
- program = glCreateProgramObjectARB ();
- glAttachObjectARB (program, fragShader);
- glAttachObjectARB (program, vertShader);
- glLinkProgramARB (program);
- glUseProgramObjectARB (program);
-
- uTime = glGetUniformLocationARB (program, "time");
-
- glClearColor (0.0f, 0.1f, 0.3f, 1.0f);
- glEnable (GL_CULL_FACE);
- glEnable (GL_DEPTH_TEST);
-
- printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER));
-}
-
-int main (int argc, char *argv[])
-{
- glutInit (&argc, argv);
- glutInitWindowSize (200, 200);
- glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow (argv[0]);
- glutReshapeFunc (Reshape);
- glutKeyboardFunc (Key);
- glutDisplayFunc (Redisplay);
- glutIdleFunc (Idle);
- Init ();
- glutMainLoop ();
- return 0;
-}
-
diff --git a/progs/glsl/pointcoord.c b/progs/glsl/pointcoord.c
deleted file mode 100644
index 5dced6fac3..0000000000
--- a/progs/glsl/pointcoord.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/**
- * 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/glew.h>
-#include <GL/glut.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(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(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);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- tex0 = glGetUniformLocation(program, "tex0");
- printf("Uniforms: tex0: %d\n", tex0);
-
- glUniform1i(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(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/points.c b/progs/glsl/points.c
deleted file mode 100644
index 98490f1819..0000000000
--- a/progs/glsl/points.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/**
- * Implement smooth (AA) points with shaders.
- * A simple variation could be used for sprite points.
- * Brian Paul
- * 29 July 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static GLuint FragShader;
-static GLuint VertShader;
-static GLuint Program;
-
-static GLint Win = 0;
-static GLint WinWidth = 500, WinHeight = 200;
-static GLfloat Xpos = 0.0f, Ypos = 0.0f;
-static GLint uViewportInv;
-static GLboolean Smooth = GL_TRUE, Blend = GL_TRUE;
-
-
-/**
- * Issue vertices for a "shader point".
- * The position is duplicated, only texcoords (or other vertex attrib) change.
- * The vertex program will compute the "real" quad corners.
- */
-static void
-PointVertex3f(GLfloat x, GLfloat y, GLfloat z)
-{
- glTexCoord2f(-1, -1);
- glVertex3f(x, y, z);
-
- glTexCoord2f( 1, -1);
- glVertex3f(x, y, z);
-
- glTexCoord2f( 1, 1);
- glVertex3f(x, y, z);
-
- glTexCoord2f(-1, 1);
- glVertex3f(x, y, z);
-}
-
-
-static void
-DrawPoints(GLboolean shaderPoints)
-{
- int i;
- for (i = 0; i < 9; i++) {
- GLfloat x = i - 4, y = 0, z = 0;
- /* note: can't call glPointSize inside Begin/End :( */
- glPointSize( 2 + i * 5 );
- if (shaderPoints) {
- glBegin(GL_QUADS);
- PointVertex3f(x, y, z);
- glEnd();
- }
- else {
- glBegin(GL_POINTS);
- glVertex3f(x, y, z);
- glEnd();
- }
- }
-}
-
-
-/**
- * Top row of points is rendered conventionally with GL_POINT_SMOOTH.
- * Bottom row is rendered with special vertex/fragment shaders (see Init()).
- */
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- if (Smooth)
- glEnable(GL_POINT_SMOOTH);
- else
- glDisable(GL_POINT_SMOOTH);
-
- if (Blend)
- glEnable(GL_BLEND);
- else
- glDisable(GL_BLEND);
-
- glPushMatrix();
- glTranslatef(Xpos, Ypos, 0);
-
- /*
- * regular points
- */
- glPushMatrix();
- glTranslatef(0, 1.2, 0);
- glUseProgram(0);
- DrawPoints(GL_FALSE);
- glPopMatrix();
-
- /*
- * shader points
- */
- glPushMatrix();
- glTranslatef(0, -1.2, 0);
- glUseProgram(Program);
- if (uViewportInv != -1) {
- glUniform2f(uViewportInv, 1.0 / WinWidth, 1.0 / WinHeight);
- }
- DrawPoints(GL_TRUE);
- glPopMatrix();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- WinWidth = width;
- WinHeight = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 4.0, 30.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -20.0f);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
-
- switch(key) {
- case 'b':
- Blend = !Blend;
- break;
- case 's':
- Smooth = !Smooth;
- break;
- case 27:
- glDeleteShader(FragShader);
- glDeleteShader(VertShader);
- glDeleteProgram(Program);
- glutDestroyWindow(Win);
- exit(0);
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 1/100.0;
- switch(key) {
- case GLUT_KEY_UP:
- Ypos += step;
- break;
- case GLUT_KEY_DOWN:
- Ypos -= step;
- break;
- case GLUT_KEY_LEFT:
- Xpos -= step;
- break;
- case GLUT_KEY_RIGHT:
- Xpos += step;
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-Init(void)
-{
- /* Fragment shader: compute distance of fragment from center of point
- * (we're using texcoords but another varying could be used).
- * if dist > 1, discard (coverage==0)
- * if dist < k, coverage = 1
- * else, coverage = func(dist)
- * Note: length() uses sqrt() and may be expensive. The distance could
- * be squared instead (with adjustments to the threshold (k) test)
- */
- static const char *fragShaderText =
- "void main() {\n"
- " float cover; \n"
- " float k = 2.0 / gl_Point.size; \n"
- " float d = length(gl_TexCoord[0].xy); \n"
- " if (d >= 1.0) \n"
- " discard; \n"
- " if (d < 1.0 - k) \n"
- " cover = 1.0; \n"
- " else \n"
- " cover = (1.0 - d) * 0.5 * gl_Point.size; \n"
- " gl_FragColor.rgb = gl_Color.rgb; \n"
- " gl_FragColor.a = cover; \n"
- "}\n";
- /* Vertex shader: compute new vertex position based on incoming vertex pos,
- * texcoords, point size, and inverse viewport scale factor.
- * Note: should compute point size attenuation here too.
- */
- static const char *vertShaderText =
- "uniform vec2 viewportInv; \n"
- "void main() {\n"
- " vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_Position.xy = pos.xy + gl_MultiTexCoord0.xy * viewportInv \n"
- " * gl_Point.size * pos.w; \n"
- " gl_Position.zw = pos.zw; \n"
- " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
- " gl_FrontColor = gl_Color; \n"
- "}\n";
-
- if (!ShadersSupported())
- exit(1);
-
- VertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- FragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- Program = LinkShaders(VertShader, FragShader);
-
- glUseProgram(Program);
-
- uViewportInv = glGetUniformLocation(Program, "viewportInv");
-
- glUseProgram(0);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- Win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- Init();
- glutMainLoop();
- return 0;
-}
-
-
diff --git a/progs/glsl/reflect.vert b/progs/glsl/reflect.vert
deleted file mode 100644
index e1f22def33..0000000000
--- a/progs/glsl/reflect.vert
+++ /dev/null
@@ -1,20 +0,0 @@
-// Vertex shader for cube-texture reflection mapping
-// Brian Paul
-
-
-varying vec3 normal;
-
-void main()
-{
- vec3 n = gl_NormalMatrix * gl_Normal;
- vec3 u = normalize(vec3(gl_ModelViewMatrix * gl_Vertex));
- float two_n_dot_u = 2.0 * dot(n, u);
- vec4 f;
- f.xyz = u - n * two_n_dot_u;
- f.w = 1.0;
-
- // outputs
- normal = n;
- gl_TexCoord[0] = gl_TextureMatrix[0] * f;
- gl_Position = ftransform();
-}
diff --git a/progs/glsl/samplers.c b/progs/glsl/samplers.c
deleted file mode 100644
index 8f26a5e329..0000000000
--- a/progs/glsl/samplers.c
+++ /dev/null
@@ -1,375 +0,0 @@
-/**
- * Exercise all available GLSL texture samplers.
- *
- * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * We generate a fragment shader which uses the maximum number of supported
- * texture samplers.
- * For each sampler we create a separate texture. Each texture has a
- * single strip of color at a different intensity. The fragment shader
- * samples all the textures at the same coordinate and sums the values.
- * The result should be a quad with rows of colors of increasing intensity
- * from bottom to top.
- *
- * Brian Paul
- * 1 Jan 2009
- */
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <GL/glew.h>
-#include "GL/glut.h"
-#include "shaderutil.h"
-
-
-#define MAX_SAMPLERS 128
-
-
-static const char *Demo = "samplers";
-
-static GLuint Program;
-static GLint NumSamplers;
-static GLuint Textures[MAX_SAMPLERS];
-static GLfloat Xrot = 0.0, Yrot = .0, Zrot = 0.0;
-static GLfloat EyeDist = 10;
-static GLboolean Anim = GL_FALSE;
-
-
-static void
-DrawPolygon(GLfloat size)
-{
- glPushMatrix();
- glNormal3f(0, 0, 1);
- glBegin(GL_POLYGON);
-
- glMultiTexCoord2f(GL_TEXTURE0, 0, 0);
- glVertex2f(-size, -size);
-
- glMultiTexCoord2f(GL_TEXTURE0, 1, 0);
- glVertex2f( size, -size);
-
- glMultiTexCoord2f(GL_TEXTURE0, 1, 1);
- glVertex2f( size, size);
-
- glMultiTexCoord2f(GL_TEXTURE0, 0, 1);
- glVertex2f(-size, size);
-
- glEnd();
- glPopMatrix();
-}
-
-
-static void
-draw(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glTranslatef(0.0, 0.0, -EyeDist);
- glRotatef(Zrot, 0, 0, 1);
- glRotatef(Yrot, 0, 1, 0);
- glRotatef(Xrot, 1, 0, 0);
-
- DrawPolygon(3.0);
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-idle(void)
-{
- GLfloat t = 0.05 * glutGet(GLUT_ELAPSED_TIME);
- Yrot = t;
- glutPostRedisplay();
-}
-
-
-static void
-key(unsigned char k, int x, int y)
-{
- (void) x;
- (void) y;
- switch (k) {
- case ' ':
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'z':
- EyeDist -= 0.5;
- if (EyeDist < 3.0)
- EyeDist = 3.0;
- break;
- case 'Z':
- EyeDist += 0.5;
- if (EyeDist > 90.0)
- EyeDist = 90;
- break;
- case 27:
- exit(0);
- }
- glutPostRedisplay();
-}
-
-
-static void
-specialkey(int key, int x, int y)
-{
- GLfloat step = 2.0;
- (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();
-}
-
-
-/* new window size or exposure */
-static void
-Reshape(int width, int height)
-{
- GLfloat ar = (float) width / (float) height;
- glViewport(0, 0, (GLint)width, (GLint)height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-2.0*ar, 2.0*ar, -2.0, 2.0, 4.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-InitTextures(void)
-{
- const GLint size = MAX_SAMPLERS;
- GLubyte *texImage;
- GLenum filter = GL_NEAREST;
- GLint stripeSize;
- GLint s;
-
- texImage = (GLubyte *) malloc(size * size * 4);
-
- glGenTextures(NumSamplers, Textures);
-
- /* size of texels stripe */
- stripeSize = size / NumSamplers;
-
- /* create a texture for each sampler */
- for (s = 0; s < NumSamplers; s++) {
- GLint x, y, ypos;
- GLubyte intensity = 31 + s * (256-32) / (NumSamplers - 1);
-
- printf("Texture %d: color = %d, %d, %d\n", s,
- (int) intensity, 0, (int) intensity );
-
- /* initialize the texture to black */
- memset(texImage, 0, size * size * 4);
-
- /* set a stripe of texels to the intensity value */
- ypos = s * stripeSize;
- for (y = 0; y < stripeSize; y++) {
- for (x = 0; x < size; x++) {
- GLint k = 4 * ((ypos + y) * size + x);
- if (x < size / 2) {
- texImage[k + 0] = intensity;
- texImage[k + 1] = intensity;
- texImage[k + 2] = 0;
- texImage[k + 3] = 255;
- }
- else {
- texImage[k + 0] = 255 - intensity;
- texImage[k + 1] = 0;
- texImage[k + 2] = 0;
- texImage[k + 3] = 255;
- }
- }
- }
-
- glActiveTexture(GL_TEXTURE0 + s);
- glBindTexture(GL_TEXTURE_2D, Textures[s]);
- gluBuild2DMipmaps(GL_TEXTURE_2D, 4, size, size,
- GL_RGBA, GL_UNSIGNED_BYTE, texImage);
-
- 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);
- }
-
- free(texImage);
-}
-
-
-/**
- * Generate a fragment shader that uses the given number of samplers.
- */
-static char *
-GenFragmentShader(GLint numSamplers)
-{
- const int maxLen = 10 * 1000;
- char *prog = (char *) malloc(maxLen);
- char *p = prog;
- int s;
-
- p += sprintf(p, "// Generated fragment shader:\n");
-#ifndef SAMPLERS_ARRAY
- for (s = 0; s < numSamplers; s++) {
- p += sprintf(p, "uniform sampler2D tex%d;\n", s);
- }
-#else
- p += sprintf(p, "uniform sampler2D tex[%d];\n", numSamplers);
-#endif
- p += sprintf(p, "void main()\n");
- p += sprintf(p, "{\n");
- p += sprintf(p, " vec4 color = vec4(0.0);\n");
- for (s = 0; s < numSamplers; s++) {
-#ifndef SAMPLERS_ARRAY
- p += sprintf(p, " color += texture2D(tex%d, gl_TexCoord[0].xy);\n", s);
-#else
- p += sprintf(p, " color += texture2D(tex[%d], gl_TexCoord[0].xy);\n", s);
-#endif
- }
- p += sprintf(p, " gl_FragColor = color;\n");
- p += sprintf(p, "}\n");
-
- assert(p - prog < maxLen);
- return prog;
-}
-
-
-/** Create & bind shader program */
-static GLuint
-CreateProgram(void)
-{
- GLuint fragShader, vertShader, program;
- const char *vertShaderText =
- "void main() \n"
- "{ \n"
- " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
- " gl_Position = ftransform(); \n"
- "} \n";
- char *fragShaderText = GenFragmentShader(NumSamplers);
-
- printf("%s", fragShaderText);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- assert(vertShader);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- free(fragShaderText);
-
- return program;
-}
-
-
-static void
-InitProgram(void)
-{
- GLint s;
-
- Program = CreateProgram();
-
- /* init sampler uniforms */
- for (s = 0; s < NumSamplers; s++) {
- char uname[10];
- GLint loc;
-
-#ifndef SAMPLERS_ARRAY
- sprintf(uname, "tex%d", s);
-#else
- sprintf(uname, "tex[%d]", s);
-#endif
- loc = glGetUniformLocation(Program, uname);
- assert(loc >= 0);
-
- glUniform1i(loc, s);
- }
-}
-
-
-static void
-InitGL(void)
-{
- if (!ShadersSupported()) {
- printf("GLSL not supported!\n");
- exit(1);
- }
-
- printf("GL_RENDERER = %s\n", (const char *) glGetString(GL_RENDERER));
-
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &NumSamplers);
- if (NumSamplers > MAX_SAMPLERS)
- NumSamplers = MAX_SAMPLERS;
- printf("Testing %d samplers\n", NumSamplers);
-
- InitTextures();
- InitProgram();
-
- glClearColor(.6, .6, .9, 0);
- glColor3f(1.0, 1.0, 1.0);
-
- printf("Each color corresponds to a separate sampler/texture.\n");
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(500, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- glutCreateWindow(Demo);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(key);
- glutSpecialFunc(specialkey);
- glutDisplayFunc(draw);
- if (Anim)
- glutIdleFunc(idle);
- InitGL();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/shadow_sampler.c b/progs/glsl/shadow_sampler.c
deleted file mode 100644
index 0adc9d88ba..0000000000
--- a/progs/glsl/shadow_sampler.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/**
- * Test shadow2DRectProj() and shadow2D() functions.
- * Brian Paul
- * 11 April 2007
- */
-
-#define GL_GLEXT_PROTOTYPES
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-
-
-/** Use GL_RECTANGLE texture (with projective texcoords)? */
-#define USE_RECT 01
-
-#define TEXSIZE 16
-
-
-static char *FragProgFile = NULL;
-static char *VertProgFile = NULL;
-
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-static GLint uTexture2D;
-static GLint uTextureRect;
-
-static GLint win = 0;
-
-static GLenum Filter = GL_LINEAR;
-
-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
-PrintString(const char *s)
-{
- while (*s) {
- glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
- s++;
- }
-}
-
-
-static void
-Redisplay(void)
-{
- CheckError(__LINE__);
- glClear(GL_COLOR_BUFFER_BIT);
-
- glPushMatrix();
-
- CheckError(__LINE__);
- glUseProgram(program);
- CheckError(__LINE__);
-
- glBegin(GL_POLYGON);
-#if USE_RECT
- /* scale coords by two to test projection */
- glTexCoord4f( 0, 0, 0, 2.0); glVertex2f(-1, -1);
- glTexCoord4f(2*TEXSIZE, 0, 2*1, 2.0); glVertex2f( 1, -1);
- glTexCoord4f(2*TEXSIZE, 2*TEXSIZE, 2*1, 2.0); glVertex2f( 1, 1);
- glTexCoord4f( 0, 2*TEXSIZE, 0, 2.0); glVertex2f(-1, 1);
-#else
- glTexCoord3f(0, 0, 0); glVertex2f(-1, -1);
- glTexCoord3f(1, 0, 1); glVertex2f( 1, -1);
- glTexCoord3f(1, 1, 1); glVertex2f( 1, 1);
- glTexCoord3f(0, 1, 0); glVertex2f(-1, 1);
-#endif
- glEnd();
-
- glPopMatrix();
-
- glUseProgram(0);
- glWindowPos2iARB(80, 20);
- PrintString("white black white black");
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -8.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(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)
-{
- GLfloat image[TEXSIZE][TEXSIZE];
- GLuint i, j;
-
- for (i = 0; i < TEXSIZE; i++) {
- for (j = 0; j < TEXSIZE; j++) {
- if (j < (TEXSIZE / 2)) {
- image[i][j] = 0.25;
- }
- else {
- image[i][j] = 0.75;
- }
- }
- }
-
- glActiveTexture(GL_TEXTURE0); /* unit 0 */
- glBindTexture(GL_TEXTURE_2D, 42);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, TEXSIZE, TEXSIZE, 0,
- GL_DEPTH_COMPONENT, GL_FLOAT, image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
- GL_COMPARE_R_TO_TEXTURE_ARB);
- CheckError(__LINE__);
-
- glActiveTexture(GL_TEXTURE1); /* unit 1 */
- glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 43);
- glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT,
- TEXSIZE, 10, 0,/*16x10*/
- GL_DEPTH_COMPONENT, GL_FLOAT, image);
- glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, Filter);
- glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_COMPARE_MODE_ARB,
- GL_COMPARE_R_TO_TEXTURE_ARB);
- CheckError(__LINE__);
-}
-
-
-static void
-LoadAndCompileShader(GLuint shader, const char *text)
-{
- GLint stat;
- glShaderSource(shader, 1, (const GLchar **) &text, NULL);
- glCompileShader(shader);
- glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetShaderInfoLog(shader, 1000, &len, log);
- fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log);
- exit(1);
- }
-}
-
-
-/**
- * Read a shader from a file.
- */
-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, "fslight: Unable to open shader file %s\n", filename);
- exit(1);
- }
-
- n = fread(buffer, 1, max, f);
- printf("fslight: 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;
- glGetProgramiv(prog, GL_LINK_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetProgramInfoLog(prog, 1000, &len, log);
- fprintf(stderr, "Linker error:\n%s\n", log);
- }
-}
-
-
-static void
-Init(void)
-{
- static const char *fragShaderText =
- "uniform sampler2DShadow shadowTex2D; \n"
- "uniform sampler2DRectShadow shadowTexRect; \n"
- "void main() {\n"
-#if USE_RECT
- " gl_FragColor = shadow2DRectProj(shadowTexRect, gl_TexCoord[0]); \n"
-#else
- " gl_FragColor = shadow2D(shadowTex2D, gl_TexCoord[0].xyz); \n"
-#endif
- "}\n";
- static const char *vertShaderText =
- "void main() {\n"
- " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
- " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
- "}\n";
- const char *version;
-
-#if USE_RECT
- if (!glutExtensionSupported("GL_ARB_texture_rectangle")) {
- printf("This program requires GL_ARB_texture_rectangle\n");
- exit(1);
- }
-#endif
-
- version = (const char *) glGetString(GL_VERSION);
- if (version[0] != '2' || version[1] != '.') {
- printf("This program requires OpenGL 2.x, found %s\n", version);
- exit(1);
- }
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- fragShader = glCreateShader(GL_FRAGMENT_SHADER);
- if (FragProgFile)
- ReadShader(fragShader, FragProgFile);
- else
- LoadAndCompileShader(fragShader, fragShaderText);
-
- vertShader = glCreateShader(GL_VERTEX_SHADER);
- if (VertProgFile)
- ReadShader(vertShader, VertProgFile);
- else
- LoadAndCompileShader(vertShader, vertShaderText);
-
- program = glCreateProgram();
- glAttachShader(program, fragShader);
- glAttachShader(program, vertShader);
- glLinkProgram(program);
- CheckLink(program);
- glUseProgram(program);
-
- uTexture2D = glGetUniformLocation(program, "shadowTex2D");
- uTextureRect = glGetUniformLocation(program, "shadowTexRect");
- printf("uTexture2D %d uTextureRect %d\n", uTexture2D, uTextureRect);
- if (uTexture2D >= 0) {
- glUniform1i(uTexture2D, 0); /* use texture unit 0 */
- }
- if (uTextureRect >= 0) {
- glUniform1i(uTextureRect, 1); /* use texture unit 0 */
- }
- CheckError(__LINE__);
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
- glColor3f(1, 1, 1);
-
- MakeTexture();
- CheckError(__LINE__);
-}
-
-
-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);
- glutInitWindowSize(400, 300);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
-
-
diff --git a/progs/glsl/shadowtex.frag b/progs/glsl/shadowtex.frag
deleted file mode 100644
index a6a80da47f..0000000000
--- a/progs/glsl/shadowtex.frag
+++ /dev/null
@@ -1,21 +0,0 @@
-// Fragment shader for 2D texture with shadow attenuation
-// Brian Paul
-
-
-uniform sampler2D tex2d;
-uniform vec3 lightPos;
-
-void main()
-{
- // XXX should compute this from lightPos
- vec2 shadowCenter = vec2(-0.25, -0.25);
-
- // d = distance from center
- float d = distance(gl_TexCoord[0].xy, shadowCenter);
-
- // attenuate and clamp
- d = clamp(d * d * d, 0.0, 2.0);
-
- // modulate texture by d for shadow effect
- gl_FragColor = d * texture2D(tex2d, gl_TexCoord[0].xy, 0.0);
-}
diff --git a/progs/glsl/shtest.c b/progs/glsl/shtest.c
deleted file mode 100644
index 520eccfb6d..0000000000
--- a/progs/glsl/shtest.c
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
- * Simple shader test harness.
- * Brian Paul
- * 13 Aug 2009
- *
- * Usage:
- * shtest --vs vertShaderFile --fs fragShaderFile
- *
- * In this case the given vertex/frag shaders are read and compiled.
- * Random values are assigned to the uniforms.
- *
- * or:
- * shtest configFile
- *
- * In this case a config file is read that specifies the file names
- * of the shaders plus initial values for uniforms.
- *
- * Example config file:
- *
- * vs shader.vert
- * fs shader.frag
- * uniform pi 3.14159
- * uniform v1 1.0 0.5 0.2 0.3
- * texture 0 2D texture0.rgb
- * texture 1 CUBE texture1.rgb
- * texture 2 RECT texture2.rgb
- *
- */
-
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glu.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-#include "readtex.h"
-
-
-typedef enum
-{
- SPHERE,
- CUBE,
- NUM_SHAPES
-} shape;
-
-
-static char *FragShaderFile = NULL;
-static char *VertShaderFile = NULL;
-static char *ConfigFile = NULL;
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint Program;
-
-
-#define MAX_UNIFORMS 100
-static struct uniform_info Uniforms[MAX_UNIFORMS];
-static GLuint NumUniforms = 0;
-
-
-#define MAX_ATTRIBS 100
-static struct attrib_info Attribs[MAX_ATTRIBS];
-static GLuint NumAttribs = 0;
-
-
-/**
- * Config file info.
- */
-struct config_file
-{
- struct name_value
- {
- char name[100];
- float value[4];
- int type;
- } uniforms[100];
-
- int num_uniforms;
-};
-
-
-static GLint win = 0;
-static GLboolean Anim = GL_FALSE;
-static GLfloat TexRot = 0.0;
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
-static shape Object = SPHERE;
-
-
-static float
-RandomFloat(float min, float max)
-{
- int k = rand() % 10000;
- float x = min + (max - min) * k / 10000.0;
- return x;
-}
-
-
-/** Set new random values for uniforms */
-static void
-RandomUniformValues(void)
-{
- GLuint i;
- for (i = 0; i < NumUniforms; i++) {
- switch (Uniforms[i].type) {
- case GL_FLOAT:
- Uniforms[i].value[0] = RandomFloat(0.0, 1.0);
- break;
- case GL_SAMPLER_1D:
- case GL_SAMPLER_2D:
- case GL_SAMPLER_3D:
- case GL_SAMPLER_CUBE:
- case GL_SAMPLER_2D_RECT_ARB:
- /* don't change sampler values - random values are bad */
- break;
- default:
- Uniforms[i].value[0] = RandomFloat(-1.0, 2.0);
- Uniforms[i].value[1] = RandomFloat(-1.0, 2.0);
- Uniforms[i].value[2] = RandomFloat(-1.0, 2.0);
- Uniforms[i].value[3] = RandomFloat(-1.0, 2.0);
- }
- }
-}
-
-
-static void
-Idle(void)
-{
- yRot += 2.0;
- if (yRot > 360.0)
- yRot -= 360.0;
- glutPostRedisplay();
-}
-
-
-
-static void
-SquareVertex(GLfloat s, GLfloat t, GLfloat size)
-{
- GLfloat x = -size + s * 2.0 * size;
- GLfloat y = -size + t * 2.0 * size;
- GLuint i;
-
- glMultiTexCoord2f(GL_TEXTURE0, s, t);
- glMultiTexCoord2f(GL_TEXTURE1, s, t);
- glMultiTexCoord2f(GL_TEXTURE2, s, t);
- glMultiTexCoord2f(GL_TEXTURE3, s, t);
-
- /* assign (s,t) to the generic attributes */
- for (i = 0; i < NumAttribs; i++) {
- if (Attribs[i].location >= 0) {
- glVertexAttrib2f(Attribs[i].location, s, t);
- }
- }
-
- glVertex2f(x, y);
-}
-
-
-/*
- * Draw a square, specifying normal and tangent vectors.
- */
-static void
-Square(GLfloat size)
-{
- GLint tangentAttrib = 1;
- glNormal3f(0, 0, 1);
- glVertexAttrib3f(tangentAttrib, 1, 0, 0);
- glBegin(GL_POLYGON);
-#if 1
- SquareVertex(0, 0, size);
- SquareVertex(1, 0, size);
- SquareVertex(1, 1, size);
- SquareVertex(0, 1, size);
-#else
- glTexCoord2f(0, 0); glVertex2f(-size, -size);
- glTexCoord2f(1, 0); glVertex2f( size, -size);
- glTexCoord2f(1, 1); glVertex2f( size, size);
- glTexCoord2f(0, 1); glVertex2f(-size, size);
-#endif
- glEnd();
-}
-
-
-static void
-Cube(GLfloat size)
-{
- /* +X */
- glPushMatrix();
- glRotatef(90, 0, 1, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* -X */
- glPushMatrix();
- glRotatef(-90, 0, 1, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* +Y */
- glPushMatrix();
- glRotatef(90, 1, 0, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* -Y */
- glPushMatrix();
- glRotatef(-90, 1, 0, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
-
- /* +Z */
- glPushMatrix();
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-
- /* -Z */
- glPushMatrix();
- glRotatef(180, 0, 1, 0);
- glTranslatef(0, 0, size);
- Square(size);
- glPopMatrix();
-}
-
-
-static void
-Sphere(GLfloat radius, GLint slices, GLint stacks)
-{
- static GLUquadricObj *q = NULL;
-
- if (!q) {
- q = gluNewQuadric();
- gluQuadricDrawStyle(q, GLU_FILL);
- gluQuadricNormals(q, GLU_SMOOTH);
- gluQuadricTexture(q, GL_TRUE);
- }
-
- gluSphere(q, radius, slices, stacks);
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glRotatef(TexRot, 0.0f, 1.0f, 0.0f);
- glMatrixMode(GL_MODELVIEW);
-
- if (Object == SPHERE) {
- Sphere(2.5, 20, 10);
- }
- else if (Object == CUBE) {
- Cube(2.0);
- }
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(Program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 2.0;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(Idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'z':
- zRot += step;
- break;
- case 'Z':
- zRot -= step;
- break;
- case 'o':
- Object = (Object + 1) % NUM_SHAPES;
- break;
- case 'r':
- RandomUniformValues();
- SetUniformValues(Program, Uniforms);
- PrintUniforms(Uniforms);
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 2.0;
-
- (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
-InitUniforms(const struct config_file *conf,
- struct uniform_info uniforms[])
-{
- int i;
-
- for (i = 0; i < conf->num_uniforms; i++) {
- int j;
- for (j = 0; uniforms[j].name; j++) {
- if (strcmp(uniforms[j].name, conf->uniforms[i].name) == 0) {
- uniforms[j].type = conf->uniforms[i].type;
- uniforms[j].value[0] = conf->uniforms[i].value[0];
- uniforms[j].value[1] = conf->uniforms[i].value[1];
- uniforms[j].value[2] = conf->uniforms[i].value[2];
- uniforms[j].value[3] = conf->uniforms[i].value[3];
- }
- }
- }
-}
-
-
-static void
-LoadTexture(GLint unit, GLenum target, const char *texFileName)
-{
- GLint imgWidth, imgHeight;
- GLenum imgFormat;
- GLubyte *image = NULL;
- GLuint tex;
- GLenum filter = GL_LINEAR;
- GLenum objTarget;
-
- image = LoadRGBImage(texFileName, &imgWidth, &imgHeight, &imgFormat);
- if (!image) {
- printf("Couldn't read %s\n", texFileName);
- exit(1);
- }
-
- printf("Load Texture: unit %d, target 0x%x: %s %d x %d\n",
- unit, target, texFileName, imgWidth, imgHeight);
-
- if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) {
- objTarget = GL_TEXTURE_CUBE_MAP;
- }
- else {
- objTarget = target;
- }
-
- glActiveTexture(GL_TEXTURE0 + unit);
- glGenTextures(1, &tex);
- glBindTexture(objTarget, tex);
-
- if (target == GL_TEXTURE_3D) {
- /* depth=1 */
- gluBuild3DMipmaps(target, 4, imgWidth, imgHeight, 1,
- imgFormat, GL_UNSIGNED_BYTE, image);
- }
- else if (target == GL_TEXTURE_1D) {
- gluBuild1DMipmaps(target, 4, imgWidth,
- imgFormat, GL_UNSIGNED_BYTE, image);
- }
- else {
- gluBuild2DMipmaps(target, 4, imgWidth, imgHeight,
- imgFormat, GL_UNSIGNED_BYTE, image);
- }
-
- free(image);
-
- glTexParameteri(objTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(objTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(objTarget, GL_TEXTURE_MIN_FILTER, filter);
- glTexParameteri(objTarget, 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_1D", GL_SAMPLER_1D },
- { "GL_SAMPLER_2D", GL_SAMPLER_2D },
- { "GL_SAMPLER_3D", GL_SAMPLER_3D },
- { "GL_SAMPLER_CUBE", GL_SAMPLER_CUBE },
- { "GL_SAMPLER_2D_RECT", GL_SAMPLER_2D_RECT_ARB },
- { 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.
- */
-static void
-ReadConfigFile(const char *filename, struct config_file *conf)
-{
- char line[1000];
- FILE *f;
-
- f = fopen(filename, "r");
- if (!f) {
- fprintf(stderr, "Unable to open config file %s\n", filename);
- exit(1);
- }
-
- conf->num_uniforms = 0;
-
- /* ugly but functional parser */
- while (fgets(line, sizeof(line), f) != NULL) {
- if (line[0]) {
- if (strncmp(line, "vs ", 3) == 0) {
- VertShaderFile = strdup(line + 3);
- VertShaderFile[strlen(VertShaderFile) - 1] = 0;
- }
- else if (strncmp(line, "fs ", 3) == 0) {
- FragShaderFile = strdup(line + 3);
- FragShaderFile[strlen(FragShaderFile) - 1] = 0;
- }
- else if (strncmp(line, "texture ", 8) == 0) {
- char target[100], texFileName[100];
- int unit, k;
- k = sscanf(line + 8, "%d %s %s", &unit, target, texFileName);
- assert(k == 3 || k == 8);
- if (strcmp(target, "CUBE") == 0) {
- char texFileNames[6][100];
- k = sscanf(line + 8, "%d %s %s %s %s %s %s %s",
- &unit, target,
- texFileNames[0],
- texFileNames[1],
- texFileNames[2],
- texFileNames[3],
- texFileNames[4],
- texFileNames[5]);
- LoadTexture(unit, GL_TEXTURE_CUBE_MAP_POSITIVE_X, texFileNames[0]);
- LoadTexture(unit, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, texFileNames[1]);
- LoadTexture(unit, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, texFileNames[2]);
- LoadTexture(unit, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, texFileNames[3]);
- LoadTexture(unit, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, texFileNames[4]);
- LoadTexture(unit, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, texFileNames[5]);
- }
- else if (!strcmp(target, "2D")) {
- LoadTexture(unit, GL_TEXTURE_2D, texFileName);
- }
- else if (!strcmp(target, "3D")) {
- LoadTexture(unit, GL_TEXTURE_3D, texFileName);
- }
- else if (!strcmp(target, "RECT")) {
- LoadTexture(unit, GL_TEXTURE_RECTANGLE_ARB, texFileName);
- }
- else {
- printf("Bad texture target: %s\n", target);
- exit(1);
- }
- }
- else if (strncmp(line, "uniform ", 8) == 0) {
- char name[1000], typeName[100];
- int k;
- float v1 = 0.0F, v2 = 0.0F, v3 = 0.0F, v4 = 0.0F;
- GLenum type;
-
- k = sscanf(line + 8, "%s %s %f %f %f %f", name, typeName,
- &v1, &v2, &v3, &v4);
-
- type = TypeFromName(typeName);
-
- if (strlen(name) + 1 > sizeof(conf->uniforms[conf->num_uniforms].name)) {
- fprintf(stderr, "string overflow\n");
- exit(1);
- }
- strcpy(conf->uniforms[conf->num_uniforms].name, name);
- conf->uniforms[conf->num_uniforms].value[0] = v1;
- conf->uniforms[conf->num_uniforms].value[1] = v2;
- conf->uniforms[conf->num_uniforms].value[2] = v3;
- conf->uniforms[conf->num_uniforms].value[3] = v4;
- conf->uniforms[conf->num_uniforms].type = type;
- conf->num_uniforms++;
- }
- else {
- if (strlen(line) > 1) {
- fprintf(stderr, "syntax error in: %s\n", line);
- break;
- }
- }
- }
- }
-
- fclose(f);
-}
-
-
-static void
-Init(void)
-{
- GLdouble vertTime, fragTime, linkTime;
- struct config_file config;
-
- memset(&config, 0, sizeof(config));
-
- if (ConfigFile)
- ReadConfigFile(ConfigFile, &config);
-
- if (!VertShaderFile) {
- fprintf(stderr, "Error: no vertex shader\n");
- exit(1);
- }
-
- if (!FragShaderFile) {
- fprintf(stderr, "Error: no fragment shader\n");
- exit(1);
- }
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertShaderFile);
- vertTime = GetShaderCompileTime();
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragShaderFile);
- fragTime = GetShaderCompileTime();
-
- Program = LinkShaders(vertShader, fragShader);
- linkTime = GetShaderLinkTime();
-
- printf("Read vert shader %s\n", VertShaderFile);
- printf("Read frag shader %s\n", FragShaderFile);
-
- printf("Time to compile vertex shader: %fs\n", vertTime);
- printf("Time to compile fragment shader: %fs\n", fragTime);
- printf("Time to link shaders: %fs\n", linkTime);
-
- assert(ValidateShaderProgram(Program));
-
- glUseProgram(Program);
-
- NumUniforms = GetUniforms(Program, Uniforms);
- if (config.num_uniforms) {
- InitUniforms(&config, Uniforms);
- }
- else {
- RandomUniformValues();
- }
- SetUniformValues(Program, Uniforms);
- PrintUniforms(Uniforms);
-
- NumAttribs = GetAttribs(Program, Attribs);
- PrintAttribs(Attribs);
-
- /* assert(glGetError() == 0); */
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- glEnable(GL_DEPTH_TEST);
-
- glColor3f(1, 0, 0);
-}
-
-
-static void
-Keys(void)
-{
- printf("Keyboard:\n");
- printf(" a Animation toggle\n");
- printf(" r Randomize uniform values\n");
- printf(" o Change object\n");
- printf(" arrows Rotate object\n");
- printf(" ESC Exit\n");
-}
-
-
-static void
-Usage(void)
-{
- printf("Usage:\n");
- printf(" shtest config.shtest\n");
- printf(" Run w/ given config file.\n");
- printf(" shtest --vs vertShader --fs fragShader\n");
- printf(" Load/compile given shaders.\n");
-}
-
-
-static void
-ParseOptions(int argc, char *argv[])
-{
- int i;
-
- if (argc == 1) {
- Usage();
- exit(1);
- }
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "--fs") == 0) {
- FragShaderFile = argv[i+1];
- i++;
- }
- else if (strcmp(argv[i], "--vs") == 0) {
- VertShaderFile = argv[i+1];
- i++;
- }
- else {
- /* assume the arg is a config file */
- ConfigFile = argv[i];
- break;
- }
- }
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInitWindowSize(400, 400);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- Keys();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/simple.vert b/progs/glsl/simple.vert
deleted file mode 100644
index a0abe0dc0b..0000000000
--- a/progs/glsl/simple.vert
+++ /dev/null
@@ -1,9 +0,0 @@
-// Simple vertex shader
-// Brian Paul
-
-
-void main()
-{
- gl_TexCoord[0] = gl_MultiTexCoord0;
- gl_Position = ftransform();
-}
diff --git a/progs/glsl/skinning.c b/progs/glsl/skinning.c
deleted file mode 100644
index 2b96f31d06..0000000000
--- a/progs/glsl/skinning.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- * Vertex "skinning" example.
- * The idea is there are multiple modeling matrices applied to every
- * vertex. Weighting values in [0,1] control the influence of each
- * matrix on each vertex.
- *
- * 4 Nov 2008
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-#ifndef M_PI
-#define M_PI 3.1415926535
-#endif
-
-static char *FragProgFile = "skinning.frag";
-static char *VertProgFile = "skinning.vert";
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-
-static GLint win = 0;
-static GLboolean Anim = GL_TRUE;
-static GLboolean WireFrame = GL_TRUE;
-static GLfloat xRot = 0.0f, yRot = 90.0f, zRot = 0.0f;
-
-#define NUM_MATS 2
-
-static GLfloat Matrices[NUM_MATS][16];
-static GLint uMat0, uMat1;
-static GLint WeightAttr;
-
-
-static void
-Idle(void)
-{
- yRot = 90 + glutGet(GLUT_ELAPSED_TIME) * 0.005;
- glutPostRedisplay();
-}
-
-
-static void
-Cylinder(GLfloat length, GLfloat radius, GLint slices, GLint stacks)
-{
- float dw = 1.0 / (stacks - 1);
- float dz = length / stacks;
- int i, j;
-
- for (j = 0; j < stacks; j++) {
- float w0 = j * dw;
- float z0 = j * dz;
-
- glBegin(GL_TRIANGLE_STRIP);
- for (i = 0; i < slices; i++) {
- float a = (float) i / (slices - 1) * M_PI * 2.0;
- float x = radius * cos(a);
- float y = radius * sin(a);
- glVertexAttrib1f(WeightAttr, w0);
- glNormal3f(x, y, 0.0);
- glVertex3f(x, y, z0);
-
- glVertexAttrib1f(WeightAttr, w0 + dw);
- glNormal3f(x, y, 0.0);
- glVertex3f(x, y, z0 + dz);
- }
- glEnd();
- }
-}
-
-
-/**
- * Update/animate the two matrices. One rotates, the other scales.
- */
-static void
-UpdateMatrices(void)
-{
- GLfloat t = glutGet(GLUT_ELAPSED_TIME) * 0.0025;
- GLfloat scale = 0.5 * (1.1 + sin(0.5 * t));
- GLfloat rot = cos(t) * 90.0;
-
- glPushMatrix();
- glLoadIdentity();
- glScalef(1.0, scale, 1.0);
- glGetFloatv(GL_MODELVIEW_MATRIX, Matrices[0]);
- glPopMatrix();
-
- glPushMatrix();
- glLoadIdentity();
- glRotatef(rot, 0, 0, 1);
- glGetFloatv(GL_MODELVIEW_MATRIX, Matrices[1]);
- glPopMatrix();
-}
-
-
-static void
-Redisplay(void)
-{
- UpdateMatrices();
-
- glUniformMatrix4fv(uMat0, 1, GL_FALSE, Matrices[0]);
- glUniformMatrix4fv(uMat1, 1, GL_FALSE, Matrices[1]);
-
- if (WireFrame)
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glPushMatrix();
- glTranslatef(0, 0, -2.5);
- Cylinder(5.0, 1.0, 10, 20);
- glPopMatrix();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 2.0;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(Idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'w':
- WireFrame = !WireFrame;
- break;
- case 'z':
- zRot += step;
- break;
- case 'Z':
- zRot -= step;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 2.0;
-
- (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)
-{
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- uMat0 = glGetUniformLocation(program, "mat0");
- uMat1 = glGetUniformLocation(program, "mat1");
-
- WeightAttr = glGetAttribLocation(program, "weight");
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- glEnable(GL_DEPTH_TEST);
-
- 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);
- glutInitWindowSize(500, 500);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- if (Anim)
- glutIdleFunc(Idle);
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/skinning.frag b/progs/glsl/skinning.frag
deleted file mode 100644
index 9053755a83..0000000000
--- a/progs/glsl/skinning.frag
+++ /dev/null
@@ -1,6 +0,0 @@
-// color pass-through
-
-void main()
-{
- gl_FragColor = gl_Color;
-}
diff --git a/progs/glsl/skinning.vert b/progs/glsl/skinning.vert
deleted file mode 100644
index 28970eee58..0000000000
--- a/progs/glsl/skinning.vert
+++ /dev/null
@@ -1,24 +0,0 @@
-// Vertex weighting/blendin shader
-// Brian Paul
-// 4 Nov 2008
-
-uniform mat4 mat0, mat1;
-attribute float weight;
-
-void main()
-{
- // simple diffuse shading
- // Note that we should really transform the normal vector along with
- // the postion below... someday.
- vec3 lightVec = vec3(0, 0, 1);
- vec3 norm = gl_NormalMatrix * gl_Normal;
- float dot = 0.2 + max(0.0, dot(norm, lightVec));
- gl_FrontColor = vec4(dot);
-
- // compute sum of weighted transformations
- vec4 pos0 = mat0 * gl_Vertex;
- vec4 pos1 = mat1 * gl_Vertex;
- vec4 pos = mix(pos0, pos1, weight);
-
- gl_Position = gl_ModelViewProjectionMatrix * pos;
-}
diff --git a/progs/glsl/texaaline.c b/progs/glsl/texaaline.c
deleted file mode 100644
index 00edab7310..0000000000
--- a/progs/glsl/texaaline.c
+++ /dev/null
@@ -1,372 +0,0 @@
-/**
- * AA lines with texture mapped quads
- *
- * Brian Paul
- * 9 Feb 2008
- */
-
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-
-#ifndef M_PI
-#define M_PI 3.1415926535
-#endif
-
-static GLint WinWidth = 300, WinHeight = 300;
-static GLint win = 0;
-static GLfloat Width = 8.;
-
-/*
- * Quad strip for line from v0 to v1:
- *
- 1 3 5 7
- +---+---------------------+---+
- | |
- | *v0 v1* |
- | |
- +---+---------------------+---+
- 0 2 4 6
- */
-static void
-QuadLine(const GLfloat *v0, const GLfloat *v1, GLfloat width)
-{
- GLfloat dx = v1[0] - v0[0];
- GLfloat dy = v1[1] - v0[1];
- GLfloat len = sqrt(dx*dx + dy*dy);
- float dx0, dx1, dx2, dx3, dx4, dx5, dx6, dx7;
- float dy0, dy1, dy2, dy3, dy4, dy5, dy6, dy7;
-
- dx /= len;
- dy /= len;
-
- width *= 0.5; /* half width */
- dx = dx * (width + 0.0);
- dy = dy * (width + 0.0);
-
- dx0 = -dx+dy; dy0 = -dy-dx;
- dx1 = -dx-dy; dy1 = -dy+dx;
-
- dx2 = 0+dy; dy2 = -dx+0;
- dx3 = 0-dy; dy3 = +dx+0;
-
- dx4 = 0+dy; dy4 = -dx+0;
- dx5 = 0-dy; dy5 = +dx+0;
-
- dx6 = dx+dy; dy6 = dy-dx;
- dx7 = dx-dy; dy7 = dy+dx;
-
- /*
- printf("dx, dy = %g, %g\n", dx, dy);
- printf(" dx0, dy0: %g, %g\n", dx0, dy0);
- printf(" dx1, dy1: %g, %g\n", dx1, dy1);
- printf(" dx2, dy2: %g, %g\n", dx2, dy2);
- printf(" dx3, dy3: %g, %g\n", dx3, dy3);
- */
-
- glBegin(GL_QUAD_STRIP);
- glTexCoord2f(0, 0);
- glVertex2f(v0[0] + dx0, v0[1] + dy0);
- glTexCoord2f(0, 1);
- glVertex2f(v0[0] + dx1, v0[1] + dy1);
-
- glTexCoord2f(0.5, 0);
- glVertex2f(v0[0] + dx2, v0[1] + dy2);
- glTexCoord2f(0.5, 1);
- glVertex2f(v0[0] + dx3, v0[1] + dy3);
-
- glTexCoord2f(0.5, 0);
- glVertex2f(v1[0] + dx2, v1[1] + dy2);
- glTexCoord2f(0.5, 1);
- glVertex2f(v1[0] + dx3, v1[1] + dy3);
-
- glTexCoord2f(1, 0);
- glVertex2f(v1[0] + dx6, v1[1] + dy6);
- glTexCoord2f(1, 1);
- glVertex2f(v1[0] + dx7, v1[1] + dy7);
- glEnd();
-}
-
-
-static float Cos(float a)
-{
- return cos(a * M_PI / 180.);
-}
-
-static float Sin(float a)
-{
- return sin(a * M_PI / 180.);
-}
-
-static void
-Redisplay(void)
-{
- float cx = 0.5 * WinWidth, cy = 0.5 * WinHeight;
- float len = 0.5 * WinWidth - 20.0;
- int i;
-
- glClear(GL_COLOR_BUFFER_BIT);
-
- glColor3f(1, 1, 1);
-
- glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
-
- for (i = 0; i < 360; i+=5) {
- float v0[2], v1[2];
- v0[0] = cx + 40 * Cos(i);
- v0[1] = cy + 40 * Sin(i);
- v1[0] = cx + len * Cos(i);
- v1[1] = cy + len * Sin(i);
- QuadLine(v0, v1, Width);
- }
-
- {
- float v0[2], v1[2], x;
- for (x = 0; x < 1.0; x += 0.2) {
- v0[0] = cx + x;
- v0[1] = cy + x * 40 - 20;
- v1[0] = cx + x + 5.0;
- v1[1] = cy + x * 40 - 20;
- QuadLine(v0, v1, Width);
- }
- }
-
- glDisable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- WinWidth = width;
- WinHeight = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, 0, height, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-CleanUp(void)
-{
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- (void) x;
- (void) y;
-
- switch(key) {
- case 'w':
- Width -= 0.5;
- break;
- case 'W':
- Width += 0.5;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
-#if 0
- if (Width < 3)
- Width = 3;
-#endif
- printf("Width = %g\n", Width);
- glutPostRedisplay();
-}
-
-
-static float
-ramp4(GLint i, GLint size)
-{
- float d;
- if (i < 4 ) {
- d = i / 4.0;
- }
- else if (i >= size - 5) {
- d = 1.0 - (i - (size - 5)) / 4.0;
- }
- else {
- d = 1.0;
- }
- return d;
-}
-
-static float
-ramp2(GLint i, GLint size)
-{
- float d;
- if (i < 2 ) {
- d = i / 2.0;
- }
- else if (i >= size - 3) {
- d = 1.0 - (i - (size - 3)) / 2.0;
- }
- else {
- d = 1.0;
- }
- return d;
-}
-
-static float
-ramp1(GLint i, GLint size)
-{
- float d;
- if (i == 0 || i == size-1) {
- d = 0.0;
- }
- else {
- d = 1.0;
- }
- return d;
-}
-
-
-/**
- * Make an alpha texture for antialiasing lines.
- * Just a linear fall-off ramp for now.
- * Should have a number of different textures for different line widths.
- * Could try a bell-like-curve....
- */
-static void
-MakeTexture(void)
-{
-#define SZ 8
- GLfloat tex[SZ][SZ]; /* alpha tex */
- int i, j;
- for (i = 0; i < SZ; i++) {
- for (j = 0; j < SZ; j++) {
-#if 0
- float k = (SZ-1) / 2.0;
- float dx = fabs(i - k) / k;
- float dy = fabs(j - k) / k;
- float d;
-
- dx = 1.0 - dx;
- dy = 1.0 - dy;
- d = dx * dy;
-
-#else
- float d = ramp1(i, SZ) * ramp1(j, SZ);
- printf("%d, %d: %g\n", i, j, d);
-#endif
- tex[i][j] = d;
- }
- }
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, SZ, SZ, 0, GL_ALPHA, GL_FLOAT, tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-#undef SZ
-}
-
-
-static void
-MakeMipmap(void)
-{
-#define SZ 64
- GLfloat tex[SZ][SZ]; /* alpha tex */
- int level;
-
- glPixelStorei(GL_UNPACK_ROW_LENGTH, SZ);
- for (level = 0; level < 7; level++) {
- int sz = 1 << (6 - level);
- int i, j;
- for (i = 0; i < sz; i++) {
- for (j = 0; j < sz; j++) {
- if (level == 6)
- tex[i][j] = 1.0;
- else if (level == 5)
- tex[i][j] = 0.5;
- else
- tex[i][j] = ramp1(i, sz) * ramp1(j, sz);
- }
- }
-
- glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA,
- sz, sz, 0, GL_ALPHA, GL_FLOAT, tex);
- }
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); */
- /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5); */
-
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-#undef SZ
-}
-
-
-static void
-Init(void)
-{
- const char *version;
-
- (void) MakeTexture;
- (void) ramp4;
- (void) ramp2;
-
- version = (const char *) glGetString(GL_VERSION);
- if (version[0] != '2' || version[1] != '.') {
- printf("This program requires OpenGL 2.x, found %s\n", version);
- exit(1);
- }
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-#if 0
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-#elif 0
- MakeTexture();
-#else
- MakeMipmap();
-#endif
-}
-
-
-static void
-ParseOptions(int argc, char *argv[])
-{
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/texdemo1.c b/progs/glsl/texdemo1.c
deleted file mode 100644
index 2076e6aef9..0000000000
--- a/progs/glsl/texdemo1.c
+++ /dev/null
@@ -1,438 +0,0 @@
-/**
- * Test texturing with GL shading language.
- *
- * Copyright (C) 2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <GL/glew.h>
-#include "GL/glut.h"
-#include "readtex.h"
-#include "shaderutil.h"
-
-static const char *Demo = "texdemo1";
-
-static const char *ReflectVertFile = "reflect.vert";
-static const char *CubeFragFile = "cubemap.frag";
-
-static const char *SimpleVertFile = "simple.vert";
-static const char *SimpleTexFragFile = "shadowtex.frag";
-
-static const char *GroundImage = "../images/tile.rgb";
-
-static GLuint Program1, Program2;
-
-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[] = {
- { "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_SAMPLER_2D, { 1, 0, 0, 0 }, -1 },
- { "lightPos", 1, GL_FLOAT_VEC3, { 10, 10, 20, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-
-static void
-DrawGround(GLfloat size)
-{
- glPushMatrix();
- glRotatef(90, 1, 0, 0);
- glNormal3f(0, 0, 1);
- glBegin(GL_POLYGON);
- glTexCoord2f(-2, -2); glVertex2f(-size, -size);
- glTexCoord2f( 2, -2); glVertex2f( size, -size);
- glTexCoord2f( 2, 2); glVertex2f( size, size);
- glTexCoord2f(-2, 2); glVertex2f(-size, size);
- glEnd();
- glPopMatrix();
-}
-
-
-static void
-draw(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glEnable(GL_TEXTURE_2D);
-
- glPushMatrix(); /* modelview matrix */
- glTranslatef(0.0, 0.0, -EyeDist);
- glRotatef(Xrot, 1, 0, 0);
- glRotatef(Yrot, 0, 1, 0);
- glRotatef(Zrot, 0, 0, 1);
-
- /* sphere w/ reflection map */
- glPushMatrix();
- glTranslatef(0, 1, 0);
- glUseProgram(Program1);
-
- /* setup texture matrix */
- glActiveTexture(GL_TEXTURE0);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glRotatef(-TexYrot, 0, 1, 0);
- glRotatef(-TexXrot, 1, 0, 0);
-
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glEnable(GL_TEXTURE_GEN_R);
- glutSolidSphere(2.0, 20, 20);
-
- glLoadIdentity(); /* texture matrix */
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
- /* ground */
- glUseProgram(Program2);
- glTranslatef(0, -1.0, 0);
- DrawGround(5);
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-idle(void)
-{
- GLfloat t = 0.05 * glutGet(GLUT_ELAPSED_TIME);
- TexYrot = t;
- glutPostRedisplay();
-}
-
-
-static void
-key(unsigned char k, int x, int y)
-{
- (void) x;
- (void) y;
- switch (k) {
- case ' ':
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'z':
- EyeDist -= 0.5;
- if (EyeDist < 6.0)
- EyeDist = 6.0;
- break;
- case 'Z':
- EyeDist += 0.5;
- if (EyeDist > 90.0)
- EyeDist = 90;
- break;
- case 27:
- glutDestroyWindow(win);
- exit(0);
- }
- glutPostRedisplay();
-}
-
-
-static void
-specialkey(int key, int x, int y)
-{
- GLfloat step = 2.0;
- (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();
-}
-
-
-/* new window size or exposure */
-static void
-Reshape(int width, int height)
-{
- GLfloat ar = (float) width / (float) height;
- glViewport(0, 0, (GLint)width, (GLint)height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-2.0*ar, 2.0*ar, -2.0, 2.0, 4.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-InitCheckers(void)
-{
-#define CUBE_TEX_SIZE 64
- GLubyte image[CUBE_TEX_SIZE][CUBE_TEX_SIZE][3];
- static const GLubyte colors[6][3] = {
- { 255, 0, 0 }, /* face 0 - red */
- { 0, 255, 255 }, /* face 1 - cyan */
- { 0, 255, 0 }, /* face 2 - green */
- { 255, 0, 255 }, /* face 3 - purple */
- { 0, 0, 255 }, /* face 4 - blue */
- { 255, 255, 0 } /* face 5 - yellow */
- };
- static const GLenum targets[6] = {
- GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
- GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
- GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
- GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
- GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
- };
-
- GLint i, j, f;
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- /* make colored checkerboard cube faces */
- for (f = 0; f < 6; f++) {
- for (i = 0; i < CUBE_TEX_SIZE; i++) {
- for (j = 0; j < CUBE_TEX_SIZE; j++) {
- if ((i/4 + j/4) & 1) {
- image[i][j][0] = colors[f][0];
- image[i][j][1] = colors[f][1];
- image[i][j][2] = colors[f][2];
- }
- else {
- image[i][j][0] = 255;
- image[i][j][1] = 255;
- image[i][j][2] = 255;
- }
- }
- }
-
- glTexImage2D(targets[f], 0, GL_RGB, CUBE_TEX_SIZE, CUBE_TEX_SIZE, 0,
- GL_RGB, GL_UNSIGNED_BYTE, image);
- }
-}
-
-
-static void
-LoadFace(GLenum target, const char *filename,
- GLboolean flipTB, GLboolean flipLR)
-{
- GLint w, h;
- GLenum format;
- GLubyte *img = LoadRGBImage(filename, &w, &h, &format);
- if (!img) {
- printf("Error: couldn't load texture image %s\n", filename);
- exit(1);
- }
- assert(format == GL_RGB);
-
- /* <sigh> the way the texture cube mapping works, we have to flip
- * images to make things look right.
- */
- if (flipTB) {
- const int stride = 3 * w;
- GLubyte temp[3*1024];
- int i;
- for (i = 0; i < h / 2; i++) {
- memcpy(temp, img + i * stride, stride);
- memcpy(img + i * stride, img + (h - i - 1) * stride, stride);
- memcpy(img + (h - i - 1) * stride, temp, stride);
- }
- }
- if (flipLR) {
- const int stride = 3 * w;
- GLubyte temp[3];
- GLubyte *row;
- int i, j;
- for (i = 0; i < h; i++) {
- row = img + i * stride;
- for (j = 0; j < w / 2; j++) {
- int k = w - j - 1;
- temp[0] = row[j*3+0];
- temp[1] = row[j*3+1];
- temp[2] = row[j*3+2];
- row[j*3+0] = row[k*3+0];
- row[j*3+1] = row[k*3+1];
- row[j*3+2] = row[k*3+2];
- row[k*3+0] = temp[0];
- row[k*3+1] = temp[1];
- row[k*3+2] = temp[2];
- }
- }
- }
-
- gluBuild2DMipmaps(target, GL_RGB, w, h, format, GL_UNSIGNED_BYTE, img);
- free(img);
-}
-
-
-static void
-LoadEnvmaps(void)
-{
- LoadFace(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, "right.rgb", GL_TRUE, GL_FALSE);
- LoadFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, "left.rgb", GL_TRUE, GL_FALSE);
- LoadFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, "top.rgb", GL_FALSE, GL_TRUE);
- LoadFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, "bottom.rgb", GL_FALSE, GL_TRUE);
- LoadFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, "front.rgb", GL_TRUE, GL_FALSE);
- LoadFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, "back.rgb", GL_TRUE, GL_FALSE);
-}
-
-
-static void
-InitTextures(GLboolean useImageFiles)
-{
- GLenum filter;
-
- /*
- * Env map
- */
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_CUBE_MAP, 1);
- if (useImageFiles) {
- LoadEnvmaps();
- filter = GL_LINEAR;
- }
- else {
- InitCheckers();
- filter = GL_NEAREST;
- }
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, filter);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, filter);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- /*
- * Ground texture
- */
- {
- GLint imgWidth, imgHeight;
- GLenum imgFormat;
- GLubyte *image = NULL;
-
- image = LoadRGBImage(GroundImage, &imgWidth, &imgHeight, &imgFormat);
- if (!image) {
- printf("Couldn't read %s\n", GroundImage);
- exit(0);
- }
-
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, 2);
- gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 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, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- }
-}
-
-
-static GLuint
-CreateProgram(const char *vertProgFile, const char *fragProgFile,
- struct uniform_info *uniforms)
-{
- GLuint fragShader, vertShader, program;
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, vertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, fragProgFile);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- SetUniformValues(program, uniforms);
- PrintUniforms(uniforms);
-
- return program;
-}
-
-
-static void
-InitPrograms(void)
-{
- Program1 = CreateProgram(ReflectVertFile, CubeFragFile, ReflectUniforms);
- Program2 = CreateProgram(SimpleVertFile, SimpleTexFragFile, SimpleUniforms);
-}
-
-
-static void
-Init(GLboolean useImageFiles)
-{
- if (!ShadersSupported()) {
- exit(1);
- }
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- InitTextures(useImageFiles);
- InitPrograms();
-
- glEnable(GL_DEPTH_TEST);
-
- glClearColor(.6, .6, .9, 0);
- glColor3f(1.0, 1.0, 1.0);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(500, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- win = glutCreateWindow(Demo);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(key);
- glutSpecialFunc(specialkey);
- glutDisplayFunc(draw);
- if (Anim)
- glutIdleFunc(idle);
- if (argc > 1 && strcmp(argv[1] , "-i") == 0)
- Init(1);
- else
- Init(0);
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/toyball.c b/progs/glsl/toyball.c
deleted file mode 100644
index c502f24077..0000000000
--- a/progs/glsl/toyball.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/**
- * "Toy Ball" shader demo. Uses the example shaders from
- * chapter 11 of the OpenGL Shading Language "orange" book.
- * 16 Jan 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static char *FragProgFile = "CH11-toyball.frag";
-static char *VertProgFile = "CH11-toyball.vert";
-
-/* program/shader objects */
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-
-static struct uniform_info Uniforms[] = {
- { "LightDir", 1, GL_FLOAT_VEC4, { 0.57737, 0.57735, 0.57735, 0.0 }, -1 },
- { "HVector", 1, GL_FLOAT_VEC4, { 0.32506, 0.32506, 0.88808, 0.0 }, -1 },
- { "BallCenter", 1, GL_FLOAT_VEC4, { 0.0, 0.0, 0.0, 1.0 }, -1 },
- { "SpecularColor", 1, GL_FLOAT_VEC4, { 0.4, 0.4, 0.4, 60.0 }, -1 },
- { "Red", 1, GL_FLOAT_VEC4, { 0.6, 0.0, 0.0, 1.0 }, -1 },
- { "Blue", 1, GL_FLOAT_VEC4, { 0.0, 0.3, 0.6, 1.0 }, -1 },
- { "Yellow", 1, GL_FLOAT_VEC4, { 0.6, 0.5, 0.0, 1.0 }, -1 },
- { "HalfSpace0", 1, GL_FLOAT_VEC4, { 1.0, 0.0, 0.0, 0.2 }, -1 },
- { "HalfSpace1", 1, GL_FLOAT_VEC4, { 0.309016994, 0.951056516, 0.0, 0.2 }, -1 },
- { "HalfSpace2", 1, GL_FLOAT_VEC4, { -0.809016994, 0.587785252, 0.0, 0.2 }, -1 },
- { "HalfSpace3", 1, GL_FLOAT_VEC4, { -0.809016994, -0.587785252, 0.0, 0.2 }, -1 },
- { "HalfSpace4", 1, GL_FLOAT_VEC4, { 0.309116994, -0.951056516, 0.0, 0.2 }, -1 },
- { "InOrOutInit", 1, GL_FLOAT, { -3.0, 0, 0, 0 }, -1 },
- { "StripeWidth", 1, GL_FLOAT, { 0.3, 0, 0, 0 }, -1 },
- { "FWidth", 1, GL_FLOAT, { 0.005, 0, 0, 0 }, -1 },
- END_OF_UNIFORMS
-};
-
-static GLint win = 0;
-static GLboolean Anim = GL_FALSE;
-static GLfloat TexRot = 0.0;
-static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
-
-
-static void
-Idle(void)
-{
- TexRot += 2.0;
- if (TexRot > 360.0)
- TexRot -= 360.0;
- glutPostRedisplay();
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glRotatef(TexRot, 0.0f, 1.0f, 0.0f);
- glMatrixMode(GL_MODELVIEW);
-
- glutSolidSphere(2.0, 20, 10);
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 2.0;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(Idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'z':
- zRot += step;
- break;
- case 'Z':
- zRot -= step;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 2.0;
-
- (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)
-{
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderFile(GL_VERTEX_SHADER, VertProgFile);
- fragShader = CompileShaderFile(GL_FRAGMENT_SHADER, FragProgFile);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- SetUniformValues(program, Uniforms);
- PrintUniforms(Uniforms);
-
- assert(glGetError() == 0);
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- glEnable(GL_DEPTH_TEST);
-
- 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);
- glutInitWindowSize(400, 400);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/toyball.shtest b/progs/glsl/toyball.shtest
deleted file mode 100644
index 887663abd3..0000000000
--- a/progs/glsl/toyball.shtest
+++ /dev/null
@@ -1,17 +0,0 @@
-vs CH11-toyball.vert
-fs CH11-toyball.frag
-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
diff --git a/progs/glsl/trirast.c b/progs/glsl/trirast.c
deleted file mode 100644
index 857342636d..0000000000
--- a/progs/glsl/trirast.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/**
- * Demonstration of doing triangle rasterization with a fragment program.
- * Basic idea:
- * 1. Draw screen-aligned quad / bounding box around the triangle verts.
- * 2. For each pixel in the quad, determine if pixel is inside/outside
- * the triangle edges.
- *
- * Brian Paul
- * 1 Aug 2007
- */
-
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.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 GLboolean anim = GL_TRUE;
-static GLfloat Zrot = 0.0f;
-static GLint uv0, uv1, uv2;
-
-
-static const GLfloat TriVerts[3][2] = {
- { 50, 50 },
- { 250, 50 },
- { 150, 250 }
-};
-
-
-static void
-RotateVerts(GLfloat a,
- GLuint n, const GLfloat vertsIn[][2], GLfloat vertsOut[][2])
-{
- GLuint i;
- GLfloat cx = WinWidth / 2, cy = WinHeight / 2;
- for (i = 0; i < n; i++) {
- float x = vertsIn[i][0] - cx;
- float y = vertsIn[i][1] - cy;
-
- vertsOut[i][0] = x * cos(a) + y * sin(a) + cx;
- vertsOut[i][1] = -x * sin(a) + y * cos(a) + cy;
- }
-}
-
-static void
-ComputeBounds(GLuint n, GLfloat vertsIn[][2],
- GLfloat *xmin, GLfloat *ymin,
- GLfloat *xmax, GLfloat *ymax)
-{
- GLuint i;
- *xmin = *xmax = vertsIn[0][0];
- *ymin = *ymax = vertsIn[0][1];
- for (i = 1; i < n; i++) {
- if (vertsIn[i][0] < *xmin)
- *xmin = vertsIn[i][0];
- else if (vertsIn[i][0] > *xmax)
- *xmax = vertsIn[i][0];
- if (vertsIn[i][1] < *ymin)
- *ymin = vertsIn[i][1];
- else if (vertsIn[i][1] > *ymax)
- *ymax = vertsIn[i][1];
- }
-}
-
-
-static void
-Redisplay(void)
-{
- GLfloat v[3][2], xmin, ymin, xmax, ymax;
-
- RotateVerts(Zrot, 3, TriVerts, v);
- ComputeBounds(3, v, &xmin, &ymin, &xmax, &ymax);
-
- glUniform2fv(uv0, 1, v[0]);
- glUniform2fv(uv1, 1, v[1]);
- glUniform2fv(uv2, 1, v[2]);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glBegin(GL_POLYGON);
- glVertex2f(xmin, ymin);
- glVertex2f(xmax, ymin);
- glVertex2f(xmax, ymax);
- glVertex2f(xmin, ymax);
- glEnd();
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Idle(void)
-{
- if (anim) {
- Zrot = glutGet(GLUT_ELAPSED_TIME) * 0.0005;
- glutPostRedisplay();
- }
- else
- abort();
-}
-
-
-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();
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(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 'z':
- Zrot = 0;
- break;
- case 's':
- Zrot += 0.05;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-Init(void)
-{
- static const char *fragShaderText =
- "uniform vec2 v0, v1, v2; \n"
- "float crs(const vec2 u, const vec2 v) \n"
- "{ \n"
- " return u.x * v.y - u.y * v.x; \n"
- "} \n"
- "\n"
- "void main() {\n"
- " vec2 p = gl_FragCoord.xy; \n"
- " if (crs(v1 - v0, p - v0) >= 0.0 && \n"
- " crs(v2 - v1, p - v1) >= 0.0 && \n"
- " crs(v0 - v2, p - v2) >= 0.0) \n"
- " gl_FragColor = vec4(1.0); \n"
- " else \n"
- " gl_FragColor = vec4(0.5); \n"
- "}\n";
- static const char *vertShaderText =
- "void main() {\n"
- " gl_Position = ftransform(); \n"
- "}\n";
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- uv0 = glGetUniformLocation(program, "v0");
- uv1 = glGetUniformLocation(program, "v1");
- uv2 = glGetUniformLocation(program, "v2");
- printf("Uniforms: %d %d %d\n", uv0, uv1, uv2);
-
- /*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(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(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);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- if (anim)
- glutIdleFunc(Idle);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/twoside.c b/progs/glsl/twoside.c
deleted file mode 100644
index ce155d64e9..0000000000
--- a/progs/glsl/twoside.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/**
- * Test two-sided lighting with shaders.
- * Both GL_VERTEX_PROGRAM_TWO_SIDE and gl_FrontFacing can be tested
- * (see keys below).
- *
- * Brian Paul
- * 18 Dec 2007
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-#ifndef M_PI
-#define M_PI 3.1415926535
-#endif
-
-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 GLboolean anim;
-static GLboolean DetermineFacingInFragProg;
-static GLfloat Xrot;
-static GLint u_fragface;
-static GLenum FrontWinding;
-static int prevTime = 0;
-
-
-static const GLfloat Red[4] = {1, 0, 0, 1};
-static const GLfloat Green[4] = {0, 1, 0, 0};
-
-
-static void
-SetDefaults(void)
-{
- DetermineFacingInFragProg = GL_TRUE;
- FrontWinding = GL_CCW;
- Xrot = 30;
- anim = 0;
- glutIdleFunc(NULL);
-}
-
-
-static void
-Redisplay(void)
-{
- const int sections = 20;
- int i;
- float radius = 2;
-
- glFrontFace(FrontWinding);
-
- if (DetermineFacingInFragProg) {
- glUniform1i(u_fragface, 1);
- glDisable(GL_VERTEX_PROGRAM_TWO_SIDE);
- }
- else {
- glUniform1i(u_fragface, 0);
- glEnable(GL_VERTEX_PROGRAM_TWO_SIDE);
- }
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- glPushMatrix();
- glRotatef(Xrot, 1, 0, 0);
-
- /* Draw a tristrip ring */
- glBegin(GL_TRIANGLE_STRIP);
- glColor4fv(Red);
- glSecondaryColor3fv(Green);
- for (i = 0; i <= sections; i++) {
- float a = (float) i / (sections) * M_PI * 2.0;
- float x = radius * cos(a);
- float y = radius * sin(a);
- glVertex3f(x, -1, y);
- glVertex3f(x, +1, y);
- }
- glEnd();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Idle(void)
-{
- int curTime = glutGet(GLUT_ELAPSED_TIME);
- int dt = curTime - prevTime;
-
- if (prevTime == 0) {
- prevTime = curTime;
- return;
- }
- prevTime = curTime;
-
- Xrot += dt * 0.1;
- glutPostRedisplay();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- float ar = (float) width / height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1, 1, 3, 25);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0, 0, -10);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(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) {
- prevTime = glutGet(GLUT_ELAPSED_TIME);
- glutIdleFunc(Idle);
- }
- else
- glutIdleFunc(NULL);
- break;
- case 'f':
- printf("Using frag shader gl_FrontFacing\n");
- DetermineFacingInFragProg = GL_TRUE;
- break;
- case 'v':
- printf("Using vert shader Two-sided lighting\n");
- DetermineFacingInFragProg = GL_FALSE;
- break;
- case 'r':
- /* reset */
- SetDefaults();
- break;
- case 's':
- Xrot += 5;
- break;
- case 'S':
- Xrot -= 5;
- break;
- case 'w':
- if (FrontWinding == GL_CCW) {
- FrontWinding = GL_CW;
- printf("FrontFace = GL_CW\n");
- }
- else {
- FrontWinding = GL_CCW;
- printf("FrontFace = GL_CCW\n");
- }
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-Init(void)
-{
- static const char *fragShaderText =
- "uniform bool fragface; \n"
- "void main() { \n"
-#if 1
- " if (!fragface || gl_FrontFacing) { \n"
- " gl_FragColor = gl_Color; \n"
- " } \n"
- " else { \n"
- " // note: dim green to help debug \n"
- " gl_FragColor = 0.8 * gl_SecondaryColor; \n"
- " } \n"
-#else
- /* DEBUG CODE */
- " 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"
-#endif
- "} \n";
- static const char *vertShaderText =
- "uniform bool fragface; \n"
- "void main() { \n"
- " gl_FrontColor = gl_Color; \n"
- " if (fragface) { \n"
- " // front/back chosen in frag prog \n"
- " gl_FrontSecondaryColor = gl_SecondaryColor; \n"
- " } \n"
- " else { \n"
- " // front/back chosen in prim setup \n"
- " gl_BackColor = gl_SecondaryColor; \n"
- " } \n"
- " gl_Position = ftransform(); \n"
- "} \n";
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, fragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- u_fragface = glGetUniformLocation(program, "fragface");
- printf("Uniforms: %d\n", u_fragface);
-
- /*assert(glGetError() == 0);*/
-
- glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-
- assert(glIsProgram(program));
- assert(glIsShader(fragShader));
- assert(glIsShader(vertShader));
-
- glEnable(GL_DEPTH_TEST);
-
- SetDefaults();
-}
-
-
-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];
- }
- }
-}
-
-
-static void
-Usage(void)
-{
- printf("Keys:\n");
- printf(" f - do front/back determination in fragment shader\n");
- printf(" v - do front/back determination in vertex shader\n");
- printf(" r - reset, show front\n");
- 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");
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(WinWidth, WinHeight);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- if (anim)
- glutIdleFunc(Idle);
- ParseOptions(argc, argv);
- Init();
- Usage();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/vert-or-frag-only.c b/progs/glsl/vert-or-frag-only.c
deleted file mode 100644
index 148991ca83..0000000000
--- a/progs/glsl/vert-or-frag-only.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/**
- * Draw two quads, one using only a vertex shader, the other only with a
- * fragment shader. They should appear the same.
- * 17 Dec 2008
- * Brian Paul
- */
-
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static char *FragProgFile = NULL;
-static char *VertProgFile = NULL;
-static GLuint FragShader;
-static GLuint VertShader;
-static GLuint VertProgram; /* w/out vertex shader */
-static GLuint FragProgram; /* w/out fragment shader */
-static GLint Win = 0;
-
-
-static void
-DrawQuadColor(void)
-{
- glBegin(GL_QUADS);
- glColor3f(1, 0, 0); glVertex2f(-1, -1);
- glColor3f(0, 1, 0); glVertex2f( 1, -1);
- glColor3f(0, 0, 1); glVertex2f( 1, 1);
- glColor3f(1, 0, 1); glVertex2f(-1, 1);
- glEnd();
-}
-
-
-/** as above, but specify color via texcoords */
-static void
-DrawQuadTex(void)
-{
- glBegin(GL_QUADS);
- glTexCoord3f(1, 0, 0); glVertex2f(-1, -1);
- glTexCoord3f(0, 1, 0); glVertex2f( 1, -1);
- glTexCoord3f(0, 0, 1); glVertex2f( 1, 1);
- glTexCoord3f(1, 0, 1); glVertex2f(-1, 1);
- glEnd();
-}
-
-
-static void
-Redisplay(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- /* render with vertex shader only */
- glUseProgram(VertProgram);
- glPushMatrix();
- glTranslatef(-1.5, 0, 0);
- DrawQuadTex();
- glPopMatrix();
-
- /* render with fragment shader only */
- glUseProgram(FragProgram);
- glPushMatrix();
- glTranslatef(+1.5, 0, 0);
- DrawQuadColor();
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-4, 4, -2, 2, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(FragShader);
- glDeleteShader(VertShader);
- glDeleteProgram(VertProgram);
- glDeleteProgram(FragProgram);
- 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
-Init(void)
-{
- static const char *fragShaderText =
- "void main() {\n"
- " gl_FragColor = gl_Color;\n"
- "}\n";
- static const char *vertShaderText =
- "void main() {\n"
- " gl_Position = ftransform();\n"
- " gl_FrontColor = gl_MultiTexCoord0;\n" /* see DrawQuadTex() */
- "}\n";
-
- if (!ShadersSupported())
- exit(1);
-
- 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);
-
- VertProgram = LinkShaders(VertShader, 0);
- FragProgram = LinkShaders(0, FragShader);
-
- 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(VertProgram));
- assert(glIsProgram(FragProgram));
- assert(glIsShader(FragShader));
- assert(glIsShader(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);
- glutInitWindowSize(400, 200);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- Win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Redisplay);
- ParseOptions(argc, argv);
- Init();
- glutMainLoop();
- return 0;
-}
diff --git a/progs/glsl/vert-tex.c b/progs/glsl/vert-tex.c
deleted file mode 100644
index 2b93c78888..0000000000
--- a/progs/glsl/vert-tex.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/**
- * Vertex shader texture sampling test.
- * Brian Paul
- * 2 Dec 2008
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-
-
-static const char *VertShaderText =
- "uniform sampler2D tex1; \n"
- "void main() \n"
- "{ \n"
- " vec4 pos = gl_Vertex; \n"
- " pos.z = texture2D(tex1, gl_MultiTexCoord0.xy).x - 0.5; \n"
- " gl_Position = gl_ModelViewProjectionMatrix * pos; \n"
- " gl_FrontColor = pos; \n"
- "} \n";
-
-static const char *FragShaderText =
- "void main() \n"
- "{ \n"
- " gl_FragColor = gl_Color; \n"
- "} \n";
-
-
-static GLuint fragShader;
-static GLuint vertShader;
-static GLuint program;
-
-static GLint win = 0;
-static GLboolean Anim = GL_TRUE;
-static GLboolean WireFrame = GL_TRUE;
-static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f;
-
-static void
-Idle(void)
-{
- zRot = 90 + glutGet(GLUT_ELAPSED_TIME) * 0.05;
- glutPostRedisplay();
-}
-
-
-static void
-DrawMesh(void)
-{
- GLfloat xmin = -2.0, xmax = 2.0;
- GLfloat ymin = -2.0, ymax = 2.0;
- GLuint xdivs = 20, ydivs = 20;
- GLfloat dx = (xmax - xmin) / xdivs;
- GLfloat dy = (ymax - ymin) / ydivs;
- GLfloat ds = 1.0 / xdivs, dt = 1.0 / ydivs;
- GLfloat x, y, s, t;
- GLuint i, j;
-
- y = ymin;
- t = 0.0;
- for (i = 0; i < ydivs; i++) {
- x = xmin;
- s = 0.0;
- glBegin(GL_QUAD_STRIP);
- for (j = 0; j < xdivs; j++) {
- glTexCoord2f(s, t);
- glVertex2f(x, y);
- glTexCoord2f(s, t + dt);
- glVertex2f(x, y + dy);
- x += dx;
- s += ds;
- }
- glEnd();
- y += dy;
- t += dt;
- }
-}
-
-
-static void
-Redisplay(void)
-{
- if (WireFrame)
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glRotatef(zRot, 0.0f, 0.0f, 1.0f);
-
- glPushMatrix();
- DrawMesh();
- glPopMatrix();
-
- glPopMatrix();
-
- glutSwapBuffers();
-}
-
-
-static void
-Reshape(int width, int height)
-{
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -15.0f);
-}
-
-
-static void
-CleanUp(void)
-{
- glDeleteShader(fragShader);
- glDeleteShader(vertShader);
- glDeleteProgram(program);
- glutDestroyWindow(win);
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- const GLfloat step = 2.0;
- (void) x;
- (void) y;
-
- switch(key) {
- case 'a':
- Anim = !Anim;
- if (Anim)
- glutIdleFunc(Idle);
- else
- glutIdleFunc(NULL);
- break;
- case 'w':
- WireFrame = !WireFrame;
- break;
- case 'z':
- zRot += step;
- break;
- case 'Z':
- zRot -= step;
- break;
- case 27:
- CleanUp();
- exit(0);
- break;
- }
- glutPostRedisplay();
-}
-
-
-static void
-SpecialKey(int key, int x, int y)
-{
- const GLfloat step = 2.0;
-
- (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
-MakeTexture(void)
-{
- const GLuint texWidth = 64, texHeight = 64;
- GLfloat texImage[64][64];
- GLuint i, j;
-
- /* texture is basically z = f(x, y) */
- for (i = 0; i < texHeight; i++) {
- GLfloat y = 2.0 * (i / (float) (texHeight - 1)) - 1.0;
- for (j = 0; j < texWidth; j++) {
- GLfloat x = 2.0 * (j / (float) (texWidth - 1)) - 1.0;
- GLfloat z = 0.5 + 0.5 * (sin(4.0 * x) * sin(4.0 * y));
- texImage[i][j] = z;
- }
- }
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, 42);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY, texWidth, texHeight, 0,
- GL_LUMINANCE, GL_FLOAT, texImage);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-}
-
-
-static void
-Init(void)
-{
- GLint m;
-
- glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &m);
- if (m < 1) {
- printf("Error: no vertex shader texture units supported.\n");
- exit(1);
- }
-
- if (!ShadersSupported())
- exit(1);
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, VertShaderText);
- fragShader = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderText);
- program = LinkShaders(vertShader, fragShader);
-
- glUseProgram(program);
-
- assert(glGetError() == 0);
-
- MakeTexture();
-
- glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
-
- glEnable(GL_DEPTH_TEST);
-
- glColor3f(1, 1, 1);
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInit(&argc, argv);
- glutInitWindowSize(500, 500);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutSpecialFunc(SpecialKey);
- glutDisplayFunc(Redisplay);
- Init();
- if (Anim)
- glutIdleFunc(Idle);
- glutMainLoop();
- return 0;
-}
-
diff --git a/progs/glsl/vsraytrace.c b/progs/glsl/vsraytrace.c
deleted file mode 100644
index 64d928883e..0000000000
--- a/progs/glsl/vsraytrace.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- */
-/*
- Copyright (c) 2010 Kristóf Ralovich
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <GL/glew.h>
-#include <GL/glut.h>
-#include "shaderutil.h"
-#include <math.h>
-
-static int Win;
-static int WinWidth = 256, WinHeight = 256;
-static GLboolean mouseGrabbed = GL_FALSE;
-static GLuint vertShader;
-static GLuint program;
-float rot[9] = {1,0,0, 0,1,0, 0,0,1};
-
-static const char* vsSource =
- "const float INF = 9999.9; \n"
- "const float EPSILON = 0.00001; \n"
- "const vec3 lightPos = vec3(0.0, 8.0, 1.0); \n"
- "const vec4 backgroundColor = vec4(0.2,0.3,0.4,1); \n"
- " \n"
- "uniform mat3 rot; \n"
- " \n"
- "struct Ray \n"
- "{ \n"
- "vec3 orig; \n"
- "vec3 dir; \n"
- "}; \n"
- " \n"
- "struct Sphere \n"
- "{ \n"
- " vec3 c; \n"
- " float r; \n"
- "}; \n"
- " \n"
- "struct Isec \n"
- "{ \n"
- " float t; \n"
- " int idx; \n"
- " vec3 hit; \n"
- " vec3 n; \n"
- "}; \n"
- " \n"
-#ifdef __APPLE__
- "Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
- "Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
- "Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
- "Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
-#else
- "const Sphere spheres0 = Sphere( vec3(0.0,0.0,-1.0), 0.5 ); \n"
- "const Sphere spheres1 = Sphere( vec3(-3.0,0.0,-1.0), 1.5 ); \n"
- "const Sphere spheres2 = Sphere( vec3(0.0,3.0,-1.0), 0.5 ); \n"
- "const Sphere spheres3 = Sphere( vec3(2.0,0.0,-1.0), 1.0 ); \n"
-#endif
- " \n"
- "// Mesa intel gen4 generates \"unsupported IR in fragment shader 13\" for\n"
- "// sqrt, let's work around. \n"
- "float \n"
- "sqrt_hack(float f2) \n"
- "{ \n"
- " vec3 v = vec3(f2,0.0,0.0); \n"
- " return length(v); \n"
- "} \n"
- " \n"
- "void \n"
- "intersect(const in Ray ray, \n"
- " const in Sphere sph, \n"
- " const in int idx, \n"
- " inout Isec isec) \n"
- "{ \n"
- " // Project both o and the sphere to the plane perpendicular to d \n"
- " // and containing c. Let x be the point where the ray intersects \n"
- " // the plane. If |x-c| < r, the ray intersects the sphere. \n"
- " vec3 o = ray.orig; \n"
- " vec3 d = ray.dir; \n"
- " vec3 n = -d; \n"
- " vec3 c = sph.c; \n"
- " float r = sph.r; \n"
- " float t = dot(c-o,n)/dot(n,d); \n"
- " vec3 x = o+d*t; \n"
- " float e = length(x-c); \n"
- " if(e > r) \n"
- " { \n"
- " // no intersection \n"
- " return; \n"
- " } \n"
- " \n"
- " // Apply Pythagorean theorem on the (intersection,x,c) triangle \n"
- " // to get the distance between c and the intersection. \n"
- "#define BUGGY_INTEL_GEN4_GLSL 1 \n"
- "#ifndef BUGGY_INTEL_GEN4_GLSL \n"
- " float f = sqrt(r*r - e*e); \n"
- "#else \n"
- " float f = sqrt_hack(r*r - e*e); \n"
- "#endif \n"
- " float dist = t - f; \n"
- " if(dist < 0.0) \n"
- " { \n"
- " // inside the sphere \n"
- " return; \n"
- " } \n"
- " \n"
- " if(dist < EPSILON) \n"
- " return; \n"
- " \n"
- " if(dist > isec.t) \n"
- " return; \n"
- " \n"
- " isec.t = dist; \n"
- " isec.idx = idx; \n"
- " \n"
- " isec.hit = ray.orig + ray.dir * isec.t; \n"
- " isec.n = (isec.hit - c) / r; \n"
- "} \n"
- " \n"
- "Isec \n"
- "intersect(const in Ray ray, \n"
- " const in float max_t /*= INF*/) \n"
- "{ \n"
- " Isec nearest; \n"
- " nearest.t = max_t; \n"
- " nearest.idx = -1; \n"
- " \n"
- " intersect(ray, spheres0, 0, nearest); \n"
- " intersect(ray, spheres1, 1, nearest); \n"
- " intersect(ray, spheres2, 2, nearest); \n"
- " intersect(ray, spheres3, 3, nearest); \n"
- " \n"
- " return nearest; \n"
- "} \n"
- " \n"
- "vec4 \n"
- "idx2color(const in int idx) \n"
- "{ \n"
- " vec4 diff; \n"
- " if(idx == 0) \n"
- " diff = vec4(1.0, 0.0, 0.0, 0.0); \n"
- " else if(idx == 1) \n"
- " diff = vec4(0.0, 1.0, 0.0, 0.0); \n"
- " else if(idx == 2) \n"
- " diff = vec4(0.0, 0.0, 1.0, 0.0); \n"
- " else if(idx == 3) \n"
- " diff = vec4(1.0, 1.0, 0.0, 0.0); \n"
- " return diff; \n"
- "} \n"
- " \n"
- "vec4 \n"
- "trace0(const in Ray ray) \n"
- "{ \n"
- " Isec isec = intersect(ray, INF); \n"
- " \n"
- " if(isec.idx == -1) \n"
- " { \n"
- " return backgroundColor; \n"
- " } \n"
- " \n"
- " vec4 diff = idx2color(isec.idx); \n"
- " \n"
- " vec3 N = isec.n; \n"
- " vec3 L = normalize(lightPos-isec.hit); \n"
- " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
- " return dot(N,L)*diff + pow( \n"
- " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
- "} \n"
- " \n"
- "vec4 \n"
- "trace1(const in Ray ray) \n"
- "{ \n"
- " Isec isec = intersect(ray, INF); \n"
- " \n"
- " if(isec.idx == -1) \n"
- " { \n"
- " return backgroundColor; \n"
- " } \n"
- " \n"
- " Ray reflRay = Ray(isec.hit, reflect(ray.dir, isec.n)); \n"
- " \n"
- " vec4 reflCol = trace0(reflRay); \n"
- " \n"
- " vec4 diff = idx2color(isec.idx) + reflCol; \n"
- " \n"
- " vec3 N = isec.n; \n"
- " vec3 L = normalize(lightPos-isec.hit); \n"
- " vec3 camera_dir = normalize(ray.orig - isec.hit); \n"
- " return dot(N,L)*diff + pow( \n"
- " clamp(dot(reflect(-L,N),camera_dir),0.0,1.0),16.0); \n"
- "} \n"
- " \n"
- "void main() \n"
- "{ \n"
- " const vec3 cameraPos = vec3(0,0,3); \n"
- " vec3 rayDir = normalize(vec3(gl_Vertex.x, gl_Vertex.y, -1.0) * rot);\n"
- " Ray ray = Ray(cameraPos, rayDir); \n"
- " gl_Position = gl_Vertex; \n"
- " gl_FrontColor = trace1(ray); \n"
- "}\n";
-
-
-static
-float
-deg2rad(const float degree)
-{
- return( degree * 0.017453292519943295769236907684886F);
-}
-
-static void
-rotate_xy(float* mat3, const float degreesAroundX, const float degreesAroundY)
-{
- const float rad1 = deg2rad(degreesAroundX);
- const float c1 = cosf(rad1);
- const float s1 = sinf(rad1);
- const float rad2 = deg2rad(degreesAroundY);
- const float c2 = cosf(rad2);
- const float s2 = sinf(rad2);
- mat3[0] = c2; mat3[3] = 0.0F; mat3[6] = s2;
- mat3[1] = s1*s2; mat3[4] = c1; mat3[7] = -s1*c2;
- mat3[2] = -c1*s2;mat3[5] = s1; mat3[8] = c1*c2;
-}
-
-static void
-identity(float* mat3)
-{
- mat3[0] = 1.0F; mat3[3] = 0.0F; mat3[6] = 0.0F;
- mat3[1] = 0.0F; mat3[4] = 1.0F; mat3[7] = 0.0F;
- mat3[2] = 0.0F; mat3[5] = 0.0F; mat3[8] = 1.0F;
-}
-
-static void
-Draw(void)
-{
- const float w = 0.5F * WinWidth;
- const float h = 0.5F * WinHeight;
- int x,y;
-
- GLint location = glGetUniformLocation(program, "rot");
-
- glUseProgram(program);
- glUniformMatrix3fv(location, 1, 0, rot);
- glBegin(GL_POINTS);
- for(y = 0; y < WinHeight; y++)
- {
- for(x = 0; x < WinWidth; x++)
- {
- const float posx = x / w - 1.0F;
- const float posy = y / h - 1.0F;
- glVertex2f(posx, posy);
- }
- }
- glEnd();
- glUseProgram(0);
-
- glutSwapBuffers();
-
- {
- static int frames = 0;
- static int t0 = 0;
- static int t1 = 0;
- float dt;
- frames++;
- t1 = glutGet(GLUT_ELAPSED_TIME);
- dt = (float)(t1-t0)/1000.0F;
- if (dt >= 5.0F)
- {
- float fps = (float)frames / dt;
- printf("%f FPS (%d frames in %f seconds)\n", fps, frames, dt);
- frames = 0;
- t0 = t1;
- }
- }
-}
-
-
-static void
-Reshape(int width, int height)
-{
- WinWidth = width;
- WinHeight = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-
-static void
-Key(unsigned char key, int x, int y)
-{
- if(key == 27)
- {
- glutDestroyWindow(Win);
- exit(0);
- }
- glutPostRedisplay();
-}
-
-
-static
-void
-drag(int x, int y)
-{
- float scale = 1.5F;
- if(mouseGrabbed)
- {
- static GLfloat xRot = 0, yRot = 0;
- xRot = (float)(x - WinWidth/2) / scale;
- yRot = (float)(y - WinHeight/2) / scale;
- identity(rot);
- rotate_xy(rot, yRot, xRot);
- glutPostRedisplay();
- }
-}
-
-
-static
-void
-mouse(int button, int state, int x, int y)
-{
- mouseGrabbed = (state == GLUT_DOWN);
-}
-
-
-static void
-Init(void)
-{
- glDisable(GL_DEPTH_TEST);
-
- if(!ShadersSupported())
- {
- fprintf(stderr, "Shaders are not supported!\n");
- exit(-1);
- }
-
- vertShader = CompileShaderText(GL_VERTEX_SHADER, vsSource);
- program = LinkShaders(vertShader, 0);
- glUseProgram(0);
-
- if(glGetError() != 0)
- {
- fprintf(stderr, "Shaders were not loaded!\n");
- exit(-1);
- }
-
- if(!glIsShader(vertShader))
- {
- fprintf(stderr, "Vertex shader failed!\n");
- exit(-1);
- }
-
- if(!glIsProgram(program))
- {
- fprintf(stderr, "Shader program failed!\n");
- exit(-1);
- }
-
- printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
-}
-
-
-int
-main(int argc, char *argv[])
-{
- glutInitWindowSize(WinWidth, WinHeight);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- Win = glutCreateWindow(argv[0]);
- glewInit();
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Draw);
- glutIdleFunc(Draw);
- glutMouseFunc(mouse);
- glutMotionFunc(drag);
- Init();
- glutMainLoop();
- return 0;
-}
-