summaryrefslogtreecommitdiffstats
path: root/progs/tests
diff options
context:
space:
mode:
Diffstat (limited to 'progs/tests')
-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
4 files changed, 815 insertions, 8 deletions
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;
+}