summaryrefslogtreecommitdiff
path: root/progs/tests
diff options
context:
space:
mode:
Diffstat (limited to 'progs/tests')
-rw-r--r--progs/tests/Makefile1
-rw-r--r--progs/tests/SConscript1
-rw-r--r--progs/tests/cylwrap.c204
3 files changed, 206 insertions, 0 deletions
diff --git a/progs/tests/Makefile b/progs/tests/Makefile
index a38f411def..d33415ab05 100644
--- a/progs/tests/Makefile
+++ b/progs/tests/Makefile
@@ -41,6 +41,7 @@ SOURCES = \
copypixrate.c \
crossbar.c \
cva.c \
+ cylwrap.c \
drawbuffers.c \
drawbuffers2.c \
exactrast.c \
diff --git a/progs/tests/SConscript b/progs/tests/SConscript
index 0a11b965f7..04e4bdf8c2 100644
--- a/progs/tests/SConscript
+++ b/progs/tests/SConscript
@@ -45,6 +45,7 @@ progs = [
'copypixrate',
'crossbar',
'cva',
+ 'cylwrap',
'drawbuffers',
'drawbuffers2',
'exactrast',
diff --git a/progs/tests/cylwrap.c b/progs/tests/cylwrap.c
new file mode 100644
index 0000000000..9d541e319f
--- /dev/null
+++ b/progs/tests/cylwrap.c
@@ -0,0 +1,204 @@
+/*
+ * Test cylindrical texcoord wrapping
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/glut.h>
+
+static int Win;
+static int WinWidth = 600, WinHeight = 400;
+static GLboolean CylWrap = GL_TRUE;
+
+
+
+static void
+PrintString(const char *s)
+{
+ while (*s) {
+ glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
+ s++;
+ }
+}
+
+
+static void
+DrawSample(GLboolean wrap)
+{
+ float p;
+
+ glEnable(GL_TEXTURE_2D);
+
+ /* texured quad */
+ glBegin(GL_QUAD_STRIP);
+ for (p = 0.0; p <= 1.001; p += 0.1) {
+ float x = -2.0 + p * 4.0;
+ float s = p + 0.5;
+ if (wrap && s > 1.0)
+ s -= 1.0;
+ glTexCoord2f(s, 0); glVertex2f(x, -1);
+ glTexCoord2f(s, 1); glVertex2f(x, +1);
+ }
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+
+ /* hash marks */
+ glColor3f(0,0,0);
+ glBegin(GL_LINES);
+ for (p = 0.0; p <= 1.001; p += 0.1) {
+ float x = -2.0 + p * 4.0;
+ glVertex2f(x, -1.1);
+ glVertex2f(x, -0.8);
+ }
+ glEnd();
+
+ /* labels */
+ glColor3f(1,1,1);
+ for (p = 0.0; p <= 1.001; p += 0.1) {
+ char str[100];
+ float x = -2.0 + p * 4.0;
+ float s = p + 0.5;
+
+ if (wrap && s > 1.0)
+ s -= 1.0;
+
+ sprintf(str, "%3.1f", s);
+ glRasterPos2f(x, -1.2);
+ glBitmap(0, 0, 0, 0, -11, 0, NULL);
+ PrintString(str);
+ if (p == 0.0) {
+ glBitmap(0, 0, 0, 0, -55, 0, NULL);
+ PrintString("s =");
+ }
+ }
+}
+
+
+static void
+Draw(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glPushMatrix();
+ glTranslatef(0, +1.2, 0);
+ DrawSample(GL_FALSE);
+ glPopMatrix();
+
+ /* set Mesa back-door state for testing cylindrical wrap mode */
+ if (CylWrap)
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.125);
+
+ glPushMatrix();
+ glTranslatef(0, -1.2, 0);
+ DrawSample(GL_TRUE);
+ glPopMatrix();
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 1.0);
+
+ glutSwapBuffers();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+ WinWidth = width;
+ WinHeight = 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 'c':
+ case 'C':
+ CylWrap = !CylWrap;
+ if (CylWrap)
+ printf("Cylindrical wrap on.\n");
+ else
+ printf("Cylindrical wrap off.\n");
+ break;
+ case 27:
+ glutDestroyWindow(Win);
+ exit(0);
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+MakeSineWaveTexture(void)
+{
+ GLubyte tex[128][512][4];
+ int i, j;
+
+ for (j = 0; j < 128; j++) {
+ for (i = 0; i < 512; i++) {
+ float x = i / 511.0 * 2.0 * M_PI + M_PI * 0.5;
+ float y0 = sin(x) * 0.5 + 0.5;
+ int jy0 = y0 * 128;
+ float y1 = sin(x + M_PI) * 0.5 + 0.5;
+ int jy1 = y1 * 128;
+ if (j < jy0)
+ tex[j][i][0] = 0xff;
+ else
+ tex[j][i][0] = 0;
+ if (j < jy1)
+ tex[j][i][1] = 0xff;
+ else
+ tex[j][i][1] = 0;
+ tex[j][i][2] = 0;
+ tex[j][i][3] = 0xff;
+ }
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 128, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+}
+
+
+static void
+Init(void)
+{
+ glBindTexture(GL_TEXTURE_2D, 5);
+ MakeSineWaveTexture();
+
+ glClearColor(0.5, 0.5, 0.5, 0.0);
+ glPointSize(3.0);
+
+ printf("Press 'c' to toggle cylindrical wrap mode.\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(WinWidth, WinHeight);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ Win = glutCreateWindow(argv[0]);
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ Init();
+ glutMainLoop();
+ return 0;
+}