summaryrefslogtreecommitdiffstats
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/Makefile4
-rw-r--r--progs/demos/Makefile.win23
-rw-r--r--progs/demos/arbfplight.c4
-rw-r--r--progs/demos/arbfslight.c2
-rw-r--r--progs/demos/fogcoord.c364
-rw-r--r--progs/demos/fplight.c6
-rw-r--r--progs/demos/fslight.c12
-rw-r--r--progs/demos/shadowtex.c328
-rw-r--r--progs/demos/spriteblast.c22
-rw-r--r--progs/demos/tessdemo.c2
-rw-r--r--progs/glsl/Makefile7
-rw-r--r--progs/glsl/deriv.c319
-rw-r--r--progs/miniglx/miniglxtest.c239
-rw-r--r--progs/redbook/Imakefile221
-rw-r--r--progs/samples/Imakefile101
-rw-r--r--progs/tests/Makefile8
-rw-r--r--progs/tests/arraytexture.c337
-rw-r--r--progs/tests/drawbuffers.c21
-rw-r--r--progs/tests/random.c457
-rw-r--r--progs/util/extfuncs.h2
-rw-r--r--progs/xdemos/Makefile1
-rw-r--r--progs/xdemos/texture_from_pixmap.c396
22 files changed, 2205 insertions, 671 deletions
diff --git a/progs/Makefile b/progs/Makefile
index d5ec17d43e5..5e705efa7ee 100644
--- a/progs/Makefile
+++ b/progs/Makefile
@@ -17,7 +17,7 @@ message:
subdirs:
@for dir in $(SUBDIRS) ; do \
if [ -d $$dir ] ; then \
- (cd $$dir ; $(MAKE)) || exit 1 ; \
+ (cd $$dir && $(MAKE)) || exit 1 ; \
fi \
done
@@ -27,6 +27,6 @@ install:
clean:
@for dir in $(SUBDIRS) tests ; do \
if [ -d $$dir ] ; then \
- (cd $$dir ; $(MAKE) clean) ; \
+ (cd $$dir && $(MAKE) clean) ; \
fi \
done
diff --git a/progs/demos/Makefile.win b/progs/demos/Makefile.win
index 4ac32361b26..0d0b19b9fe7 100644
--- a/progs/demos/Makefile.win
+++ b/progs/demos/Makefile.win
@@ -22,9 +22,11 @@ LIBS = GLUT32.LIB OPENGL32.LIB
all: OPENGL32.DLL GLU32.DLL GLUT32.DLL \
readtex.h readtex.c showbuffer.h showbuffer.c \
+ extfuncs.h trackball.h trackball.c \
arbfplight.exe arbfslight.exe arbocclude.exe bounce.exe \
- clearspd.exe cubemap.exe drawpix.exe fire.exe fogcoord.exe \
- fplight.exe gamma.exe gearbox.exe \
+ clearspd.exe cubemap.exe drawpix.exe engine.exe \
+ fire.exe fogcoord.exe \
+ fplight.exe fslight.exe gamma.exe gearbox.exe \
gears.exe geartrain.exe gloss.exe \
glinfo.exe glslnoise.exe \
gltestperf.exe glutfx.exe ipers.exe isosurf.exe lodbias.exe \
@@ -42,14 +44,16 @@ bounce.exe: bounce.obj
clearspd.exe: clearspd.obj
cubemap.exe: cubemap.obj readtex.obj
drawpix.exe: drawpix.obj readtex.obj
+engine.exe: engine.obj readtex.obj trackball.obj
fire.exe: fire.obj readtex.obj
fogcoord.exe: fogcoord.obj readtex.obj
fplight.exe: fplight.obj
+fslight.exe: fslight.obj
gamma.exe: gamma.obj
gearbox.exe: gearbox.obj
gears.exe: gears.obj
geartrain.exe: geartrain.obj
-gloss.exe: gloss.obj readtex.obj
+gloss.exe: gloss.obj readtex.obj trackball.obj
glinfo.exe: glinfo.obj
glslnoise.exe: glslnoise.obj
gltestperf.exe: gltestperf.obj
@@ -105,14 +109,23 @@ showbuffer.c: $(TOP)\progs\util\showbuffer.c
showbuffer.h: $(TOP)\progs\util\showbuffer.h
copy $** .
+trackball.c: $(TOP)\progs\util\trackball.c
+ copy $** .
+
+trackball.h: $(TOP)\progs\util\trackball.h
+ copy $** .
+
+extfuncs.h: $(TOP)\progs\util\extfuncs.h
+ copy $** .
+
.obj.exe:
$(link) $(ldebug) -out:$@ $** /LIBPATH:$(LIBDIR) $(LIBS)
.c.obj:
- $(cc) $(cdebug) $(cflags) $(cvars) /I$(INCDIR) $*.c
+ $(cc) $(cdebug) $(cflags) $(cvars) -D_USE_MATH_DEFINES /I$(INCDIR) $*.c
clean::
- del *.obj *.exe readtex.* showbuffer.*
+ del *.obj *.exe readtex.* showbuffer.* trackball.*
clobber::
diff --git a/progs/demos/arbfplight.c b/progs/demos/arbfplight.c
index d9c564fbe56..bc2c7e312ab 100644
--- a/progs/demos/arbfplight.c
+++ b/progs/demos/arbfplight.c
@@ -24,6 +24,7 @@ static GLuint VertProg;
static GLboolean Anim = GL_TRUE;
static GLboolean Wire = GL_FALSE;
static GLboolean PixelLight = GL_TRUE;
+static GLint Win;
static GLint T0 = 0;
static GLint Frames = 0;
@@ -148,6 +149,7 @@ static void Key( unsigned char key, int x, int y )
case 27:
glDeleteProgramsARB_func(1, &VertProg);
glDeleteProgramsARB_func(1, &FragProg);
+ glutDestroyWindow(Win);
exit(0);
break;
}
@@ -382,7 +384,7 @@ int main( int argc, char *argv[] )
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 200, 200 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
- glutCreateWindow(argv[0]);
+ Win = glutCreateWindow(argv[0]);
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c
index 374de568872..69575f06236 100644
--- a/progs/demos/arbfslight.c
+++ b/progs/demos/arbfslight.c
@@ -62,7 +62,7 @@ static PFNGLUNIFORM3FVARBPROC glUniform4fvARB = NULL;
static void normalize (GLfloat *dst, const GLfloat *src)
{
- GLfloat len = sqrtf (src[0] * src[0] + src[1] * src[1] + src[2] * src[2]);
+ 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;
diff --git a/progs/demos/fogcoord.c b/progs/demos/fogcoord.c
index 19a15f05b87..00c73c6f048 100644
--- a/progs/demos/fogcoord.c
+++ b/progs/demos/fogcoord.c
@@ -7,151 +7,136 @@
* Daniel Borca
*/
-
+#define GL_GLEXT_PROTOTYPES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
-#include "readtex.h"
-
-#define TEXTURE_FILE "../images/bw.rgb"
-
-#define ARRAYS 0 /* use glDrawElements */
-
-#define VERBOSE 1 /* tell me what happens */
+#define DEPTH 5.0f
-#define DEPTH 15.0f
+static PFNGLFOGCOORDFEXTPROC glFogCoordf_ext;
+static PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointer_ext;
-#if !defined(GLAPIENTRYP)
-# define GLAPIENTRYP *
-#endif
-
-typedef void (GLAPIENTRYP GLFOGCOORDFEXTPROC) (GLfloat f);
-typedef void (GLAPIENTRYP GLFOGCOORDPOINTEREXTPROC) (GLenum, GLsizei, const GLvoid *);
-
-static GLFOGCOORDFEXTPROC glFogCoordf_ext;
-#if ARRAYS
-static GLFOGCOORDPOINTEREXTPROC glFogCoordPointer_ext;
-#endif
static GLboolean have_fog_coord;
static GLfloat camz;
-static GLuint texture[1];
static GLint fogMode;
static GLboolean fogCoord;
static GLfloat fogDensity = 0.75;
-static GLfloat fogStart = 1.0, fogEnd = 40.0;
+static GLfloat fogStart = 1.0, fogEnd = DEPTH;
static GLfloat fogColor[4] = {0.6f, 0.3f, 0.0f, 1.0f};
+static const char *ModeStr = NULL;
+static GLboolean Arrays = GL_FALSE;
+static GLboolean Texture = GL_TRUE;
-static void APIENTRY glFogCoordf_nop (GLfloat f)
+static void
+Reset(void)
{
- (void)f;
+ fogMode = 1;
+ fogCoord = 1;
+ fogDensity = 0.75;
+ fogStart = 1.0;
+ fogEnd = DEPTH;
+ Arrays = GL_FALSE;
+ Texture = GL_TRUE;
}
-static int BuildTexture (const char *filename, GLuint texid[])
+static void APIENTRY
+glFogCoordf_nop (GLfloat f)
{
- GLubyte *tex_data;
- GLenum tex_format;
- GLint tex_width, tex_height;
+ (void)f;
+}
- tex_data = LoadRGBImage(filename, &tex_width, &tex_height, &tex_format);
- if (tex_data == NULL) {
- return -1;
- }
- {
- GLint tex_max;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &tex_max);
- if ((tex_width > tex_max) || (tex_height > tex_max)) {
- return -1;
- }
+static void
+PrintString(const char *s)
+{
+ while (*s) {
+ glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
+ s++;
}
+}
- glGenTextures(1, texid);
-
- glBindTexture(GL_TEXTURE_2D, texid[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexImage2D(GL_TEXTURE_2D, 0, tex_format, tex_width, tex_height, 0,
- tex_format, GL_UNSIGNED_BYTE, tex_data);
- return 0;
+static void
+PrintInfo(void)
+{
+ char s[100];
+
+ glDisable(GL_FOG);
+ glColor3f(0, 1, 1);
+
+ sprintf(s, "Mode(m): %s Start(s/S): %g End(e/E): %g Density(d/D): %g",
+ ModeStr, fogStart, fogEnd, fogDensity);
+ glWindowPos2iARB(5, 20);
+ PrintString(s);
+
+ sprintf(s, "Arrays(a): %s glFogCoord(c): %s EyeZ(z/z): %g",
+ (Arrays ? "Yes" : "No"),
+ (fogCoord ? "Yes" : "No"),
+ camz);
+ glWindowPos2iARB(5, 5);
+ PrintString(s);
}
-static int SetFogMode (GLint fogMode)
+static int
+SetFogMode(GLint fogMode)
{
fogMode &= 3;
switch (fogMode) {
case 0:
+ ModeStr = "Off";
glDisable(GL_FOG);
-#if VERBOSE
- printf("fog(disable)\n");
-#endif
break;
case 1:
+ ModeStr = "GL_LINEAR";
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, fogStart);
glFogf(GL_FOG_END, fogEnd);
-#if VERBOSE
- printf("fog(GL_LINEAR, %.2f, %.2f)\n", fogStart, fogEnd);
-#endif
break;
case 2:
+ ModeStr = "GL_EXP";
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP);
glFogf(GL_FOG_DENSITY, fogDensity);
-#if VERBOSE
- printf("fog(GL_EXP, %.2f)\n", fogDensity);
-#endif
break;
case 3:
+ ModeStr = "GL_EXP2";
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glFogf(GL_FOG_DENSITY, fogDensity);
-#if VERBOSE
- printf("fog(GL_EXP2, %.2f)\n", fogDensity);
-#endif
break;
}
return fogMode;
}
-static GLboolean SetFogCoord (GLboolean fogCoord)
+static GLboolean
+SetFogCoord(GLboolean fogCoord)
{
glFogCoordf_ext = glFogCoordf_nop;
if (!have_fog_coord) {
-#if VERBOSE
- printf("fog(GL_FRAGMENT_DEPTH_EXT)%s\n", fogCoord ? " EXT_fog_coord not available!" : "");
-#endif
return GL_FALSE;
}
if (fogCoord) {
- glFogCoordf_ext = (GLFOGCOORDFEXTPROC)glutGetProcAddress("glFogCoordfEXT");
+ glFogCoordf_ext = (PFNGLFOGCOORDFEXTPROC)glutGetProcAddress("glFogCoordfEXT");
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
-#if VERBOSE
- printf("fog(GL_FOG_COORDINATE_EXT)\n");
-#endif
- } else {
+ }
+ else {
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
-#if VERBOSE
- printf("fog(GL_FRAGMENT_DEPTH_EXT)\n");
-#endif
}
return fogCoord;
}
-#if ARRAYS
/* could reuse vertices */
static GLuint vertex_index[] = {
/* Back */
@@ -172,19 +157,19 @@ static GLuint vertex_index[] = {
static GLfloat vertex_pointer[][3] = {
/* Back */
- {-2.5f,-2.5f,-DEPTH}, { 2.5f,-2.5f,-DEPTH}, { 2.5f, 2.5f,-DEPTH}, {-2.5f, 2.5f,-DEPTH},
+ {-1.0f,-1.0f,-DEPTH}, { 1.0f,-1.0f,-DEPTH}, { 1.0f, 1.0f,-DEPTH}, {-1.0f, 1.0f,-DEPTH},
/* Floor */
- {-2.5f,-2.5f,-DEPTH}, { 2.5f,-2.5f,-DEPTH}, { 2.5f,-2.5f, DEPTH}, {-2.5f,-2.5f, DEPTH},
+ {-1.0f,-1.0f,-DEPTH}, { 1.0f,-1.0f,-DEPTH}, { 1.0f,-1.0f, 0.0}, {-1.0f,-1.0f, 0.0},
/* Roof */
- {-2.5f, 2.5f,-DEPTH}, { 2.5f, 2.5f,-DEPTH}, { 2.5f, 2.5f, DEPTH}, {-2.5f, 2.5f, DEPTH},
+ {-1.0f, 1.0f,-DEPTH}, { 1.0f, 1.0f,-DEPTH}, { 1.0f, 1.0f, 0.0}, {-1.0f, 1.0f, 0.0},
/* Right */
- { 2.5f,-2.5f, DEPTH}, { 2.5f, 2.5f, DEPTH}, { 2.5f, 2.5f,-DEPTH}, { 2.5f,-2.5f,-DEPTH},
+ { 1.0f,-1.0f, 0.0}, { 1.0f, 1.0f, 0.0}, { 1.0f, 1.0f,-DEPTH}, { 1.0f,-1.0f,-DEPTH},
/* Left */
- {-2.5f,-2.5f, DEPTH}, {-2.5f, 2.5f, DEPTH}, {-2.5f, 2.5f,-DEPTH}, {-2.5f,-2.5f,-DEPTH}
+ {-1.0f,-1.0f, 0.0}, {-1.0f, 1.0f, 0.0}, {-1.0f, 1.0f,-DEPTH}, {-1.0f,-1.0f,-DEPTH}
};
static GLfloat texcoord_pointer[][2] = {
@@ -192,118 +177,139 @@ static GLfloat texcoord_pointer[][2] = {
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f},
/* Floor */
- {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f},
+ {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, DEPTH}, {0.0f, DEPTH},
/* Roof */
- {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f},
+ {1.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, DEPTH}, {1.0f, DEPTH},
/* Right */
- {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f},
+ {0.0f, 1.0f}, {0.0f, 0.0f}, {DEPTH, 0.0f}, {DEPTH, 1.0f},
/* Left */
- {0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}
+ {0.0f, 0.0f}, {0.0f, 1.0f}, {DEPTH, 1.0f}, {DEPTH, 0.0f}
};
-static GLfloat fogcoord_pointer[][1] = {
+static GLfloat fogcoord_pointer[] = {
/* Back */
- {1.0f}, {1.0f}, {1.0f}, {1.0f},
+ DEPTH, DEPTH, DEPTH, DEPTH,
/* Floor */
- {1.0f}, {1.0f}, {0.0f}, {0.0f},
+ DEPTH, DEPTH, 0.0, 0.0,
/* Roof */
- {1.0f}, {1.0f}, {0.0f}, {0.0f},
+ DEPTH, DEPTH, 0.0, 0.0,
/* Right */
- {0.0f}, {0.0f}, {1.0f}, {1.0f},
+ 0.0, 0.0, DEPTH, DEPTH,
/* Left */
- {0.0f}, {0.0f}, {1.0f}, {1.0f}
+ 0.0, 0.0, DEPTH, DEPTH
};
-#endif
-static void Display( void )
+static void
+Display( void )
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
- glTranslatef(0.0f, 0.0f, camz);
+ glTranslatef(0.0f, 0.0f, -camz);
-#if ARRAYS
- glDrawElements(GL_QUADS, sizeof(vertex_index) / sizeof(vertex_index[0]), GL_UNSIGNED_INT, vertex_index);
-#else
- /* Back */
- glBegin(GL_QUADS);
- glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f,-2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f,-2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f, 2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f, 2.5f,-DEPTH);
- glEnd();
+ SetFogMode(fogMode);
- /* Floor */
- glBegin(GL_QUADS);
- glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f,-2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f,-2.5f,-DEPTH);
- glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f,-2.5f, DEPTH);
- glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f,-2.5f, DEPTH);
- glEnd();
+ glColor3f(1, 1, 1);
- /* Roof */
- glBegin(GL_QUADS);
- glFogCoordf_ext(1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f, 2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f, 2.5f,-DEPTH);
- glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f, 2.5f, DEPTH);
- glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f, 2.5f, DEPTH);
- glEnd();
+ if (Texture)
+ glEnable(GL_TEXTURE_2D);
- /* Right */
- glBegin(GL_QUADS);
- glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 2.5f,-2.5f, DEPTH);
- glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 2.5f, 2.5f, DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.5f, 2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.5f,-2.5f,-DEPTH);
- glEnd();
+ if (Arrays) {
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDrawElements(GL_QUADS, sizeof(vertex_index) / sizeof(vertex_index[0]),
+ GL_UNSIGNED_INT, vertex_index);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ else {
+ /* Back */
+ glBegin(GL_QUADS);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f,-DEPTH);
+ glEnd();
+
+ /* Floor */
+ glBegin(GL_QUADS);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f,-DEPTH);
+ glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, DEPTH); glVertex3f( 1.0f,-1.0f,0.0);
+ glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, DEPTH); glVertex3f(-1.0f,-1.0f,0.0);
+ glEnd();
+
+ /* Roof */
+ glBegin(GL_QUADS);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, 1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f,-DEPTH);
+ glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, DEPTH); glVertex3f( 1.0f, 1.0f,0.0);
+ glFogCoordf_ext(0.0f); glTexCoord2f(1.0f, DEPTH); glVertex3f(-1.0f, 1.0f,0.0);
+ glEnd();
+
+ /* Right */
+ glBegin(GL_QUADS);
+ glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,-1.0f,0.0);
+ glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f,0.0);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 0.0f); glVertex3f( 1.0f, 1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 1.0f); glVertex3f( 1.0f,-1.0f,-DEPTH);
+ glEnd();
+
+ /* Left */
+ glBegin(GL_QUADS);
+ glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f,0.0);
+ glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f,0.0);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 1.0f); glVertex3f(-1.0f, 1.0f,-DEPTH);
+ glFogCoordf_ext(DEPTH); glTexCoord2f(DEPTH, 0.0f); glVertex3f(-1.0f,-1.0f,-DEPTH);
+ glEnd();
+ }
- /* Left */
- glBegin(GL_QUADS);
- glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.5f,-2.5f, DEPTH);
- glFogCoordf_ext(0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.5f, 2.5f, DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-2.5f, 2.5f,-DEPTH);
- glFogCoordf_ext(1.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-2.5f,-2.5f,-DEPTH);
- glEnd();
-#endif
+ glDisable(GL_TEXTURE_2D);
+
+ PrintInfo();
glutSwapBuffers();
}
-static void Reshape( int width, int height )
+static void
+Reshape( int width, int height )
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(45.0f, (GLfloat)(width)/(GLfloat)(height), 0.1f, 100.0f);
+ glFrustum(-1, 1, -1, 1, 1.0, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
-static void Key( unsigned char key, int x, int y )
+static void
+Key( unsigned char key, int x, int y )
{
(void) x;
(void) y;
switch (key) {
+ case 'a':
+ Arrays = !Arrays;
+ break;
case 'f':
+ case 'm':
fogMode = SetFogMode(fogMode + 1);
break;
- case '+':
- if (fogDensity < 1.0) {
- fogDensity += 0.05;
- }
+ case 'D':
+ fogDensity += 0.05;
SetFogMode(fogMode);
break;
- case '-':
+ case 'd':
if (fogDensity > 0.0) {
fogDensity -= 0.05;
}
@@ -311,31 +317,43 @@ static void Key( unsigned char key, int x, int y )
break;
case 's':
if (fogStart > 0.0) {
- fogStart -= 1.0;
+ fogStart -= 0.25;
}
SetFogMode(fogMode);
break;
case 'S':
- if (fogStart < fogEnd) {
- fogStart += 1.0;
+ if (fogStart < 100.0) {
+ fogStart += 0.25;
}
SetFogMode(fogMode);
break;
case 'e':
- if (fogEnd > fogStart) {
- fogEnd -= 1.0;
+ if (fogEnd > 0.0) {
+ fogEnd -= 0.25;
}
SetFogMode(fogMode);
break;
case 'E':
if (fogEnd < 100.0) {
- fogEnd += 1.0;
+ fogEnd += 0.25;
}
SetFogMode(fogMode);
break;
case 'c':
fogCoord = SetFogCoord(fogCoord ^ GL_TRUE);
break;
+ case 't':
+ Texture = !Texture;
+ break;
+ case 'z':
+ camz -= 0.1;
+ break;
+ case 'Z':
+ camz += 0.1;
+ break;
+ case 'r':
+ Reset();
+ break;
case 27:
exit(0);
break;
@@ -344,37 +362,28 @@ static void Key( unsigned char key, int x, int y )
}
-static void SpecialKey( int key, int x, int y )
+static void
+Init(void)
{
- (void) x;
- (void) y;
- switch (key) {
- case GLUT_KEY_UP:
- if (camz < (DEPTH - 1.0)) {
- camz += 1.0f;
- }
- break;
- case GLUT_KEY_DOWN:
- if (camz > -19.0) {
- camz -= 1.0f;
- }
- break;
- }
- glutPostRedisplay();
-}
+ static const GLubyte teximage[2][2][4] = {
+ { { 255, 255, 255, 255}, { 128, 128, 128, 255} },
+ { { 128, 128, 128, 255}, { 255, 255, 255, 255} }
+ };
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
-static void Init( void )
-{
have_fog_coord = glutExtensionSupported("GL_EXT_fog_coord");
-
- if (BuildTexture(TEXTURE_FILE, texture) == -1) {
- exit(1);
+ if (!have_fog_coord) {
+ printf("GL_EXT_fog_coord not supported!\n");
}
- glEnable(GL_TEXTURE_2D);
- glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
- glClearDepth(1.0f);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, teximage);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
+
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
@@ -383,11 +392,8 @@ static void Init( void )
glFogfv(GL_FOG_COLOR, fogColor);
glHint(GL_FOG_HINT, GL_NICEST);
fogCoord = SetFogCoord(GL_TRUE); /* try to enable fog_coord */
- fogMode = SetFogMode(2); /* GL_EXP */
-
- camz = -19.0f;
+ fogMode = SetFogMode(1);
-#if ARRAYS
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertex_pointer);
@@ -395,24 +401,24 @@ static void Init( void )
glTexCoordPointer(2, GL_FLOAT, 0, texcoord_pointer);
if (have_fog_coord) {
- glFogCoordPointer_ext = (GLFOGCOORDPOINTEREXTPROC)glutGetProcAddress("glFogCoordPointerEXT");
+ glFogCoordPointer_ext = (PFNGLFOGCOORDPOINTEREXTPROC)glutGetProcAddress("glFogCoordPointerEXT");
glEnableClientState(GL_FOG_COORDINATE_ARRAY_EXT);
glFogCoordPointer_ext(GL_FLOAT, 0, fogcoord_pointer);
}
-#endif
+
+ Reset();
}
-int main( int argc, char *argv[] )
+int
+main( int argc, char *argv[] )
{
glutInit( &argc, argv );
- glutInitWindowPosition( 0, 0 );
- glutInitWindowSize( 640, 480 );
+ glutInitWindowSize( 600, 600 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow(argv[0]);
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
- glutSpecialFunc( SpecialKey );
glutDisplayFunc( Display );
Init();
glutMainLoop();
diff --git a/progs/demos/fplight.c b/progs/demos/fplight.c
index c7a38248d38..fb510cccc8a 100644
--- a/progs/demos/fplight.c
+++ b/progs/demos/fplight.c
@@ -24,7 +24,7 @@ static GLuint VertProg;
static GLboolean Anim = GL_TRUE;
static GLboolean Wire = GL_FALSE;
static GLboolean PixelLight = GL_TRUE;
-
+static GLint Win;
static GLfloat Xrot = 0, Yrot = 0;
@@ -136,8 +136,8 @@ static void Key( unsigned char key, int x, int y )
}
break;
case 27:
+ glutDestroyWindow(Win);
exit(0);
- break;
}
glutPostRedisplay();
}
@@ -272,7 +272,7 @@ int main( int argc, char *argv[] )
glutInitWindowPosition( 0, 0 );
glutInitWindowSize( 200, 200 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
- glutCreateWindow(argv[0]);
+ Win = glutCreateWindow(argv[0]);
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
glutSpecialFunc( SpecialKey );
diff --git a/progs/demos/fslight.c b/progs/demos/fslight.c
index 736cc48ac67..e6d83bf8fb3 100644
--- a/progs/demos/fslight.c
+++ b/progs/demos/fslight.c
@@ -45,7 +45,7 @@ static GLint uTexture;
static GLuint SphereList, RectList, CurList;
static GLint win = 0;
-static GLboolean anim = GL_FALSE;
+static GLboolean anim = GL_TRUE;
static GLboolean wire = GL_FALSE;
static GLboolean pixelLight = GL_TRUE;
@@ -58,7 +58,7 @@ static GLfloat xRot = 90.0f, yRot = 0.0f;
static void
normalize(GLfloat *dst, const GLfloat *src)
{
- GLfloat len = sqrtf(src[0] * src[0] + src[1] * src[1] + src[2] * src[2]);
+ 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;
@@ -477,8 +477,8 @@ Init(void)
version = (const char *) glGetString(GL_VERSION);
if (version[0] != '2' || version[1] != '.') {
- printf("Warning: this program expects OpenGL 2.0\n");
- /*exit(1);*/
+ printf("This program requires OpenGL 2.x, found %s\n", version);
+ exit(1);
}
GetExtensionFuncs();
@@ -579,6 +579,8 @@ Init(void)
#if 0
TestFunctions();
+#else
+ (void) TestFunctions;
#endif
}
@@ -603,7 +605,7 @@ main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition( 0, 0);
- glutInitWindowSize(100, 100);
+ glutInitWindowSize(200, 200);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
win = glutCreateWindow(argv[0]);
glutReshapeFunc(Reshape);
diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c
index b32fb45b4fa..59253e8c1e3 100644
--- a/progs/demos/shadowtex.c
+++ b/progs/demos/shadowtex.c
@@ -9,6 +9,7 @@
* Added GL_EXT_packed_depth_stencil support on 15 March 2006.
* Added GL_EXT_framebuffer_object support on 27 March 2006.
* Removed old SGIX extension support on 5 April 2006.
+ * Added vertex / fragment program support on 7 June 2007 (Ian Romanick).
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
@@ -34,6 +35,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <math.h>
#include <GL/glut.h>
#include "showbuffer.h"
@@ -67,8 +69,27 @@ static GLboolean NeedNewShadowMap = GL_FALSE;
static GLuint ShadowTexture, GrayTexture;
static GLuint ShadowFBO;
+static GLfloat lightModelview[16];
+static GLfloat lightProjection[16];
+
+static GLuint vert_prog;
+static GLuint frag_progs[3];
+static GLuint curr_frag = 0;
+static GLuint max_frag = 1;
+
+#define NUM_FRAG_MODES 3
+static const char *FragProgNames[] = {
+ "fixed-function",
+ "program without \"OPTION ARB_fragment_program_shadow\"",
+ "program with \"OPTION ARB_fragment_program_shadow\"",
+};
+
static GLboolean HaveFBO = GL_FALSE;
static GLboolean UseFBO = GL_FALSE;
+static GLboolean HaveVP = GL_FALSE;
+static GLboolean HaveFP = GL_FALSE;
+static GLboolean HaveFP_Shadow = GL_FALSE;
+static GLboolean UseVP = GL_FALSE;
static GLboolean HavePackedDepthStencil = GL_FALSE;
static GLboolean UsePackedDepthStencil = GL_FALSE;
static GLboolean HaveEXTshadowFuncs = GL_FALSE;
@@ -91,6 +112,103 @@ static GLuint DisplayMode;
+#define MAT4_MUL(dest_vec, src_mat, src_vec) \
+ "DP4 " dest_vec ".x, " src_mat "[0], " src_vec ";\n" \
+ "DP4 " dest_vec ".y, " src_mat "[1], " src_vec ";\n" \
+ "DP4 " dest_vec ".z, " src_mat "[2], " src_vec ";\n" \
+ "DP4 " dest_vec ".w, " src_mat "[3], " src_vec ";\n"
+
+#define MAT3_MUL(dest_vec, src_mat, src_vec) \
+ "DP3 " dest_vec ".x, " src_mat "[0], " src_vec ";\n" \
+ "DP3 " dest_vec ".y, " src_mat "[1], " src_vec ";\n" \
+ "DP3 " dest_vec ".z, " src_mat "[2], " src_vec ";\n"
+
+#define NORMALIZE(dest, src) \
+ "DP3 " dest ".w, " src ", " src ";\n" \
+ "RSQ " dest ".w, " dest ".w;\n" \
+ "MUL " dest ", " src ", " dest ".w;\n"
+
+/**
+ * Vertex program for shadow mapping.
+ */
+static const char vert_code[] =
+ "!!ARBvp1.0\n"
+ "ATTRIB iPos = vertex.position;\n"
+ "ATTRIB iNorm = vertex.normal;\n"
+
+ "PARAM mvinv[4] = { state.matrix.modelview.invtrans };\n"
+ "PARAM mvp[4] = { state.matrix.mvp };\n"
+ "PARAM mv[4] = { state.matrix.modelview };\n"
+ "PARAM texmat[4] = { state.matrix.texture[0] };\n"
+ "PARAM lightPos = state.light[0].position;\n"
+ "PARAM ambientCol = state.lightprod[0].ambient;\n"
+ "PARAM diffuseCol = state.lightprod[0].diffuse;\n"
+
+ "TEMP n, lightVec;\n"
+ "ALIAS V = lightVec;\n"
+ "ALIAS NdotL = n;\n"
+
+ "OUTPUT oPos = result.position;\n"
+ "OUTPUT oColor = result.color;\n"
+ "OUTPUT oTex = result.texcoord[0];\n"
+
+ /* Transform the vertex to clip coordinates. */
+ MAT4_MUL("oPos", "mvp", "iPos")
+
+ /* Transform the vertex to eye coordinates. */
+ MAT4_MUL("V", "mv", "iPos")
+
+ /* Transform the vertex to projected light coordinates. */
+ MAT4_MUL("oTex", "texmat", "iPos")
+
+ /* Transform the normal to eye coordinates. */
+ MAT3_MUL("n", "mvinv", "iNorm")
+
+ /* Calculate the vector from the vertex to the light in eye
+ * coordinates.
+ */
+ "SUB lightVec, lightPos, V;\n"
+ NORMALIZE("lightVec", "lightVec")
+
+ /* Compute diffuse lighting coefficient.
+ */
+ "DP3 NdotL.x, n, lightVec;\n"
+ "MAX NdotL.x, NdotL.x, {0.0};\n"
+ "MIN NdotL.x, NdotL.x, {1.0};\n"
+
+ /* Accumulate color contributions.
+ */
+ "MOV oColor, diffuseCol;\n"
+ "MAD oColor.xyz, NdotL.x, diffuseCol, ambientCol;\n"
+ "END\n"
+ ;
+
+static const char frag_code[] =
+ "!!ARBfp1.0\n"
+
+ "TEMP shadow, temp;\n"
+
+ "TXP shadow, fragment.texcoord[0], texture[0], 2D;\n"
+ "RCP temp.x, fragment.texcoord[0].w;\n"
+ "MUL temp.x, temp.x, fragment.texcoord[0].z;\n"
+ "SGE shadow, shadow.x, temp.x;\n"
+ "MUL result.color.rgb, fragment.color, shadow.x;\n"
+ "MOV result.color.a, fragment.color;\n"
+ "END\n"
+ ;
+
+static const char frag_shadow_code[] =
+ "!!ARBfp1.0\n"
+ "OPTION ARB_fragment_program_shadow;\n"
+
+ "TEMP shadow;\n"
+
+ "TXP shadow, fragment.texcoord[0], texture[0], SHADOW2D;\n"
+ "MUL result.color.rgb, fragment.color, shadow.x;\n"
+ "MOV result.color.a, fragment.color.a;\n"
+ "END\n"
+ ;
+
static void
DrawScene(void)
{
@@ -134,27 +252,56 @@ DrawScene(void)
}
-/*
- * Load the GL_TEXTURE matrix with the projection from the light
- * source's point of view.
+/**
+ * Calculate modelview and project matrices for the light
+ *
+ * Stores the results in \c lightProjection (projection matrix) and
+ * \c lightModelview (modelview matrix).
*/
static void
MakeShadowMatrix(const GLfloat lightPos[4], const GLfloat spotDir[3],
GLfloat spotAngle, GLfloat shadowNear, GLfloat shadowFar)
{
- GLfloat d;
-
- glMatrixMode(GL_TEXTURE);
+ /* compute frustum to enclose spot light cone */
+ const GLfloat d = shadowNear * tan(spotAngle);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
glLoadIdentity();
- glTranslatef(0.5, 0.5, 0.5 + Bias);
- glScalef(0.5, 0.5, 0.5);
- d = shadowNear * tan(spotAngle);
glFrustum(-d, d, -d, d, shadowNear, shadowFar);
+ glGetFloatv(GL_PROJECTION_MATRIX, lightProjection);
+ glPopMatrix();
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
gluLookAt(lightPos[0], lightPos[1], lightPos[2],
lightPos[0] + spotDir[0],
lightPos[1] + spotDir[1],
lightPos[2] + spotDir[2],
- 0, 1, 0);
+ 0.0, 1.0, 0.0);
+ glGetFloatv(GL_MODELVIEW_MATRIX, lightModelview);
+ glPopMatrix();
+}
+
+
+/**
+ * Load \c GL_TEXTURE matrix with light's MVP matrix.
+ */
+static void SetShadowTextureMatrix(void)
+{
+ static const GLfloat biasMatrix[16] = {
+ 0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0,
+ };
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadMatrixf(biasMatrix);
+ glTranslatef(0.0, 0.0, Bias);
+ glMultMatrixf(lightProjection);
+ glMultMatrixf(lightModelview);
glMatrixMode(GL_MODELVIEW);
}
@@ -258,7 +405,6 @@ RenderShadowMap(void)
{
GLenum depthFormat; /* GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL_EXT */
GLenum depthType; /* GL_UNSIGNED_INT_24_8_EXT or GL_UNSIGNED_INT */
- float d;
if (WindowWidth >= 1024 && WindowHeight >= 1024) {
ShadowTexWidth = ShadowTexHeight = 1024;
@@ -283,27 +429,34 @@ RenderShadowMap(void)
depthType = GL_UNSIGNED_INT;
}
- /* compute frustum to enclose spot light cone */
- d = ShadowNear * tan(SpotAngle);
-
glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-d, d, -d, d, ShadowNear, ShadowFar);
+ glLoadMatrixf(lightProjection);
+
glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(LightPos[0], LightPos[1], LightPos[2], /* from */
- 0, 0, 0, /* target */
- 0, 1, 0); /* up */
+ glLoadMatrixf(lightModelview);
if (UseFBO) {
+ GLenum fbo_status;
+
glTexImage2D(GL_TEXTURE_2D, 0, depthFormat,
ShadowTexWidth, ShadowTexHeight, 0,
depthFormat, depthType, NULL);
+
+ /* Set the filter mode so that the texture is texture-complete.
+ * Otherwise it will cause the framebuffer to fail the framebuffer
+ * completeness test.
+ */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ShadowFBO);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
- assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)
- == GL_FRAMEBUFFER_COMPLETE_EXT);
+
+ fbo_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ if (fbo_status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ fprintf(stderr, "FBO not complete! status = 0x%04x\n", fbo_status);
+ assert(fbo_status == GL_FRAMEBUFFER_COMPLETE_EXT);
+ }
}
assert(!glIsEnabled(GL_TEXTURE_1D));
@@ -376,10 +529,8 @@ ShowShadowMap(void)
DisableTexgen();
/* interpret texture's depth values as luminance values */
-#if defined(GL_ARB_shadow)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
-#endif
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBegin(GL_POLYGON);
@@ -407,6 +558,7 @@ Display(void)
LightPos, SpotDir);
if (NeedNewShadowMap) {
+ MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar);
RenderShadowMap();
NeedNewShadowMap = GL_FALSE;
}
@@ -444,12 +596,11 @@ Display(void)
}
if (DisplayMode == SHOW_DEPTH_MAPPING) {
-#if defined(GL_ARB_shadow)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
-#endif
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
- MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar);
+
+ SetShadowTextureMatrix();
EnableIdentityTexgen();
}
else if (DisplayMode == SHOW_DISTANCE) {
@@ -463,20 +614,42 @@ Display(void)
}
else {
assert(DisplayMode == SHOW_SHADOWS);
-#if defined(GL_ARB_shadow)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
GL_COMPARE_R_TO_TEXTURE_ARB);
-#endif
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ if (curr_frag > 0) {
+ glEnable(GL_FRAGMENT_PROGRAM_ARB);
+ }
+ else {
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ }
glEnable(GL_TEXTURE_2D);
- MakeShadowMatrix(LightPos, SpotDir, SpotAngle, ShadowNear, ShadowFar);
- EnableIdentityTexgen();
+
+ SetShadowTextureMatrix();
+
+ if (UseVP) {
+ glEnable(GL_VERTEX_PROGRAM_ARB);
+ }
+ else {
+ glEnable(GL_LIGHTING);
+ EnableIdentityTexgen();
+ }
}
DrawScene();
- DisableTexgen();
- glDisable(GL_TEXTURE_1D);
+ if (UseVP) {
+ glDisable(GL_VERTEX_PROGRAM_ARB);
+ }
+ else {
+ DisableTexgen();
+ glDisable(GL_LIGHTING);
+ }
+
+ if (curr_frag > 0) {
+ glDisable(GL_FRAGMENT_PROGRAM_ARB);
+ }
+
glDisable(GL_TEXTURE_2D);
}
@@ -548,6 +721,14 @@ Key(unsigned char key, int x, int y)
case 'm':
DisplayMode = SHOW_DEPTH_MAPPING;
break;
+ case 'M':
+ curr_frag = (1 + curr_frag) % max_frag;
+ printf("Using fragment %s\n", FragProgNames[curr_frag]);
+
+ if (HaveFP) {
+ glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_progs[curr_frag]);
+ }
+ break;
case 'n':
case 's':
case ' ':
@@ -559,10 +740,8 @@ Key(unsigned char key, int x, int y)
if (Operator >= 8)
Operator = 0;
printf("Operator: %s\n", OperatorName[Operator]);
-#if defined(GL_ARB_shadow)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB,
OperatorFunc[Operator]);
-#endif
}
break;
case 'p':
@@ -579,6 +758,11 @@ Key(unsigned char key, int x, int y)
NeedNewShadowMap = GL_TRUE;
}
break;
+ case 'v':
+ UseVP = !UseVP && HaveVP;
+ printf("Using vertex %s mode.\n",
+ UseVP ? "program" : "fixed-function");
+ break;
case 'z':
Zrot -= step;
break;
@@ -633,28 +817,62 @@ SpecialKey(int key, int x, int y)
}
+/* A helper for finding errors in program strings */
+static int FindLine( const char *program, int position )
+{
+ int i, line = 1;
+ for (i = 0; i < position; i++) {
+ if (program[i] == '\n')
+ line++;
+ }
+ return line;
+}
+
+
+static GLuint
+compile_program(GLenum target, const char *code)
+{
+ GLuint p;
+ GLint errorPos;
+
+
+ glGenProgramsARB(1, & p);
+
+ glBindProgramARB(target, p);
+ glProgramStringARB(target, GL_PROGRAM_FORMAT_ASCII_ARB,
+ strlen(code), code);
+ glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
+ if (glGetError() != GL_NO_ERROR || errorPos != -1) {
+ int l = FindLine(code, errorPos);
+ printf("Fragment Program Error (pos=%d line=%d): %s\n", errorPos, l,
+ (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
+ exit(0);
+ }
+
+ glBindProgramARB(target, 0);
+ return p;
+}
+
static void
Init(void)
{
static const GLfloat borderColor[4] = {1.0, 0.0, 0.0, 0.0};
-#if defined(GL_ARB_depth_texture) && defined(GL_ARB_shadow)
if (!glutExtensionSupported("GL_ARB_depth_texture") ||
!glutExtensionSupported("GL_ARB_shadow")) {
-#else
- if (1) {
-#endif
printf("Sorry, this demo requires the GL_ARB_depth_texture and GL_ARB_shadow extensions\n");
exit(1);
}
printf("Using GL_ARB_depth_texture and GL_ARB_shadow\n");
-#if defined(GL_ARB_shadow_ambient)
+ HaveVP = glutExtensionSupported("GL_ARB_vertex_program");
+ HaveFP = glutExtensionSupported("GL_ARB_fragment_program");
+ HaveFP_Shadow = glutExtensionSupported("GL_ARB_fragment_program_shadow");
+
HaveShadowAmbient = glutExtensionSupported("GL_ARB_shadow_ambient");
if (HaveShadowAmbient) {
printf("and GL_ARB_shadow_ambient\n");
}
-#endif
HaveEXTshadowFuncs = glutExtensionSupported("GL_EXT_shadow_funcs");
@@ -677,15 +895,12 @@ Init(void)
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-#if defined(GL_ARB_shadow)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,
GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
-#endif
+
if (HaveShadowAmbient) {
-#if defined(GL_ARB_shadow_ambient)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FAIL_VALUE_ARB, 0.3);
-#endif
}
#if defined(GL_EXT_framebuffer_object)
@@ -720,6 +935,25 @@ Init(void)
256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
}
+ if (HaveVP) {
+ vert_prog = compile_program(GL_VERTEX_PROGRAM_ARB, vert_code);
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vert_prog);
+ }
+
+ max_frag = 1;
+ frag_progs[0] = 0;
+
+ if (HaveFP) {
+ frag_progs[1] = compile_program(GL_FRAGMENT_PROGRAM_ARB, frag_code);
+ max_frag = 2;
+ }
+
+ if (HaveFP && HaveFP_Shadow) {
+ frag_progs[2] = compile_program(GL_FRAGMENT_PROGRAM_ARB,
+ frag_shadow_code);
+ max_frag = 3;
+ }
+
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
@@ -738,6 +972,8 @@ PrintHelp(void)
printf(" f = toggle nearest/bilinear texture filtering\n");
printf(" b/B = decrease/increase shadow map Z bias\n");
printf(" p = toggle use of packed depth/stencil\n");
+ printf(" M = cycle through fragment program modes\n");
+ printf(" v = toggle vertex program modes\n");
printf(" cursor keys = rotate scene\n");
printf(" <shift> + cursor keys = rotate light source\n");
if (HaveEXTshadowFuncs)
diff --git a/progs/demos/spriteblast.c b/progs/demos/spriteblast.c
index f0d3d0dfd41..5ad8e4d9a94 100644
--- a/progs/demos/spriteblast.c
+++ b/progs/demos/spriteblast.c
@@ -333,13 +333,13 @@ menu(int option)
smooth = 0;
break;
case 10:
- glPointSize(4.0);
+ glPointSize(16.0);
break;
case 11:
- glPointSize(8.0);
+ glPointSize(32.0);
break;
case 12:
- glPointSize(16.0);
+ glPointSize(64.0);
break;
case 13:
spin = 1 - spin;
@@ -411,19 +411,19 @@ key(unsigned char c, int x, int y)
glutPostRedisplay();
break;
case '1':
- glPointSize(2.0);
+ glPointSize(16.0);
glutPostRedisplay();
break;
case '2':
- glPointSize(4.0);
+ glPointSize(32.0);
glutPostRedisplay();
break;
case '3':
- glPointSize(8.0);
+ glPointSize(64.0);
glutPostRedisplay();
break;
case '4':
- glPointSize(16.0);
+ glPointSize(128.0);
glutPostRedisplay();
break;
case 27:
@@ -526,9 +526,9 @@ main(int argc, char **argv)
glutAddMenuEntry("Threshold 10", 7);
glutAddMenuEntry("Point smooth on", 8);
glutAddMenuEntry("Point smooth off", 9);
- glutAddMenuEntry("Point size 4", 10);
- glutAddMenuEntry("Point size 8", 11);
- glutAddMenuEntry("Point size 16", 12);
+ glutAddMenuEntry("Point size 16", 10);
+ glutAddMenuEntry("Point size 32", 11);
+ glutAddMenuEntry("Point size 64", 12);
glutAddMenuEntry("Toggle spin", 13);
glutAddMenuEntry("200 points ", 14);
glutAddMenuEntry("500 points ", 15);
@@ -544,7 +544,7 @@ main(int argc, char **argv)
glEnable(GL_DEPTH_TEST);
glEnable(GL_POINT_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPointSize(16.0);
+ glPointSize(32.0);
#ifdef GL_ARB_point_parameters
glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
#endif
diff --git a/progs/demos/tessdemo.c b/progs/demos/tessdemo.c
index 26403eee0a2..f71cea12744 100644
--- a/progs/demos/tessdemo.c
+++ b/progs/demos/tessdemo.c
@@ -4,10 +4,10 @@
* Updated for GLU 1.3 tessellation by Gareth Hughes <[email protected]>
*/
-#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <GL/glut.h>
#define MAX_POINTS 256
#define MAX_CONTOURS 32
diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index e08d4102c88..37fa312c30c 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -5,17 +5,12 @@ include $(TOP)/configs/current
INCDIR = $(TOP)/include
-OSMESA_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa -lGLU -lGL $(APP_LIB_DEPS)
-
-OSMESA16_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa16 -lGLU -lGL $(APP_LIB_DEPS)
-
-OSMESA32_LIBS = -L$(TOP)/$(LIB_DIR) -lglut -lOSMesa32 -lGLU -lGL $(APP_LIB_DEPS)
-
LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME)
PROGS = \
brick \
bump \
+ deriv \
mandelbrot \
noise \
toyball \
diff --git a/progs/glsl/deriv.c b/progs/glsl/deriv.c
new file mode 100644
index 00000000000..8b652bc1e46
--- /dev/null
+++ b/progs/glsl/deriv.c
@@ -0,0 +1,319 @@
+/**
+ * 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/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#include "extfuncs.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 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);
+ glCallList(CurList);
+ glPopMatrix();
+
+ 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();
+ 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_func(fragShader);
+ glDeleteShader_func(vertShader);
+ glDeleteProgram_func(program);
+ glutDestroyWindow(win);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+
+ switch(key) {
+ case ' ':
+ case 'a':
+ anim = !anim;
+ if (anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case '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();
+}
+
+
+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
+LoadAndCompileShader(GLuint shader, const char *text)
+{
+ GLint stat;
+
+ glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
+
+ glCompileShader_func(shader);
+
+ glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetShaderInfoLog_func(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_func(prog, GL_LINK_STATUS, &stat);
+ if (!stat) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetProgramInfoLog_func(prog, 1000, &len, log);
+ fprintf(stderr, "Linker error:\n%s\n", log);
+ }
+}
+
+
+static void
+Init(void)
+{
+ static const char *fragShaderText =
+ "void main() {\n"
+ " gl_FragColor = abs(dFdy(gl_TexCoord[0])) * 50.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";
+ const char *version;
+
+ 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);
+ }
+
+ GetExtensionFuncs();
+
+ fragShader = glCreateShader_func(GL_FRAGMENT_SHADER);
+ if (FragProgFile)
+ ReadShader(fragShader, FragProgFile);
+ else
+ LoadAndCompileShader(fragShader, fragShaderText);
+
+ vertShader = glCreateShader_func(GL_VERTEX_SHADER);
+ if (VertProgFile)
+ ReadShader(vertShader, VertProgFile);
+ else
+ LoadAndCompileShader(vertShader, vertShaderText);
+
+ program = glCreateProgram_func();
+ glAttachShader_func(program, fragShader);
+ glAttachShader_func(program, vertShader);
+ glLinkProgram_func(program);
+ CheckLink(program);
+ glUseProgram_func(program);
+
+ /*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_func(program));
+ assert(glIsShader_func(fragShader));
+ assert(glIsShader_func(vertShader));
+
+ glColor3f(1, 0, 0);
+}
+
+
+static void
+ParseOptions(int argc, char *argv[])
+{
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-fs") == 0) {
+ FragProgFile = argv[i+1];
+ }
+ else if (strcmp(argv[i], "-vs") == 0) {
+ VertProgFile = argv[i+1];
+ }
+ }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition( 0, 0);
+ glutInitWindowSize(200, 200);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Redisplay);
+ if (anim)
+ glutIdleFunc(Idle);
+ ParseOptions(argc, argv);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/miniglx/miniglxtest.c b/progs/miniglx/miniglxtest.c
index ecc5786b73a..85c25be4ed5 100644
--- a/progs/miniglx/miniglxtest.c
+++ b/progs/miniglx/miniglxtest.c
@@ -1,5 +1,3 @@
-/* $Id: miniglxtest.c,v 1.3 2004/03/25 14:58:39 brianp Exp $ */
-
/*
* Test the mini GLX interface.
*/
@@ -7,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <GL/gl.h>
#define USE_MINI_GLX 1
@@ -16,90 +15,86 @@
#include <GL/glx.h>
#endif
-#define FRONTBUFFER 1
-#define NR 6
-#define DO_SLEEPS 1
-#define NR_DISPLAYS 2
+static GLXContext ctx;
-GLXContext ctx;
+static GLuint NumFrames = 100;
+static GLuint NumDisplays = 1;
+static GLboolean Texture = GL_FALSE;
+static GLboolean SingleBuffer = GL_FALSE;
+static GLboolean Sleeps = GL_TRUE;
-static void _subset_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
+static void
+rect(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
{
- glBegin( GL_QUADS );
- glVertex2f( x1, y1 );
- glVertex2f( x2, y1 );
- glVertex2f( x2, y2 );
- glVertex2f( x1, y2 );
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glColor3f(0, 0, 1); glVertex2f(x1, y1);
+ glTexCoord2f(1, 0); glColor3f(1, 0, 0); glVertex2f(x2, y1);
+ glTexCoord2f(1, 1); glColor3f(0, 1, 0); glVertex2f(x2, y2);
+ glTexCoord2f(0, 1); glColor3f(0, 0, 0); glVertex2f(x1, y2);
glEnd();
}
-
-static void redraw( Display *dpy, Window w, int rot )
+static void
+redraw(Display *dpy, Window w, int rot)
{
- printf("Redraw event\n");
-
-#if FRONTBUFFER
- glDrawBuffer( GL_FRONT );
-#else
-/* glDrawBuffer( GL_BACK ); */
-#endif
+ GLfloat a;
- glClearColor( rand()/(float)RAND_MAX,
- rand()/(float)RAND_MAX,
- rand()/(float)RAND_MAX,
- 1);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClear( GL_COLOR_BUFFER_BIT );
-
-#if 1
- glColor3f( rand()/(float)RAND_MAX,
- rand()/(float)RAND_MAX,
- rand()/(float)RAND_MAX );
glPushMatrix();
- glRotatef(rot, 0, 0, 1);
- glScalef(.5, .5, .5);
- _subset_Rectf( -1, -1, 1, 1 );
+ glRotatef(rot, 0, 0, 1);
+ glScalef(.5, .5, .5);
+ for (a = 0.0; a < 360.0; a += 30.0) {
+ glPushMatrix();
+ glRotatef(a, 0, 0, 1);
+ glRotatef(40, 1, 0, 0);
+ glColor3f(a / 360.0, 1-a/360.0, 0);
+ rect(0.3, -0.25, 1.5, 0.25);
+ glPopMatrix();
+ }
glPopMatrix();
-#endif
-#if FRONTBUFFER
- glFlush();
-#else
- glXSwapBuffers( dpy, w );
-#endif
- glFinish();
+ if (SingleBuffer)
+ glFlush();
+ else
+ glXSwapBuffers(dpy, w);
}
-static Window make_rgb_db_window( Display *dpy,
- unsigned int width, unsigned int height )
+static Window
+make_window(Display *dpy, unsigned int width, unsigned int height)
{
- int attrib[] = { GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
-#if !FRONTBUFFER
- GLX_DOUBLEBUFFER,
-#endif
- None };
- int scrnum;
+ int attrib_single[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DEPTH_SIZE, 1,
+ None };
+ int attrib_double[] = { GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DEPTH_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None };
+ int *attrib = SingleBuffer ? attrib_single : attrib_double;
+ int scrnum = 0;
XSetWindowAttributes attr;
unsigned long mask;
Window root;
Window win;
XVisualInfo *visinfo;
- scrnum = 0;
- root = RootWindow( dpy, scrnum );
+ root = RootWindow(dpy, scrnum);
- if (!(visinfo = glXChooseVisual( dpy, scrnum, attrib ))) {
+ if (!(visinfo = glXChooseVisual(dpy, scrnum, attrib))) {
printf("Error: couldn't get an RGB, Double-buffered visual\n");
exit(1);
}
- if(!(ctx = glXCreateContext( dpy, visinfo, NULL, True ))) {
+ if (!(ctx = glXCreateContext(dpy, visinfo, NULL, True))) {
printf("Error: glXCreateContext failed\n");
exit(1);
}
@@ -107,19 +102,19 @@ static Window make_rgb_db_window( Display *dpy,
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
- attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
+ attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
- win = XCreateWindow( dpy, root, 0, 0, width, height,
+ win = XCreateWindow(dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
- visinfo->visual, mask, &attr );
+ visinfo->visual, mask, &attr);
if (!win) {
printf("Error: XCreateWindow failed\n");
exit(1);
}
- glXMakeCurrent( dpy, win, ctx );
+ glXMakeCurrent(dpy, win, ctx);
glViewport(0, 0, width, height);
@@ -127,22 +122,24 @@ static Window make_rgb_db_window( Display *dpy,
}
-static void event_loop( Display *dpy, Window win )
+static void
+event_loop(Display *dpy, Window win)
{
int i;
- printf("Hang on... drawing %d frames\n", NR);
- for (i = 0; i < NR; i++) {
- redraw( dpy, win, i*10 );
- if (DO_SLEEPS) {
- printf("sleep(1)\n");
- sleep(1);
+ printf("Drawing %d frames\n", NumFrames);
+
+ for (i = 0; i < NumFrames; i++) {
+ redraw(dpy, win, -i*2);
+ if (Sleeps) {
+ usleep(20000);
}
}
}
-static int foo( void )
+static int
+runtest(void)
{
Display *dpy;
Window win;
@@ -153,41 +150,121 @@ static int foo( void )
return 1;
}
- win = make_rgb_db_window( dpy, 800, 600);
+ win = make_window(dpy, 800, 600);
srand(getpid());
- glShadeModel( GL_FLAT );
- glClearColor( 0.5, 0.5, 0.5, 1.0 );
+ /* init GL state */
+ glClearColor(0.5, 0.5, 0.5, 1.0);
+ glEnable(GL_DEPTH_TEST);
+ if (Texture) {
+ GLubyte image[16][16][4];
+ GLint i, j;
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ if (((i / 2) ^ (j / 2)) & 1) {
+ image[i][j][0] = 255;
+ image[i][j][1] = 255;
+ image[i][j][2] = 255;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = 128;
+ image[i][j][1] = 128;
+ image[i][j][2] = 128;
+ image[i][j][3] = 128;
+ }
+ }
+ }
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glEnable(GL_TEXTURE_2D);
+ }
+ if (SingleBuffer) {
+ glDrawBuffer(GL_FRONT);
+ glReadBuffer(GL_FRONT);
+ }
+ else {
+ glDrawBuffer(GL_BACK);
+ }
- XMapWindow( dpy, win );
+ XMapWindow(dpy, win);
+ /* wait for window to get mapped */
{
XEvent e;
while (1) {
- XNextEvent( dpy, &e );
+ XNextEvent(dpy, &e);
if (e.type == MapNotify && e.xmap.window == win) {
break;
}
}
}
- event_loop( dpy, win );
+ event_loop(dpy, win);
- glXDestroyContext( dpy, ctx );
- XDestroyWindow( dpy, win );
+ glXDestroyContext(dpy, ctx);
+ XDestroyWindow(dpy, win);
- XCloseDisplay( dpy );
+ XCloseDisplay(dpy);
return 0;
}
-int main()
+static void
+usage(void)
+{
+ printf("Usage:\n");
+ printf(" -f N render N frames (default %d)\n", NumFrames);
+ printf(" -d N do N display cycles\n");
+ printf(" -t texturing\n");
+ printf(" -s single buffering\n");
+ printf(" -n no usleep() delay\n");
+}
+
+
+static void
+parse_args(int argc, char *argv[])
{
int i;
- for (i = 0 ; i < NR_DISPLAYS ; i++) {
- if (foo() != 0)
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-f") == 0) {
+ NumFrames = atoi(argv[i + 1]);
+ i++;
+ }
+ else if (strcmp(argv[i], "-d") == 0) {
+ NumDisplays = atoi(argv[i + 1]);
+ i++;
+ }
+ else if (strcmp(argv[i], "-n") == 0) {
+ Sleeps = GL_FALSE;
+ }
+ else if (strcmp(argv[i], "-s") == 0) {
+ SingleBuffer = GL_TRUE;
+ }
+ else if (strcmp(argv[i], "-t") == 0) {
+ Texture = GL_TRUE;
+ }
+ else {
+ usage();
+ exit(1);
+ }
+ }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+
+ parse_args(argc, argv);
+
+ for (i = 0; i < NumDisplays; i++) {
+ if (runtest() != 0)
break;
}
diff --git a/progs/redbook/Imakefile b/progs/redbook/Imakefile
deleted file mode 100644
index ab3b6d7f793..00000000000
--- a/progs/redbook/Imakefile
+++ /dev/null
@@ -1,221 +0,0 @@
-LOCAL_LIBRARIES = $(XLIB) $(TOP)\lib\Mesaaux.a $(TOP)\lib\Mesaglu.a $(TOP)\lib\MesaGL.a
-
-INCLUDES = -I$(TOP)\include
-
-SRCS = accanti.c \
- accnot.c \
- accpersp.c \
- accum.c \
- aim.c \
- alpha.c \
- alpha3D.c \
- anti.c \
- antiindex.c \
- antipindex.c \
- antipoint.c \
- antipoly.c \
- bezcurve.c \
- bezmesh.c \
- bezsurf.c \
- checker.c \
- checker2.c \
- chess.c \
- clip.c \
- colormat.c \
- cone.c \
- cube.c \
- curve.c \
- depthcue.c \
- disk.c \
- dof.c \
- dofnot.c \
- double.c \
- drawf.c \
- feedback.c \
- fog.c \
- fogindex.c \
- font.c \
- light.c \
- linelist.c \
- lines.c \
- list.c \
- list2.c \
- maplight.c \
- material.c \
- mipmap.c \
- model.c \
- movelight.c \
- nurbs.c \
- pickdepth.c \
- pickline.c \
- picksquare.c \
- plane.c \
- planet.c \
- planetup.c \
- polys.c \
- robot.c \
- sccolorlight.c \
- scene.c \
- scenebamb.c \
- sceneflat.c \
- select.c \
- simple.c \
- smooth.c \
- sphere.c \
- stencil.c \
- stroke.c \
- surface.c \
- tea.c \
- teaambient.c \
- teapots.c \
- texgen.c \
- texturesurf.c \
- trim.c \
- xfont.c
-
-PROGRAMS = ProgramTargetName(accanti) \
- ProgramTargetName(accnot) \
- ProgramTargetName(accpersp) \
- ProgramTargetName(accum) \
- ProgramTargetName(aim) \
- ProgramTargetName(alpha) \
- ProgramTargetName(alpha3D) \
- ProgramTargetName(anti) \
- ProgramTargetName(antiindex) \
- ProgramTargetName(antipindex) \
- ProgramTargetName(antipoint) \
- ProgramTargetName(antipoly) \
- ProgramTargetName(bezcurve) \
- ProgramTargetName(bezmesh) \
- ProgramTargetName(bezsurf) \
- ProgramTargetName(checker) \
- ProgramTargetName(checker2) \
- ProgramTargetName(chess) \
- ProgramTargetName(clip) \
- ProgramTargetName(colormat) \
- ProgramTargetName(cone) \
- ProgramTargetName(cube) \
- ProgramTargetName(curve) \
- ProgramTargetName(depthcue) \
- ProgramTargetName(disk) \
- ProgramTargetName(dof) \
- ProgramTargetName(dofnot) \
- ProgramTargetName(double) \
- ProgramTargetName(drawf) \
- ProgramTargetName(feedback) \
- ProgramTargetName(fog) \
- ProgramTargetName(fogindex) \
- ProgramTargetName(font) \
- ProgramTargetName(light) \
- ProgramTargetName(linelist) \
- ProgramTargetName(lines) \
- ProgramTargetName(list) \
- ProgramTargetName(list2) \
- ProgramTargetName(maplight) \
- ProgramTargetName(material) \
- ProgramTargetName(mipmap) \
- ProgramTargetName(model) \
- ProgramTargetName(movelight) \
- ProgramTargetName(nurbs) \
- ProgramTargetName(pickdepth) \
- ProgramTargetName(pickline) \
- ProgramTargetName(picksquare) \
- ProgramTargetName(plane) \
- ProgramTargetName(planet) \
- ProgramTargetName(planetup) \
- ProgramTargetName(polys) \
- ProgramTargetName(robot) \
- ProgramTargetName(sccolorlight) \
- ProgramTargetName(scene) \
- ProgramTargetName(scenebamb) \
- ProgramTargetName(sceneflat) \
- ProgramTargetName(select) \
- ProgramTargetName(simple) \
- ProgramTargetName(smooth) \
- ProgramTargetName(sphere) \
- ProgramTargetName(stencil) \
- ProgramTargetName(stroke) \
- ProgramTargetName(surface) \
- ProgramTargetName(tea) \
- ProgramTargetName(teaambient) \
- ProgramTargetName(teapots) \
- ProgramTargetName(texgen) \
- ProgramTargetName(texturesurf) \
- ProgramTargetName(trim) \
- ProgramTargetName(xfont)
-
-AllTarget($(PROGRAMS))
-
-NormalProgramTarget(accanti,accanti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(accnot,accnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(accpersp,accpersp.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(accum,accum.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(aim,aim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(alpha,alpha.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(alpha3D,alpha3D.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(anti,anti.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(antiindex,antiindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(antipindex,antipindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(antipoint,antipoint.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(antipoly,antipoly.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(bezcurve,bezcurve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(bezmesh,bezmesh.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(bezsurf,bezsurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(checker,checker.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(checker2,checker2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(chess,chess.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(clip,clip.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(colormat,colormat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(cone,cone.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(cube,cube.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(curve,curve.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(depthcue,depthcue.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(disk,disk.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(dof,dof.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(dofnot,dofnot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(double,double.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(drawf,drawf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(feedback,feedback.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(fog,fog.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(fogindex,fogindex.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(font,font.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(light,light.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(linelist,linelist.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(lines,lines.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(list,list.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(list2,list2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(maplight,maplight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(material,material.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(mipmap,mipmap.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(model,model.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(movelight,movelight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(nurbs,nurbs.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(pickdepth,pickdepth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(pickline,pickline.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(picksquare,picksquare.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(plane,plane.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(planet,planet.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(planetup,planetup.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(polys,polys.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(robot,robot.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(sccolorlight,sccolorlight.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(scene,scene.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(scenebamb,scenebamb.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(sceneflat,sceneflat.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(select,select.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(simple,simple.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(smooth,smooth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(sphere,sphere.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(stencil,stencil.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(stroke,stroke.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(surface,surface.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(tea,tea.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(teaambient,teaambient.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(teapots,teapots.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(texgen,texgen.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(texturesurf,texturesurf.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(trim,trim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(xfont,xfont.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-
-DependTarget()
-
diff --git a/progs/samples/Imakefile b/progs/samples/Imakefile
deleted file mode 100644
index 948a9783597..00000000000
--- a/progs/samples/Imakefile
+++ /dev/null
@@ -1,101 +0,0 @@
-LOCAL_LIBRARIES = $(XLIB) $(TOP)\lib\glut.a $(TOP)\lib\Mesaglu.a $(TOP)\lib\MesaGL.a
-
-INCLUDES = -I$(TOP)\include
-
-SRCS = accum.c \
- bitmap1.c \
- bitmap2.c \
- blendeq.c \
- blendxor.c \
- copy.c \
- cursor.c \
- depth.c \
- eval.c \
- fog.c \
- font.c \
- line.c \
- logo.c \
- nurb.c \
- oglinfo.c \
- olympic.c \
- overlay.c \
- point.c \
- prim.c \
- quad.c \
- select.c \
- shape.c \
- speed.c \
- sphere.c \
- star.c \
- stencil.c \
- stretch.c \
- texture.c \
- tri.c \
- wave.c
-
-PROGRAMS = ProgramTargetName(accum) \
- ProgramTargetName(bitmap1) \
- ProgramTargetName(bitmap2) \
- ProgramTargetName(blendeq) \
- ProgramTargetName(blendxor) \
- ProgramTargetName(copy) \
- ProgramTargetName(cursor) \
- ProgramTargetName(depth) \
- ProgramTargetName(eval) \
- ProgramTargetName(fog) \
- ProgramTargetName(font) \
- ProgramTargetName(line) \
- ProgramTargetName(logo) \
- ProgramTargetName(nurb) \
- ProgramTargetName(oglinfo) \
- ProgramTargetName(olympic) \
- ProgramTargetName(overlay) \
- ProgramTargetName(point) \
- ProgramTargetName(prim) \
- ProgramTargetName(quad) \
- ProgramTargetName(select) \
- ProgramTargetName(shape) \
- ProgramTargetName(speed) \
- ProgramTargetName(sphere) \
- ProgramTargetName(star) \
- ProgramTargetName(stencil) \
- ProgramTargetName(stretch) \
- ProgramTargetName(texture) \
- ProgramTargetName(tri) \
- ProgramTargetName(wave)
-
-AllTarget($(PROGRAMS))
-
-NormalProgramTarget(accum,accum.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(bitmap1,bitmap1.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(bitmap2,bitmap2.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(blendeq,blendeq.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(blendxor,blendxor.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(copy,copy.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(cursor,cursor.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(depth,depth.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(eval,eval.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(fog,fog.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(font,font.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(line,line.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(logo,logo.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(nurb,nurb.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(oglinfo,oglinfo.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(olympic,olympic.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(overlay,overlay.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(point,point.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(prim,prim.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(quad,quad.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(select,select.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(shape,shape.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(speed,speed.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(sphere,sphere.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(star,star.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(stencil,stencil.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(stretch,stretch.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(texture,texture.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(tri,tri.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-NormalProgramTarget(wave,wave.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter)
-
-DependTarget()
-
diff --git a/progs/tests/Makefile b/progs/tests/Makefile
index 9edef74fb2c..9016efe9e77 100644
--- a/progs/tests/Makefile
+++ b/progs/tests/Makefile
@@ -23,6 +23,7 @@ SOURCES = \
arbvptest3.c \
arbvptorus.c \
arbvpwarpmesh.c \
+ arraytexture.c \
blendminmax.c \
blendsquare.c \
bufferobj.c \
@@ -54,6 +55,7 @@ SOURCES = \
pbo.c \
prog_parameter.c \
projtex.c \
+ random.c \
readrate.c \
seccolor.c \
sharedtex.c \
@@ -117,6 +119,12 @@ getprocaddress: getprocaddress.c getproclist.h
getproclist.h: $(TOP)/src/mesa/glapi/gl_API.xml getprocaddress.c getprocaddress.py
python getprocaddress.py > getproclist.h
+arraytexture: arraytexture.o readtex.o
+ $(CC) $(CFLAGS) arraytexture.o readtex.o $(LIBS) -o $@
+
+arraytexture.o: arraytexture.c readtex.h
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
+
afsmultiarb: afsmultiarb.o readtex.o
$(CC) $(CFLAGS) afsmultiarb.o readtex.o $(LIBS) -o $@
diff --git a/progs/tests/arraytexture.c b/progs/tests/arraytexture.c
new file mode 100644
index 00000000000..48c622be302
--- /dev/null
+++ b/progs/tests/arraytexture.c
@@ -0,0 +1,337 @@
+/*
+ * (C) Copyright IBM Corporation 2007
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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 (including the next
+ * paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ * IBM AND/OR ITS SUPPLIERS 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.
+ */
+
+/**
+ * \file arraytexture.c
+ *
+ *
+ * \author Ian Romanick <[email protected]>
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+
+#if !defined(GL_EXT_texture_array) && !defined(GL_MESA_texture_array)
+# error "This demo requires enums for either GL_EXT_texture_array or GL_MESA_texture_array to build."
+#endif
+
+#include "readtex.h"
+
+#define GL_CHECK_ERROR() \
+ do { \
+ GLenum err = glGetError(); \
+ if (err) { \
+ printf("%s:%u: %s (0x%04x)\n", __FILE__, __LINE__, \
+ gluErrorString(err), err); \
+ } \
+ } while (0)
+
+static const char *const textures[] = {
+ "../images/girl.rgb",
+ "../images/girl2.rgb",
+ "../images/arch.rgb",
+ "../images/s128.rgb",
+
+ "../images/tree3.rgb",
+ "../images/bw.rgb",
+ "../images/reflect.rgb",
+ "../images/wrs_logo.rgb",
+ NULL
+};
+
+static const char frag_prog[] =
+ "!!ARBfp1.0\n"
+ "OPTION MESA_texture_array;\n"
+ "TEX result.color, fragment.texcoord[0], texture[0], ARRAY2D;\n"
+ "END\n";
+
+static GLfloat Xrot = 0, Yrot = -30, Zrot = 0;
+static GLfloat texZ = 0.0;
+static GLfloat texZ_dir = 0.01;
+static GLint num_layers;
+
+static PFNGLBINDPROGRAMARBPROC bind_program;
+static PFNGLPROGRAMSTRINGARBPROC program_string;
+static PFNGLGENPROGRAMSARBPROC gen_programs;
+
+
+static void
+PrintString(const char *s)
+{
+ while (*s) {
+ glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
+ s++;
+ }
+}
+
+
+static void Idle(void)
+{
+ static int lastTime = 0;
+ int t = glutGet(GLUT_ELAPSED_TIME);
+
+ if (lastTime == 0)
+ lastTime = t;
+ else if (t - lastTime < 10)
+ return;
+
+ lastTime = t;
+
+ texZ += texZ_dir;
+ if ((texZ < 0.0) || ((GLint) texZ > num_layers)) {
+ texZ_dir = -texZ_dir;
+ }
+
+ glutPostRedisplay();
+}
+
+
+static void Display(void)
+{
+ char str[100];
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1, 1, -1, 1, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ (*bind_program)(GL_FRAGMENT_PROGRAM_ARB, 0);
+ glColor3f(1,1,1);
+ glRasterPos3f(-0.9, -0.9, 0.0);
+ sprintf(str, "Texture Z coordinate = %4.1f", texZ);
+ PrintString(str);
+
+ (*bind_program)(GL_FRAGMENT_PROGRAM_ARB, 1);
+ GL_CHECK_ERROR();
+ glEnable(GL_TEXTURE_2D_ARRAY_EXT);
+ GL_CHECK_ERROR();
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -8.0);
+
+ glPushMatrix();
+ glRotatef(Xrot, 1, 0, 0);
+ glRotatef(Yrot, 0, 1, 0);
+ glRotatef(Zrot, 0, 0, 1);
+
+ glBegin(GL_QUADS);
+ glTexCoord3f(0.0, 0.0, texZ); glVertex2f(-1.0, -1.0);
+ glTexCoord3f(2.0, 0.0, texZ); glVertex2f(1.0, -1.0);
+ glTexCoord3f(2.0, 2.0, texZ); glVertex2f(1.0, 1.0);
+ glTexCoord3f(0.0, 2.0, texZ); glVertex2f(-1.0, 1.0);
+ glEnd();
+
+ glPopMatrix();
+
+ glDisable(GL_TEXTURE_2D_ARRAY_EXT);
+ GL_CHECK_ERROR();
+ (*bind_program)(GL_FRAGMENT_PROGRAM_ARB, 0);
+ GL_CHECK_ERROR();
+
+ glutSwapBuffers();
+}
+
+
+static void Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+}
+
+
+static void Key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 27:
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void SpecialKey(int key, int x, int y)
+{
+ const GLfloat step = 3.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 int FindLine(const char *program, int position)
+{
+ int i, line = 1;
+ for (i = 0; i < position; i++) {
+ if (program[i] == '\n')
+ line++;
+ }
+ return line;
+}
+
+
+static void
+compile_fragment_program(GLuint id, const char *prog)
+{
+ int errorPos;
+ int err;
+
+ err = glGetError();
+ (*bind_program)(GL_FRAGMENT_PROGRAM_ARB, id);
+ (*program_string)(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+ strlen(prog), (const GLubyte *) prog);
+
+ glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
+ err = glGetError();
+ if (err != GL_NO_ERROR || errorPos != -1) {
+ int l = FindLine(prog, errorPos);
+
+ printf("Fragment Program Error (err=%d, pos=%d line=%d): %s\n",
+ err, errorPos, l,
+ (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
+ exit(0);
+ }
+}
+
+
+static void require_extension(const char *ext)
+{
+ if (!glutExtensionSupported(ext)) {
+ printf("Sorry, %s not supported by this renderer.\n", ext);
+ exit(1);
+ }
+}
+
+
+static void Init(void)
+{
+ const char *const ver_string = (const char *const) glGetString(GL_VERSION);
+ unsigned i;
+
+ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION = %s\n", ver_string);
+
+ require_extension("GL_ARB_fragment_program");
+ require_extension("GL_MESA_texture_array");
+ require_extension("GL_SGIS_generate_mipmap");
+
+ bind_program = glutGetProcAddress("glBindProgramARB");
+ program_string = glutGetProcAddress("glProgramStringARB");
+ gen_programs = glutGetProcAddress("glGenProgramsARB");
+
+
+ for (num_layers = 0; textures[num_layers] != NULL; num_layers++)
+ /* empty */ ;
+
+ glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, 1);
+ glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0, GL_RGB8,
+ 256, 256, num_layers, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ GL_CHECK_ERROR();
+
+ glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_GENERATE_MIPMAP_SGIS,
+ GL_TRUE);
+
+ for (i = 0; textures[i] != NULL; i++) {
+ GLint width, height;
+ GLenum format;
+
+ GLubyte *image = LoadRGBImage(textures[i], &width, &height, &format);
+ if (!image) {
+ printf("Error: could not load texture image %s\n", textures[i]);
+ exit(1);
+ }
+
+ /* resize to 256 x 256 */
+ if (width != 256 || height != 256) {
+ GLubyte *newImage = malloc(256 * 256 * 4);
+ gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image,
+ 256, 256, GL_UNSIGNED_BYTE, newImage);
+ free(image);
+ image = newImage;
+ }
+
+ glTexSubImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0,
+ 0, 0, i, 256, 256, 1,
+ format, GL_UNSIGNED_BYTE, image);
+ free(image);
+ }
+ GL_CHECK_ERROR();
+
+ glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+
+ glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ GL_CHECK_ERROR();
+ glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ GL_CHECK_ERROR();
+
+ compile_fragment_program(1, frag_prog);
+ GL_CHECK_ERROR();
+}
+
+
+int main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize(350, 350);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ glutCreateWindow("Array texture test");
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Display);
+ glutIdleFunc(Idle);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/tests/drawbuffers.c b/progs/tests/drawbuffers.c
index 8583bac0ddf..5e89569380a 100644
--- a/progs/tests/drawbuffers.c
+++ b/progs/tests/drawbuffers.c
@@ -19,6 +19,7 @@ static int Win;
static int Width = 400, Height = 400;
static GLuint FBobject, RBobjects[3];
static GLfloat Xrot = 0.0, Yrot = 0.0;
+static GLuint Program;
static void
@@ -40,6 +41,8 @@ Display(void)
GL_COLOR_ATTACHMENT1_EXT
};
+ glUseProgram_func(Program);
+
/* draw to user framebuffer */
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBobject);
@@ -71,10 +74,12 @@ Display(void)
buffer);
/* top half = colorbuffer 1 */
glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
- glReadPixels(0, Height/2, Width, Height / 2, GL_RGBA, GL_UNSIGNED_BYTE,
- buffer + Width * Height / 2 * 4);
+ glReadPixels(0, Height/2, Width, Height - Height / 2,
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ buffer + Width * (Height / 2) * 4);
/* draw to window */
+ glUseProgram_func(0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glWindowPos2iARB(0, 0);
glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
@@ -243,15 +248,15 @@ SetupShaders(void)
" gl_FragData[1] = vec4(1.0) - gl_Color; \n"
"}\n";
- GLuint fragShader, program;
+ GLuint fragShader;
fragShader = LoadAndCompileShader(GL_FRAGMENT_SHADER, fragShaderText);
- program = glCreateProgram_func();
+ Program = glCreateProgram_func();
- glAttachShader_func(program, fragShader);
- glLinkProgram_func(program);
- CheckLink(program);
- glUseProgram_func(program);
+ glAttachShader_func(Program, fragShader);
+ glLinkProgram_func(Program);
+ CheckLink(Program);
+ glUseProgram_func(Program);
}
diff --git a/progs/tests/random.c b/progs/tests/random.c
new file mode 100644
index 00000000000..d52c338e0e1
--- /dev/null
+++ b/progs/tests/random.c
@@ -0,0 +1,457 @@
+/**
+ * Random rendering, to check for crashes, hangs, etc.
+ *
+ * Brian Paul
+ * 21 June 2007
+ */
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <GL/glut.h>
+
+static int Win;
+static GLboolean Anim = GL_TRUE;
+static int Width = 200, Height = 200;
+static int DB = 0;
+static int MinVertexCount = 0, MaxVertexCount = 1000;
+static int Count = 0;
+
+struct vertex
+{
+ int type;
+ float v[4];
+};
+
+static int BufferSize = 10000;
+static struct vertex *Vbuffer = NULL;
+static int Vcount, Vprim;
+
+enum {
+ BEGIN,
+ END,
+ VERTEX2,
+ VERTEX3,
+ VERTEX4,
+ COLOR3,
+ COLOR4,
+ TEX2,
+ TEX3,
+ TEX4,
+ SECCOLOR3,
+ NORMAL3
+};
+
+
+
+/**
+ * This can be called from within gdb after a crash:
+ * (gdb) call ReportState()
+ */
+static void
+ReportState(void)
+{
+ static const struct {
+ GLenum token;
+ char *str;
+ GLenum type;
+ } state [] = {
+ { GL_ALPHA_TEST, "GL_ALPHA_TEST", GL_INT },
+ { GL_BLEND, "GL_BLEND", GL_INT },
+ { GL_CLIP_PLANE0, "GL_CLIP_PLANE0", GL_INT },
+ { GL_DEPTH_TEST, "GL_DEPTH_TEST", GL_INT },
+ { GL_LIGHTING, "GL_LIGHTING", GL_INT },
+ { GL_LINE_WIDTH, "GL_LINE_WIDTH", GL_FLOAT },
+ { GL_POINT_SIZE, "GL_POINT_SIZE", GL_FLOAT },
+ { GL_SHADE_MODEL, "GL_SHADE_MODEL", GL_INT },
+ { GL_SCISSOR_TEST, "GL_SCISSOR_TEST", GL_INT },
+ { 0, NULL, 0 }
+ };
+
+ GLint i;
+
+ for (i = 0; state[i].token; i++) {
+ if (state[i].type == GL_INT) {
+ GLint v;
+ glGetIntegerv(state[i].token, &v);
+ printf("%s = %d\n", state[i].str, v);
+ }
+ else {
+ GLfloat v;
+ glGetFloatv(state[i].token, &v);
+ printf("%s = %f\n", state[i].str, v);
+ }
+ }
+}
+
+static void
+PrintVertex(const char *f, const struct vertex *v, int sz)
+{
+ int i;
+ printf("%s(", f);
+ for (i = 0; i < sz; i++) {
+ printf("%g%s", v->v[i], (i == sz-1) ? "" : ", ");
+ }
+ printf(");\n");
+}
+
+/**
+ * This can be called from within gdb after a crash:
+ * (gdb) call ReportState()
+ */
+static void
+LastPrim(void)
+{
+ int i;
+ for (i = 0; i < Vcount; i++) {
+ switch (Vbuffer[i].type) {
+ case BEGIN:
+ printf("glBegin(%d);\n", (int) Vbuffer[i].v[0]);
+ break;
+ case END:
+ printf("glEnd();\n");
+ break;
+ case VERTEX2:
+ PrintVertex("glVertex2f", Vbuffer + i, 2);
+ break;
+ case VERTEX3:
+ PrintVertex("glVertex3f", Vbuffer + i, 3);
+ break;
+ case VERTEX4:
+ PrintVertex("glVertex4f", Vbuffer + i, 4);
+ break;
+ case COLOR3:
+ PrintVertex("glColor3f", Vbuffer + i, 3);
+ break;
+ case COLOR4:
+ PrintVertex("glColor4f", Vbuffer + i, 4);
+ break;
+ case TEX2:
+ PrintVertex("glTexCoord2f", Vbuffer + i, 2);
+ break;
+ case TEX3:
+ PrintVertex("glTexCoord3f", Vbuffer + i, 3);
+ break;
+ case TEX4:
+ PrintVertex("glTexCoord4f", Vbuffer + i, 4);
+ break;
+ case SECCOLOR3:
+ PrintVertex("glSecondaryColor3f", Vbuffer + i, 3);
+ break;
+ case NORMAL3:
+ PrintVertex("glNormal3f", Vbuffer + i, 3);
+ break;
+ default:
+ abort();
+ }
+ }
+}
+
+
+static int
+RandomInt(int max)
+{
+ if (max == 0)
+ return 0;
+ return rand() % max;
+}
+
+static float
+RandomFloat(float min, float max)
+{
+ int k = rand() % 10000;
+ float x = min + (max - min) * k / 10000.0;
+ return x;
+}
+
+/*
+ * Return true if random number in [0,1] is <= percentile.
+ */
+static GLboolean
+RandomChoice(float percentile)
+{
+ return RandomFloat(0.0, 1.0) <= percentile;
+}
+
+static void
+RandomStateChange(void)
+{
+ int k = RandomInt(19);
+ switch (k) {
+ case 0:
+ glEnable(GL_BLEND);
+ break;
+ case 1:
+ glDisable(GL_BLEND);
+ break;
+ case 2:
+ glEnable(GL_ALPHA_TEST);
+ break;
+ case 3:
+ glEnable(GL_ALPHA_TEST);
+ break;
+ case 4:
+ glEnable(GL_DEPTH_TEST);
+ break;
+ case 5:
+ glEnable(GL_DEPTH_TEST);
+ break;
+ case 6:
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ break;
+ case 7:
+ glPointSize(10.0);
+ break;
+ case 8:
+ glPointSize(1.0);
+ break;
+ case 9:
+ glLineWidth(10.0);
+ break;
+ case 10:
+ glLineWidth(1.0);
+ break;
+ case 11:
+ glEnable(GL_LIGHTING);
+ break;
+ case 12:
+ glDisable(GL_LIGHTING);
+ break;
+ case 13:
+ glEnable(GL_SCISSOR_TEST);
+ break;
+ case 14:
+ glDisable(GL_SCISSOR_TEST);
+ break;
+ case 15:
+ glEnable(GL_CLIP_PLANE0);
+ break;
+ case 16:
+ glDisable(GL_CLIP_PLANE0);
+ break;
+ case 17:
+ glShadeModel(GL_FLAT);
+ break;
+ case 18:
+ glShadeModel(GL_SMOOTH);
+ break;
+ }
+}
+
+
+static void
+RandomPrimitive(void)
+{
+ int i;
+ int len = MinVertexCount + RandomInt(MaxVertexCount - MinVertexCount);
+
+ Vprim = RandomInt(10);
+
+ glBegin(Vprim);
+ Vbuffer[Vcount].type = BEGIN;
+ Vbuffer[Vcount].v[0] = Vprim;
+ Vcount++;
+
+ for (i = 0; i < len; i++) {
+ Vbuffer[Vcount].v[0] = RandomFloat(-3, 3);
+ Vbuffer[Vcount].v[1] = RandomFloat(-3, 3);
+ Vbuffer[Vcount].v[2] = RandomFloat(-3, 3);
+ Vbuffer[Vcount].v[3] = RandomFloat(-3, 3);
+ int k = RandomInt(9);
+ switch (k) {
+ case 0:
+ glVertex2fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = VERTEX2;
+ break;
+ case 1:
+ glVertex3fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = VERTEX3;
+ break;
+ case 2:
+ glVertex4fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = VERTEX4;
+ break;
+ case 3:
+ glColor3fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = COLOR3;
+ break;
+ case 4:
+ glColor4fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = COLOR4;
+ break;
+ case 5:
+ glTexCoord2fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = TEX2;
+ break;
+ case 6:
+ glTexCoord3fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = TEX3;
+ break;
+ case 7:
+ glTexCoord4fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = TEX4;
+ break;
+ case 8:
+ glSecondaryColor3fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = SECCOLOR3;
+ break;
+ case 9:
+ glNormal3fv(Vbuffer[Vcount].v);
+ Vbuffer[Vcount].type = NORMAL3;
+ break;
+ default:
+ abort();
+ }
+ Vcount++;
+
+ if (Vcount >= BufferSize - 2) {
+ /* reset */
+ Vcount = 0;
+ }
+ }
+
+ Vbuffer[Vcount++].type = END;
+
+ glEnd();
+}
+
+
+static void
+RandomDraw(void)
+{
+ int i;
+ GLboolean dlist = RandomChoice(0.1);
+ if (dlist)
+ glNewList(1, GL_COMPILE);
+ for (i = 0; i < 3; i++) {
+ RandomStateChange();
+ }
+ RandomPrimitive();
+
+ if (dlist) {
+ glEndList();
+ glCallList(1);
+ }
+}
+
+
+static void
+Idle(void)
+{
+ glutPostRedisplay();
+}
+
+
+static void
+Draw(void)
+{
+#if 1
+ RandomDraw();
+ Count++;
+#else
+ /* cut & paste temp code here */
+#endif
+
+ assert(glGetError() == 0);
+
+ if (DB)
+ glutSwapBuffers();
+ else
+ glFinish();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ Width = width;
+ Height = height;
+ glViewport(0, 0, width, height);
+ glScissor(20, 20, Width-40, Height-40);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+}
+
+
+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
+Init(void)
+{
+ static const GLdouble plane[4] = {1, 1, 0, 0};
+ glDrawBuffer(GL_FRONT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_LIGHT0);
+ glClipPlane(GL_CLIP_PLANE0, plane);
+
+ Vbuffer = (struct vertex *)
+ malloc(BufferSize * sizeof(struct vertex));
+
+ /* silence warnings */
+ (void) ReportState;
+ (void) LastPrim;
+}
+
+
+static void
+ParseArgs(int argc, char *argv[])
+{
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-s") == 0) {
+ int j = atoi(argv[i + 1]);
+ printf("Random seed value: %d\n", j);
+ srand(j);
+ i++;
+ }
+ else if (strcmp(argv[i], "-a") == 0) {
+ i++;
+ MinVertexCount = atoi(argv[i]);
+ }
+ else if (strcmp(argv[i], "-b") == 0) {
+ i++;
+ MaxVertexCount = atoi(argv[i]);
+ }
+ }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize(Width, Height);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ ParseArgs(argc, argv);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ if (Anim)
+ glutIdleFunc(Idle);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h
index 90302bb5107..5d647cdae7f 100644
--- a/progs/util/extfuncs.h
+++ b/progs/util/extfuncs.h
@@ -11,6 +11,7 @@ static PFNGLCREATEPROGRAMPROC glCreateProgram_func = NULL;
static PFNGLCREATESHADERPROC glCreateShader_func = NULL;
static PFNGLDELETEPROGRAMPROC glDeleteProgram_func = NULL;
static PFNGLDELETESHADERPROC glDeleteShader_func = NULL;
+static PFNGLGETACTIVEATTRIBPROC glGetActiveAttrib_func = NULL;
static PFNGLGETATTACHEDSHADERSPROC glGetAttachedShaders_func = NULL;
static PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation_func = NULL;
static PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog_func = NULL;
@@ -78,6 +79,7 @@ GetExtensionFuncs(void)
glCreateShader_func = (PFNGLCREATESHADERPROC) glutGetProcAddress("glCreateShader");
glDeleteProgram_func = (PFNGLDELETEPROGRAMPROC) glutGetProcAddress("glDeleteProgram");
glDeleteShader_func = (PFNGLDELETESHADERPROC) glutGetProcAddress("glDeleteShader");
+ glGetActiveAttrib_func = (PFNGLGETACTIVEATTRIBPROC) glutGetProcAddress("glGetActiveAttrib");
glGetAttachedShaders_func = (PFNGLGETATTACHEDSHADERSPROC) glutGetProcAddress("glGetAttachedShaders");
glGetAttribLocation_func = (PFNGLGETATTRIBLOCATIONPROC) glutGetProcAddress("glGetAttribLocation");
glGetProgramInfoLog_func = (PFNGLGETPROGRAMINFOLOGPROC) glutGetProcAddress("glGetProgramInfoLog");
diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile
index ec85464bec0..d1d7fecea1c 100644
--- a/progs/xdemos/Makefile
+++ b/progs/xdemos/Makefile
@@ -23,6 +23,7 @@ PROGS = glthreads \
overlay \
pbinfo \
pbdemo \
+ texture_from_pixmap \
wincopy \
xfont \
xrotfontdemo \
diff --git a/progs/xdemos/texture_from_pixmap.c b/progs/xdemos/texture_from_pixmap.c
new file mode 100644
index 00000000000..ab215b0ac30
--- /dev/null
+++ b/progs/xdemos/texture_from_pixmap.c
@@ -0,0 +1,396 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-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.
+ */
+
+
+/*
+ * Test the GLX_EXT_texture_from_pixmap extension
+ * Brian Paul
+ * 19 May 2007
+ */
+
+
+#define GL_GLEXT_PROTOTYPES
+#define GLX_GLXEXT_PROTOTYPES
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <X11/keysym.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static float top, bottom;
+
+static PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT_func = NULL;
+static PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT_func = NULL;
+
+
+static Display *
+OpenDisplay(void)
+{
+ int screen;
+ Display *dpy;
+ const char *ext;
+
+ dpy = XOpenDisplay(NULL);
+ if (!dpy) {
+ printf("Couldn't open default display!\n");
+ exit(1);
+ }
+
+ screen = DefaultScreen(dpy);
+ ext = glXQueryExtensionsString(dpy, screen);
+ if (!strstr(ext, "GLX_EXT_texture_from_pixmap")) {
+ fprintf(stderr, "GLX_EXT_texture_from_pixmap not supported.\n");
+ exit(1);
+ }
+
+ glXBindTexImageEXT_func = (PFNGLXBINDTEXIMAGEEXTPROC)
+ glXGetProcAddress((GLubyte *) "glXBindTexImageEXT");
+ glXReleaseTexImageEXT_func = (PFNGLXRELEASETEXIMAGEEXTPROC)
+ glXGetProcAddress((GLubyte*) "glXReleaseTexImageEXT");
+
+ if (!glXBindTexImageEXT_func || !glXReleaseTexImageEXT_func) {
+ fprintf(stderr, "glXGetProcAddress failed!\n");
+ exit(1);
+ }
+
+ return dpy;
+}
+
+
+static GLXFBConfig
+ChoosePixmapFBConfig(Display *display)
+{
+ int screen = DefaultScreen(display);
+ GLXFBConfig *fbconfigs;
+ int i, nfbconfigs, value;
+
+ fbconfigs = glXGetFBConfigs(display, screen, &nfbconfigs);
+ for (i = 0; i < nfbconfigs; i++) {
+
+ glXGetFBConfigAttrib(display, fbconfigs[i], GLX_DRAWABLE_TYPE, &value);
+ if (!(value & GLX_PIXMAP_BIT))
+ continue;
+
+ glXGetFBConfigAttrib(display, fbconfigs[i],
+ GLX_BIND_TO_TEXTURE_TARGETS_EXT, &value);
+ if (!(value & GLX_TEXTURE_2D_BIT_EXT))
+ continue;
+
+ glXGetFBConfigAttrib(display, fbconfigs[i],
+ GLX_BIND_TO_TEXTURE_RGBA_EXT, &value);
+ if (value == False) {
+ glXGetFBConfigAttrib(display, fbconfigs[i],
+ GLX_BIND_TO_TEXTURE_RGB_EXT, &value);
+ if (value == False)
+ continue;
+ }
+
+ glXGetFBConfigAttrib(display, fbconfigs[i],
+ GLX_Y_INVERTED_EXT, &value);
+ if (value == True) {
+ top = 0.0f;
+ bottom = 1.0f;
+ }
+ else {
+ top = 1.0f;
+ bottom = 0.0f;
+ }
+
+ break;
+ }
+
+ if (i == nfbconfigs) {
+ printf("Unable to find FBconfig for texturing\n");
+ exit(1);
+ }
+
+ return fbconfigs[i];
+}
+
+
+static GLXPixmap
+CreatePixmap(Display *dpy, GLXFBConfig config, int w, int h, Pixmap *p)
+{
+ GLXPixmap gp;
+ const int pixmapAttribs[] = {
+ GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
+ GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
+ None
+ };
+ Window root = RootWindow(dpy, 0);
+
+ *p = XCreatePixmap(dpy, root, w, h, 24);
+ XSync(dpy, 0);
+ gp = glXCreatePixmap(dpy, config, *p, pixmapAttribs);
+ XSync(dpy, 0);
+
+ return gp;
+}
+
+
+static void
+DrawPixmapImage(Display *dpy, Pixmap pm, int w, int h)
+{
+ XGCValues gcvals;
+ GC gc;
+
+ gcvals.background = 0;
+ gc = XCreateGC(dpy, pm, GCBackground, &gcvals);
+
+ XSetForeground(dpy, gc, 0x0);
+ XFillRectangle(dpy, pm, gc, 0, 0, w, h);
+
+ XSetForeground(dpy, gc, 0xff0000);
+ XFillRectangle(dpy, pm, gc, 0, 0, 50, 50);
+
+ XSetForeground(dpy, gc, 0x00ff00);
+ XFillRectangle(dpy, pm, gc, w - 50, 0, 50, 50);
+
+ XSetForeground(dpy, gc, 0x0000ff);
+ XFillRectangle(dpy, pm, gc, 0, h - 50, 50, 50);
+
+ XSetForeground(dpy, gc, 0xffffff);
+ XFillRectangle(dpy, pm, gc, h - 50, h - 50, 50, 50);
+
+ XSetForeground(dpy, gc, 0xffff00);
+ XSetLineAttributes(dpy, gc, 3, LineSolid, CapButt, JoinBevel);
+ XDrawLine(dpy, pm, gc, 0, 0, w, h);
+ XDrawLine(dpy, pm, gc, 0, h, w, 0);
+
+ XFreeGC(dpy, gc);
+}
+
+
+static XVisualInfo *
+ChooseWindowVisual(Display *dpy)
+{
+ int screen = DefaultScreen(dpy);
+ XVisualInfo *visinfo;
+ int attribs[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None
+ };
+
+ visinfo = glXChooseVisual(dpy, screen, attribs);
+ if (!visinfo) {
+ printf("Unable to find RGB, double-buffered visual\n");
+ exit(1);
+ }
+
+ return visinfo;
+}
+
+
+static Window
+CreateWindow(Display *dpy, XVisualInfo *visinfo,
+ int width, int height, const char *name)
+{
+ int screen = DefaultScreen(dpy);
+ Window win;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+
+ root = RootWindow(dpy, screen);
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow(dpy, root, 0, 0, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr);
+ if (win) {
+ XSizeHints sizehints;
+ sizehints.width = width;
+ sizehints.height = height;
+ sizehints.flags = USSize;
+ XSetNormalHints(dpy, win, &sizehints);
+ XSetStandardProperties(dpy, win, name, name,
+ None, (char **)NULL, 0, &sizehints);
+
+ XMapWindow(dpy, win);
+ }
+ return win;
+}
+
+
+static void
+BindPixmapTexture(Display *dpy, GLXPixmap gp)
+{
+ GLuint texture;
+
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ glXBindTexImageEXT_func(dpy, gp, GLX_FRONT_LEFT_EXT, NULL);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glEnable(GL_TEXTURE_2D);
+ /*
+ glXReleaseTexImageEXT_func(display, glxpixmap, GLX_FRONT_LEFT_EXT);
+ */
+}
+
+
+static void
+Resize(Window win, unsigned int width, unsigned int height)
+{
+ float sz = 1.5;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-sz, sz, -sz, sz, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+static void
+Redraw(Display *dpy, Window win, float rot)
+{
+ glClearColor(0.25, 0.25, 0.25, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glPushMatrix();
+ glRotatef(rot, 0, 0, 1);
+ glRotatef(2.0 * rot, 1, 0, 0);
+
+ glBegin(GL_QUADS);
+ glTexCoord2d(0.0, bottom);
+ glVertex2f(-1, -1);
+ glTexCoord2d(1.0, bottom);
+ glVertex2f( 1, -1);
+ glTexCoord2d(1.0, top);
+ glVertex2d(1.0, 1.0);
+ glTexCoord2d(0.0, top);
+ glVertex2f(-1.0, 1.0);
+ glEnd();
+
+ glPopMatrix();
+
+ glXSwapBuffers(dpy, win);
+}
+
+
+static void
+EventLoop(Display *dpy, Window win)
+{
+ GLfloat rot = 0.0;
+ int anim = 0;
+
+ while (1) {
+ if (!anim || XPending(dpy) > 0) {
+ XEvent event;
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case Expose:
+ Redraw(dpy, win, rot);
+ break;
+ case ConfigureNotify:
+ Resize(event.xany.window,
+ event.xconfigure.width,
+ event.xconfigure.height);
+ break;
+ case KeyPress:
+ {
+ char buf[100];
+ KeySym keySym;
+ XComposeStatus stat;
+ XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat);
+ if (keySym == XK_Escape) {
+ return; /* exit */
+ }
+ else if (keySym == XK_r) {
+ rot += 1.0;
+ Redraw(dpy, win, rot);
+ }
+ else if (keySym == XK_a) {
+ anim = !anim;
+ }
+ else if (keySym == XK_R) {
+ rot -= 1.0;
+ Redraw(dpy, win, rot);
+ }
+ }
+ break;
+ default:
+ ; /*no-op*/
+ }
+ }
+ else {
+ /* animate */
+ rot += 1.0;
+ Redraw(dpy, win, rot);
+ }
+ }
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+ Display *dpy;
+ GLXFBConfig pixmapConfig;
+ XVisualInfo *windowVis;
+ GLXPixmap gp;
+ Window win;
+ GLXContext ctx;
+ Pixmap p;
+
+ dpy = OpenDisplay();
+
+ pixmapConfig = ChoosePixmapFBConfig(dpy);
+ windowVis = ChooseWindowVisual(dpy);
+ win = CreateWindow(dpy, windowVis, 500, 500, "Texture From Pixmap");
+
+ gp = CreatePixmap(dpy, pixmapConfig, 512, 512, &p);
+ DrawPixmapImage(dpy, p, 512, 512);
+
+ ctx = glXCreateContext(dpy, windowVis, NULL, True);
+ if (!ctx) {
+ printf("Couldn't create GLX context\n");
+ exit(1);
+ }
+
+ glXMakeCurrent(dpy, win, ctx);
+
+ BindPixmapTexture(dpy, gp);
+
+ EventLoop(dpy, win);
+
+ return 0;
+}