diff options
Diffstat (limited to 'progs/trivial')
-rw-r--r-- | progs/trivial/Makefile | 17 | ||||
-rw-r--r-- | progs/trivial/dlist-degenerate.c | 153 | ||||
-rw-r--r-- | progs/trivial/point-param.c | 57 | ||||
-rw-r--r-- | progs/trivial/quad-clip-nearplane.c | 43 | ||||
-rw-r--r-- | progs/trivial/tri-mask-tri.c | 123 | ||||
-rw-r--r-- | progs/trivial/tri.c | 5 |
6 files changed, 291 insertions, 107 deletions
diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index d282171826..a4077bd016 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 \ @@ -19,6 +19,7 @@ SOURCES = \ dlist-dangling.c \ dlist-edgeflag-dangling.c \ dlist-edgeflag.c \ + dlist-degenerate.c \ drawarrays.c \ drawelements.c \ drawrange.c \ @@ -74,7 +75,6 @@ SOURCES = \ quadstrip-cont.c \ quadstrip-flat.c \ quadstrip.c \ - tri-orig.c \ tri-alpha.c \ tri-blend-color.c \ tri-blend-max.c \ @@ -93,6 +93,7 @@ SOURCES = \ tri-flat.c \ tri-fog.c \ tri-mask-tri.c \ + tri-orig.c \ tri-query.c \ tri-scissor-tri.c \ tri-stencil.c \ @@ -142,7 +143,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 $@ @@ -156,9 +157,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 @@ -169,13 +170,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.c b/progs/trivial/tri.c index 12fa8d11b6..aa45adb6c2 100644 --- a/progs/trivial/tri.c +++ b/progs/trivial/tri.c @@ -33,6 +33,7 @@ GLenum doubleBuffer = 1; +int win; static void Init(void) { @@ -59,6 +60,7 @@ static void Key(unsigned char key, int x, int y) switch (key) { case 27: + glutDestroyWindow(win); exit(0); default: return; @@ -120,7 +122,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); } |