Add a couple of test apps for line/unfilled polygon clipping.
authorEric Anholt <eric@anholt.net>
Thu, 27 Mar 2008 18:57:08 +0000 (11:57 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 27 Mar 2008 18:57:08 +0000 (11:57 -0700)
progs/tests/.gitignore
progs/tests/Makefile
progs/tests/lineclip.c [new file with mode: 0644]
progs/tests/unfilledclip.c [new file with mode: 0644]

index d789b3098e2a11b24054b79a7c6b2fe67f3d2a20..6505c315a67a836a1e418b5a5ce3e5b2a772a7af 100644 (file)
@@ -38,6 +38,7 @@ getproclist.h
 interleave
 invert
 jkrahntest
+lineclip
 manytex
 mipmap_limits
 multipal
@@ -66,6 +67,7 @@ texline
 texobjshare
 texrect
 texwrap
+unfilledclip
 vao-01
 vao-02
 vparray
index 7bf64e19e40d5d0dd509149b392a887ea0f6d8b4..116a19b1f5b4db7a71315a7318477c648e2009b4 100644 (file)
@@ -48,6 +48,7 @@ SOURCES = \
        interleave.c \
        invert.c \
        jkrahntest.c \
+       lineclip.c \
        manytex.c \
        minmag.c \
        mipmap_limits.c \
@@ -73,6 +74,7 @@ SOURCES = \
        texobjshare.c \
        texrect.c \
        texwrap.c \
+       unfilledclip.c \
        vao-01.c \
        vao-02.c \
        vparray.c \
diff --git a/progs/tests/lineclip.c b/progs/tests/lineclip.c
new file mode 100644 (file)
index 0000000..098f5e9
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * Copyright © 2008 Intel Corporation
+ *
+ * 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 (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 NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *
+ */
+
+#include <stdlib.h>
+#include <GL/glut.h>
+
+static int win_width, win_height;
+
+static void
+line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+       glBegin(GL_LINES);
+       glVertex2f(x1, y1);
+       glVertex2f(x2, y2);
+       glEnd();
+}
+
+static void
+line3(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2)
+{
+       glBegin(GL_LINES);
+       glVertex3f(x1, y1, z1);
+       glVertex3f(x2, y2, z2);
+       glEnd();
+}
+
+static void
+display(void)
+{
+       glClearColor(0.0, 0.0, 0.0, 0.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       glColor3f(1.0, 0.0, 0.0);
+       /* 2 lines clipped along xmin */
+       line(-20, win_height / 2 - 20,
+             20, win_height / 2 - 20);
+       line( 20, win_height / 2 + 20,
+            -20, win_height / 2 + 20);
+
+       glColor3f(0.0, 1.0, 0.0);
+       /* 2 lines clipped along ymax */
+       line(win_width / 2 - 20, win_height + 20,
+            win_width / 2 - 20, win_height - 20);
+       line(win_width / 2 + 20, win_height - 20,
+            win_width / 2 + 20, win_height + 20);
+
+       glColor3f(0.0, 0.0, 1.0);
+       /* 2 lines clipped along xmax */
+       line(win_width - 20, win_height / 2 - 20,
+            win_width + 20, win_height / 2 - 20);
+       line(win_width + 20, win_height / 2 + 20,
+            win_width - 20, win_height / 2 + 20);
+
+       glColor3f(1.0, 1.0, 1.0);
+       /* 2 lines clipped along ymin */
+       line(win_width / 2 - 20,  20,
+            win_width / 2 - 20, -20);
+       line(win_width / 2 + 20, -20,
+            win_width / 2 + 20,  20);
+
+       /* 2 lines clipped along near */
+       glColor3f(1.0, 0.0, 1.0);
+       line3(win_width / 2 - 20 - 20, win_height / 2,       0.5,
+             win_width / 2 - 20 + 20, win_height / 2,      -0.5);
+       line3(win_width / 2 - 20,      win_height / 2 - 20, -0.5,
+             win_width / 2 - 20,      win_height / 2 + 20,  0.5);
+
+       /* 2 lines clipped along far */
+       glColor3f(0.0, 1.0, 1.0);
+       line3(win_width / 2 + 20 - 20, win_height / 2,      1.5,
+             win_width / 2 + 20 + 20, win_height / 2,      0.5);
+       line3(win_width / 2 + 20,      win_height / 2 - 20, 0.5,
+             win_width / 2 + 20,      win_height / 2 + 20, 1.5);
+
+       /* entirely clipped along near/far */
+       glColor3f(.5, .5, .5);
+       line3(win_width / 2, win_height / 2 - 20, -0.5,
+             win_width / 2, win_height / 2 + 20, -0.5);
+       glColor3f(.5, .5, .5);
+       line3(win_width / 2, win_height / 2 - 20, 1.5,
+             win_width / 2, win_height / 2 + 20, 1.5);
+
+       glColor3f(1.0, 1.0, 0.0);
+       /* lines clipped along both x and y limits */
+       line(-5, 20,
+            20, -5); /* xmin, ymin */
+       line(-5, win_height - 20,
+            20, win_height + 5); /* xmin, ymax */
+       line(win_width - 20, -5,
+            win_width + 5,  20); /* xmax, ymin */
+       line(win_width - 20, win_height + 5,
+            win_width + 5,  win_height - 20); /* xmax, ymax */
+
+       glutSwapBuffers();
+}
+
+static void
+reshape(int width, int height)
+{
+       win_width = width;
+       win_height = height;
+       glViewport(0, 0, width, height);
+
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+       glOrtho(0, win_width, 0, win_height, 0.0, -1.0);
+
+       glMatrixMode(GL_MODELVIEW);
+       glLoadIdentity();
+       glTranslatef(.25, .25, 0);
+}
+
+static void key( unsigned char key, int x, int y )
+{
+       (void) x;
+       (void) y;
+
+       switch (key) {
+       case 27: /* esc */
+               exit(0);
+               break;
+       }
+
+       glutPostRedisplay();
+}
+
+static void
+init(void)
+{
+}
+
+int
+main(int argc, char *argv[])
+{
+       win_width = 200;
+       win_height = 200;
+
+       glutInit(&argc, argv);
+       glutInitWindowPosition(0, 0);
+       glutInitWindowSize(win_width, win_height);
+       glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+       glutCreateWindow(argv[0]);
+       glutReshapeFunc(reshape);
+       glutKeyboardFunc(key);
+       glutDisplayFunc(display);
+
+       init();
+
+       glutMainLoop();
+       return 0;
+}
diff --git a/progs/tests/unfilledclip.c b/progs/tests/unfilledclip.c
new file mode 100644 (file)
index 0000000..f25e526
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright © 2008 Intel Corporation
+ *
+ * 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 (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 NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *
+ */
+
+#include <stdlib.h>
+#include <GL/glut.h>
+
+static int win_width, win_height;
+
+static void
+line(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+       glBegin(GL_LINES);
+       glVertex2f(x1, y1);
+       glVertex2f(x2, y2);
+       glEnd();
+}
+
+static void
+line3(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2)
+{
+       glBegin(GL_LINES);
+       glVertex3f(x1, y1, z1);
+       glVertex3f(x2, y2, z2);
+       glEnd();
+}
+
+static void
+display(void)
+{
+       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
+       glClearColor(0.0, 0.0, 0.0, 0.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       glColor3f(1.0, 0.0, 0.0);
+       /* clipped along xmin */
+       glBegin(GL_TRIANGLES);
+       glVertex2f(-20, win_height / 2 - 20);
+       glVertex2f(20, win_height / 2);
+       glVertex2f(-20, win_height / 2 + 20);
+       glEnd();
+
+       glColor3f(0.0, 1.0, 0.0);
+       /* clipped along ymax */
+       glBegin(GL_TRIANGLES);
+       glVertex2f(win_height / 2 - 20, win_height + 20);
+       glVertex2f(win_height / 2,      win_height - 20);
+       glVertex2f(win_height / 2 + 20, win_height + 20);
+       glEnd();
+
+       glColor3f(0.0, 0.0, 1.0);
+       /* clipped along xmax */
+       glBegin(GL_TRIANGLES);
+       glVertex2f(win_height + 20, win_height / 2 - 20);
+       glVertex2f(win_height - 20, win_height / 2);
+       glVertex2f(win_height + 20, win_height / 2 + 20);
+       glEnd();
+
+       glColor3f(1.0, 1.0, 1.0);
+       /* clipped along ymin */
+       glBegin(GL_TRIANGLES);
+       glVertex2f(win_height / 2 - 20, -20);
+       glVertex2f(win_height / 2,       20);
+       glVertex2f(win_height / 2 + 20, -20);
+       glEnd();
+
+       /* clipped along near */
+       glColor3f(1.0, 0.0, 1.0);
+       glBegin(GL_TRIANGLES);
+       glVertex3f(win_width / 2 - 20, win_height / 2 - 20,  0.5);
+       glVertex3f(win_width / 2 - 40, win_height / 2,      -0.5);
+       glVertex3f(win_width / 2 - 20, win_height / 2 + 20,  0.5);
+       glEnd();
+
+       /* clipped along far */
+       glColor3f(0.0, 1.0, 1.0);
+       glBegin(GL_TRIANGLES);
+       glVertex3f(win_width / 2 + 20, win_height / 2 - 20, 0.5);
+       glVertex3f(win_width / 2 + 40, win_height / 2,      1.5);
+       glVertex3f(win_width / 2 + 20, win_height / 2 + 20, 0.5);
+       glEnd();
+
+       /* entirely clipped along near/far */
+       glColor3f(.5, .5, .5);
+       glBegin(GL_TRIANGLES);
+       glVertex3f(win_width / 2 - 20, win_height / 2 + 20, -0.5);
+       glVertex3f(win_width / 2,      win_height / 2 + 40, -0.5);
+       glVertex3f(win_width / 2 + 20, win_height / 2 + 20, -0.5);
+       glEnd();
+
+       glBegin(GL_TRIANGLES);
+       glVertex3f(win_width / 2 - 20, win_height / 2 - 20, 1.5);
+       glVertex3f(win_width / 2,      win_height / 2 - 40, 1.5);
+       glVertex3f(win_width / 2 + 20, win_height / 2 - 20, 1.5);
+       glEnd();
+
+       glColor3f(.5, .5, .5);
+       line3(win_width / 2, win_height / 2 - 20, 1.5,
+             win_width / 2, win_height / 2 + 20, 1.5);
+
+       glColor3f(1.0, 1.0, 0.0);
+       /* clipped along both x and y limits */
+       glBegin(GL_TRIANGLES); /* xmin, ymin */
+       glVertex2f(-5, 20);
+       glVertex2f(20, 20);
+       glVertex2f(20, -5);
+       glEnd();
+       glBegin(GL_TRIANGLES); /* xmin, ymax */
+       glVertex2f(-5, win_height - 20);
+       glVertex2f(20, win_height - 20);
+       glVertex2f(20, win_height + 5);
+       glEnd();
+       glBegin(GL_TRIANGLES); /* xmax, ymax */
+       glVertex2f(win_width - 20, win_height + 5);
+       glVertex2f(win_width - 20, win_height - 20);
+       glVertex2f(win_width + 5,  win_height - 20);
+       glEnd();
+       glBegin(GL_TRIANGLES); /* xmax, ymin */
+       glVertex2f(win_width + 5, 20);
+       glVertex2f(win_width - 20, 20);
+       glVertex2f(win_width - 20, -5);
+       glEnd();
+
+       glutSwapBuffers();
+}
+
+static void
+reshape(int width, int height)
+{
+       win_width = width;
+       win_height = height;
+       glViewport(0, 0, width, height);
+
+       glMatrixMode(GL_PROJECTION);
+       glLoadIdentity();
+       glOrtho(0, win_width, 0, win_height, 0.0, -1.0);
+
+       glMatrixMode(GL_MODELVIEW);
+       glLoadIdentity();
+       glTranslatef(.25, .25, 0);
+}
+
+static void key( unsigned char key, int x, int y )
+{
+       (void) x;
+       (void) y;
+
+       switch (key) {
+       case 27: /* esc */
+               exit(0);
+               break;
+       }
+
+       glutPostRedisplay();
+}
+
+static void
+init(void)
+{
+}
+
+int
+main(int argc, char *argv[])
+{
+       win_width = 200;
+       win_height = 200;
+
+       glutInit(&argc, argv);
+       glutInitWindowPosition(0, 0);
+       glutInitWindowSize(win_width, win_height);
+       glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+       glutCreateWindow(argv[0]);
+       glutReshapeFunc(reshape);
+       glutKeyboardFunc(key);
+       glutDisplayFunc(display);
+
+       init();
+
+       glutMainLoop();
+       return 0;
+}