summaryrefslogtreecommitdiff
path: root/progs/trivial
diff options
context:
space:
mode:
Diffstat (limited to 'progs/trivial')
-rw-r--r--progs/trivial/.gitignore1
-rw-r--r--progs/trivial/Makefile17
-rw-r--r--progs/trivial/dlist-degenerate.c153
-rw-r--r--progs/trivial/point-param.c57
-rw-r--r--progs/trivial/quad-clip-nearplane.c43
-rw-r--r--progs/trivial/tri-mask-tri.c123
-rw-r--r--progs/trivial/tri-stencil.c13
-rw-r--r--progs/trivial/tri.c4
8 files changed, 302 insertions, 109 deletions
diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore
index 25754a610a..8bf6e45650 100644
--- a/progs/trivial/.gitignore
+++ b/progs/trivial/.gitignore
@@ -5,6 +5,7 @@ clear-repeat
clear-scissor
clear-undefined
dlist-dangling
+dlist-degenerate
dlist-edgeflag
dlist-edgeflag-dangling
drawarrays
diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile
index cfe7fe6f31..f7bfd1f039 100644
--- a/progs/trivial/Makefile
+++ b/progs/trivial/Makefile
@@ -8,7 +8,7 @@ TOP = ../..
include $(TOP)/configs/current
-LIBS = $(APP_LIB_DEPS)
+LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS)
SOURCES = \
clear-fbo-tex.c \
@@ -20,6 +20,7 @@ SOURCES = \
dlist-dangling.c \
dlist-edgeflag-dangling.c \
dlist-edgeflag.c \
+ dlist-degenerate.c \
drawarrays.c \
drawelements.c \
drawrange.c \
@@ -75,7 +76,6 @@ SOURCES = \
quadstrip-cont.c \
quadstrip-flat.c \
quadstrip.c \
- tri-orig.c \
tri-alpha.c \
tri-array-interleaved.c \
tri-blend-color.c \
@@ -98,6 +98,7 @@ SOURCES = \
tri-fp-const-imm.c \
tri-lit.c \
tri-mask-tri.c \
+ tri-orig.c \
tri-query.c \
tri-repeat.c \
tri-scissor-tri.c \
@@ -155,7 +156,7 @@ UTIL_FILES = readtex.h readtex.c
.SUFFIXES: .c
.c:
- $(APP_CC) $(INCLUDES) $(CFLAGS) $< $(LIBS) -o $@
+ $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
.c.o:
$(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
@@ -169,9 +170,9 @@ UTIL_FILES = readtex.h readtex.c
default: $(UTIL_FILES) $(PROGS)
clean:
- rm -f $(PROGS)
- rm -f *.o
- rm -f getproclist.h
+ -rm -f $(PROGS)
+ -rm -f *.o
+ -rm -f getproclist.h
# auto code generation
@@ -182,13 +183,13 @@ getproclist.h: $(TOP)/src/mesa/glapi/gl_API.xml getprocaddress.c getprocaddress.
texrect: texrect.o readtex.o
- $(APP_CC) texrect.o readtex.o $(LIBS) -o $@
+ $(APP_CC) $(CFLAGS) $(LDFLAGS) texrect.o readtex.o $(LIBS) -o $@
texrect.o: texrect.c readtex.h
$(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
invert: invert.o readtex.o
- $(APP_CC) invert.o readtex.o $(LIBS) -o $@
+ $(APP_CC) $(CFLAGS) $(LDFLAGS) invert.o readtex.o $(LIBS) -o $@
invert.o: invert.c readtex.h
$(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@
diff --git a/progs/trivial/dlist-degenerate.c b/progs/trivial/dlist-degenerate.c
new file mode 100644
index 0000000000..c7f2d2a6e9
--- /dev/null
+++ b/progs/trivial/dlist-degenerate.c
@@ -0,0 +1,153 @@
+/**
+ * Test display list corner cases.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/glut.h>
+
+
+static int Win;
+static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
+static GLboolean Anim = GL_FALSE;
+static GLuint List1 = 0, List2 = 0;
+
+
+static void
+Idle(void)
+{
+ Xrot += 3.0;
+ Yrot += 4.0;
+ Zrot += 2.0;
+ glutPostRedisplay();
+}
+
+
+static void
+Draw(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(Xrot, 1, 0, 0);
+ glRotatef(Yrot, 0, 1, 0);
+ glRotatef(Zrot, 0, 0, 1);
+
+ glCallList(List1);
+ glCallList(List2);
+
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -15.0);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+ const GLfloat step = 3.0;
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 'a':
+ Anim = !Anim;
+ if (Anim)
+ glutIdleFunc(Idle);
+ else
+ glutIdleFunc(NULL);
+ break;
+ case 'z':
+ Zrot -= step;
+ break;
+ case 'Z':
+ Zrot += step;
+ break;
+ case 27:
+ glutDestroyWindow(Win);
+ 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 void
+Init(void)
+{
+ /* List1: start of primitive */
+ List1 = glGenLists(1);
+ glNewList(List1, GL_COMPILE);
+ glBegin(GL_POLYGON);
+ glVertex2f(-1, -1);
+ glVertex2f( 1, -1);
+ glEndList();
+
+ /* List2: end of primitive */
+ List2 = glGenLists(1);
+ glNewList(List2, GL_COMPILE);
+ glVertex2f( 1, 1);
+ glVertex2f(-1, 1);
+ glEnd();
+ glEndList();
+
+ glEnable(GL_DEPTH_TEST);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize(400, 400);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+ Win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutSpecialFunc(SpecialKey);
+ glutDisplayFunc(Draw);
+ if (Anim)
+ glutIdleFunc(Idle);
+ Init();
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/trivial/point-param.c b/progs/trivial/point-param.c
index be4328d999..96544a0525 100644
--- a/progs/trivial/point-param.c
+++ b/progs/trivial/point-param.c
@@ -22,15 +22,14 @@
* OF THIS SOFTWARE.
*/
+#define GL_GLEXT_PROTOTYPES
+#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
-#define CI_OFFSET_1 16
-#define CI_OFFSET_2 32
-
GLenum doubleBuffer;
@@ -40,53 +39,63 @@ static void Init(void)
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- glClearColor(0.0, 0.0, 1.0, 0.0);
+ glClearColor(0.0, 0.0, 1.0, 0.0);
}
static void Reshape(int width, int height)
{
-
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
+ glOrtho(-1.0, 1.0, -1.0, 1.0, 0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
static void Key(unsigned char key, int x, int y)
{
-
switch (key) {
- case 27:
+ case 27:
exit(1);
- default:
+ default:
return;
}
-
glutPostRedisplay();
}
+
+static float
+expected(float z, float size, const float atten[3])
+{
+ float dist = fabs(z);
+ const GLfloat q = atten[0] + dist * (atten[1] + dist * atten[2]);
+ const GLfloat a = sqrt(1.0 / q);
+ return size * a;
+}
+
+
static void Draw(void)
{
- static GLfloat theQuad[3] = { 0.25, 0.0, 1/60.0 };
+ static GLfloat atten[3] = { 0.0, 0.1, .01 };
+ float size = 40.0;
+ int i;
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPointSize(8.0);
- glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
+ glPointSize(size);
+ glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, atten);
+ glColor3f(1,0,0);
+ printf("Expected point sizes:\n");
glBegin(GL_POINTS);
- glColor3f(1,0,0);
- glVertex3f( 0.9, -0.9, -10.0);
- glColor3f(1,1,0);
- glVertex3f( 0.9, 0.9, -5.0);
- glColor3f(1,0,1);
- glVertex3f(-0.9, 0.9, -30.0);
- glColor3f(0,1,1);
- glVertex3f(-0.9, -0.9, -20.0);
+ for (i = 0; i < 5; i++) {
+ float x = -0.8 + i * 0.4;
+ float z = -i * 20 - 10;
+ glVertex3f( x, 0.0, z);
+ printf(" %f\n", expected(z, size, atten));
+ }
glEnd();
glFlush();
@@ -96,6 +105,7 @@ static void Draw(void)
}
}
+
static GLenum Args(int argc, char **argv)
{
GLint i;
@@ -115,6 +125,7 @@ static GLenum Args(int argc, char **argv)
return GL_TRUE;
}
+
int main(int argc, char **argv)
{
GLenum type;
@@ -131,7 +142,7 @@ int main(int argc, char **argv)
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
glutInitDisplayMode(type);
- if (glutCreateWindow("First Tri") == GL_FALSE) {
+ if (glutCreateWindow(argv[0]) == GL_FALSE) {
exit(1);
}
@@ -141,5 +152,5 @@ int main(int argc, char **argv)
glutKeyboardFunc(Key);
glutDisplayFunc(Draw);
glutMainLoop();
- return 0;
+ return 0;
}
diff --git a/progs/trivial/quad-clip-nearplane.c b/progs/trivial/quad-clip-nearplane.c
index e76eb29f89..1e8056c474 100644
--- a/progs/trivial/quad-clip-nearplane.c
+++ b/progs/trivial/quad-clip-nearplane.c
@@ -33,6 +33,7 @@
GLenum doubleBuffer;
+float Z = -6;
static void Init(void)
{
@@ -40,30 +41,36 @@ static void Init(void)
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- glClearColor(0.0, 0.0, 1.0, 0.0);
+ fprintf(stderr, "Press z/Z to translate quad\n");
+
+ glClearColor(0.0, 0.0, 1.0, 0.0);
}
static void Reshape(int width, int height)
{
-
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
+ glFrustum(-1.0, 1.0, -1.0, 1.0, 5, 100.0);
glMatrixMode(GL_MODELVIEW);
}
static void Key(unsigned char key, int x, int y)
{
-
switch (key) {
- case 27:
- exit(1);
- default:
- return;
+ case 'z':
+ Z += 0.5;
+ break;
+ case 'Z':
+ Z -= 0.5;
+ break;
+ case 27:
+ exit(1);
+ default:
+ return;
}
-
+ printf("Z = %f\n", Z);
glutPostRedisplay();
}
@@ -71,17 +78,22 @@ static void Draw(void)
{
glClear(GL_COLOR_BUFFER_BIT);
+ glPushMatrix();
+ glTranslatef(0, -0.5, Z);
+
glBegin(GL_QUADS);
glColor3f(1,0,0);
- glVertex3f( 0.9, -0.9, 30.0);
+ glVertex3f( -0.8, 0, -4.0);
glColor3f(1,1,0);
- glVertex3f( 0.9, 0.9, 30.0);
+ glVertex3f( 0.8, 0, -4.0);
glColor3f(1,0,1);
- glVertex3f(-1.9, 0.9, 30.0);
+ glVertex3f( 0.8, 0, 4.0);
glColor3f(0,1,1);
- glVertex3f(-1.9, -0.9, -30.0);
+ glVertex3f( -0.8, 0, 4.0);
glEnd();
+ glPopMatrix();
+
glFlush();
if (doubleBuffer) {
@@ -118,7 +130,8 @@ int main(int argc, char **argv)
exit(1);
}
- glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize( 250, 250);
type = GLUT_RGB | GLUT_ALPHA;
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
@@ -134,5 +147,5 @@ int main(int argc, char **argv)
glutKeyboardFunc(Key);
glutDisplayFunc(Draw);
glutMainLoop();
- return 0;
+ return 0;
}
diff --git a/progs/trivial/tri-mask-tri.c b/progs/trivial/tri-mask-tri.c
index 38ecd20a73..8333f7ed8a 100644
--- a/progs/trivial/tri-mask-tri.c
+++ b/progs/trivial/tri-mask-tri.c
@@ -28,48 +28,53 @@
#include <GL/glut.h>
-#define CI_OFFSET_1 16
-#define CI_OFFSET_2 32
-
GLint Width = 250, Height = 250;
-
GLenum doubleBuffer;
+GLint Win;
+GLboolean Rmask = GL_TRUE, Gmask = GL_FALSE, Bmask = GL_TRUE;
+
static void Init(void)
{
fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
-
- glClearColor(0.0, 0.0, 1.0, 0.0);
+ glClearColor(0.0, 0.0, 1.0, 0.0);
}
static void Reshape(int width, int height)
{
-
- glViewport(0, 0, (GLint)width, (GLint)height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
- glMatrixMode(GL_MODELVIEW);
+ glViewport(0, 0, (GLint)width, (GLint)height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
+ glMatrixMode(GL_MODELVIEW);
}
static void Key(unsigned char key, int x, int y)
{
-
- switch (key) {
- case 27:
- exit(1);
- default:
- return;
- }
-
- glutPostRedisplay();
+ switch (key) {
+ case 'r':
+ Rmask = !Rmask;
+ break;
+ case 'g':
+ Gmask = !Gmask;
+ break;
+ case 'b':
+ Bmask = !Bmask;
+ break;
+ case 27:
+ glutDestroyWindow(Win);
+ exit(1);
+ default:
+ return;
+ }
+ glutPostRedisplay();
}
static void Draw(void)
{
+ printf("ColorMask = %d, %d, %d\n", Rmask, Gmask, Bmask);
glColorMask(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
@@ -82,7 +87,7 @@ static void Draw(void)
glVertex3f(-0.9, 0.0, -30.0);
glEnd();
- glColorMask(1,0,1,0);
+ glColorMask(Rmask, Gmask, Bmask, 0);
/* left triangle: white&mask: purple middle region: white */
glBegin(GL_TRIANGLES);
@@ -103,48 +108,46 @@ static void Draw(void)
static GLenum Args(int argc, char **argv)
{
- GLint i;
-
- doubleBuffer = GL_FALSE;
-
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-sb") == 0) {
- doubleBuffer = GL_FALSE;
- } else if (strcmp(argv[i], "-db") == 0) {
- doubleBuffer = GL_TRUE;
- } else {
- fprintf(stderr, "%s (Bad option).\n", argv[i]);
- return GL_FALSE;
- }
- }
- return GL_TRUE;
+ GLint i;
+
+ doubleBuffer = GL_FALSE;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-sb") == 0) {
+ doubleBuffer = GL_FALSE;
+ }
+ else if (strcmp(argv[i], "-db") == 0) {
+ doubleBuffer = GL_TRUE;
+ }
+ else {
+ fprintf(stderr, "%s (Bad option).\n", argv[i]);
+ return GL_FALSE;
+ }
+ }
+ return GL_TRUE;
}
+
int main(int argc, char **argv)
{
- GLenum type;
-
- glutInit(&argc, argv);
+ GLenum type;
- if (Args(argc, argv) == GL_FALSE) {
- exit(1);
- }
+ glutInit(&argc, argv);
- glutInitWindowPosition(100, 0); glutInitWindowSize(Width, Height);
-
- type = GLUT_RGB;
- type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
- glutInitDisplayMode(type);
-
- if (glutCreateWindow("First Tri") == GL_FALSE) {
- exit(1);
- }
-
- Init();
+ if (Args(argc, argv) == GL_FALSE) {
+ exit(1);
+ }
- glutReshapeFunc(Reshape);
- glutKeyboardFunc(Key);
- glutDisplayFunc(Draw);
- glutMainLoop();
- return 0;
+ type = GLUT_RGB;
+ type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
+
+ glutInitWindowPosition(100, 0); glutInitWindowSize(Width, Height);
+ glutInitDisplayMode(type);
+ Win = glutCreateWindow("First Tri");
+ Init();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutMainLoop();
+ return 0;
}
diff --git a/progs/trivial/tri-stencil.c b/progs/trivial/tri-stencil.c
index 5edbef26ce..7686e16aef 100644
--- a/progs/trivial/tri-stencil.c
+++ b/progs/trivial/tri-stencil.c
@@ -49,7 +49,15 @@ static void Key(unsigned char key, int x, int y)
switch (key) {
case 27:
+ printf("Exiting...\n");
exit(1);
+ case 'r':
+ printf("Redisplaying...\n");
+ glutPostRedisplay();
+ break;
+ default:
+ printf("No such key '%c'...\n", key);
+ break;
}
}
@@ -89,7 +97,7 @@ static void Draw(void)
glEnd();
#endif
-#if 0
+#if 1
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
@@ -130,7 +138,8 @@ int main(int argc, char **argv)
exit(1);
}
- glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
+ glutInitWindowPosition(0, 0);
+ glutInitWindowSize( 300, 300);
type = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL;
glutInitDisplayMode(type);
diff --git a/progs/trivial/tri.c b/progs/trivial/tri.c
index 64c529415c..d3c6b59ea5 100644
--- a/progs/trivial/tri.c
+++ b/progs/trivial/tri.c
@@ -33,6 +33,7 @@
GLenum doubleBuffer = 1;
+int win;
static void Init(void)
{
@@ -118,7 +119,8 @@ int main(int argc, char **argv)
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
glutInitDisplayMode(type);
- if (glutCreateWindow("First Tri") == GL_FALSE) {
+ win = glutCreateWindow("First Tri");
+ if (!win) {
exit(1);
}