Keith Whitwell | a30d2c5 | 2008-09-15 13:47:12 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Test display list corner cases. |
| 3 | */ |
| 4 | |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <math.h> |
| 9 | #include <GL/glut.h> |
| 10 | |
| 11 | |
| 12 | static int Win; |
| 13 | static GLfloat Xrot = 0, Yrot = 0, Zrot = 0; |
| 14 | static GLboolean Anim = GL_FALSE; |
| 15 | static GLuint List1 = 0, List2 = 0; |
| 16 | |
| 17 | |
| 18 | static void |
| 19 | Idle(void) |
| 20 | { |
| 21 | Xrot += 3.0; |
| 22 | Yrot += 4.0; |
| 23 | Zrot += 2.0; |
| 24 | glutPostRedisplay(); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | static void |
| 29 | Draw(void) |
| 30 | { |
| 31 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 32 | |
| 33 | glPushMatrix(); |
| 34 | glRotatef(Xrot, 1, 0, 0); |
| 35 | glRotatef(Yrot, 0, 1, 0); |
| 36 | glRotatef(Zrot, 0, 0, 1); |
| 37 | |
| 38 | glCallList(List1); |
| 39 | glCallList(List2); |
| 40 | |
| 41 | glPopMatrix(); |
| 42 | |
| 43 | glutSwapBuffers(); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | static void |
| 48 | Reshape(int width, int height) |
| 49 | { |
| 50 | glViewport(0, 0, width, height); |
| 51 | glMatrixMode(GL_PROJECTION); |
| 52 | glLoadIdentity(); |
| 53 | glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); |
| 54 | glMatrixMode(GL_MODELVIEW); |
| 55 | glLoadIdentity(); |
| 56 | glTranslatef(0.0, 0.0, -15.0); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | static void |
| 61 | Key(unsigned char key, int x, int y) |
| 62 | { |
| 63 | const GLfloat step = 3.0; |
| 64 | (void) x; |
| 65 | (void) y; |
| 66 | switch (key) { |
| 67 | case 'a': |
| 68 | Anim = !Anim; |
| 69 | if (Anim) |
| 70 | glutIdleFunc(Idle); |
| 71 | else |
| 72 | glutIdleFunc(NULL); |
| 73 | break; |
| 74 | case 'z': |
| 75 | Zrot -= step; |
| 76 | break; |
| 77 | case 'Z': |
| 78 | Zrot += step; |
| 79 | break; |
| 80 | case 27: |
| 81 | glutDestroyWindow(Win); |
| 82 | exit(0); |
| 83 | break; |
| 84 | } |
| 85 | glutPostRedisplay(); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static void |
| 90 | SpecialKey(int key, int x, int y) |
| 91 | { |
| 92 | const GLfloat step = 3.0; |
| 93 | (void) x; |
| 94 | (void) y; |
| 95 | switch (key) { |
| 96 | case GLUT_KEY_UP: |
| 97 | Xrot -= step; |
| 98 | break; |
| 99 | case GLUT_KEY_DOWN: |
| 100 | Xrot += step; |
| 101 | break; |
| 102 | case GLUT_KEY_LEFT: |
| 103 | Yrot -= step; |
| 104 | break; |
| 105 | case GLUT_KEY_RIGHT: |
| 106 | Yrot += step; |
| 107 | break; |
| 108 | } |
| 109 | glutPostRedisplay(); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | static void |
| 114 | Init(void) |
| 115 | { |
| 116 | /* List1: start of primitive */ |
| 117 | List1 = glGenLists(1); |
| 118 | glNewList(List1, GL_COMPILE); |
| 119 | glBegin(GL_POLYGON); |
| 120 | glVertex2f(-1, -1); |
| 121 | glVertex2f( 1, -1); |
| 122 | glEndList(); |
| 123 | |
| 124 | /* List2: end of primitive */ |
| 125 | List2 = glGenLists(1); |
| 126 | glNewList(List2, GL_COMPILE); |
| 127 | glVertex2f( 1, 1); |
| 128 | glVertex2f(-1, 1); |
| 129 | glEnd(); |
| 130 | glEndList(); |
| 131 | |
| 132 | glEnable(GL_DEPTH_TEST); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | int |
| 137 | main(int argc, char *argv[]) |
| 138 | { |
| 139 | glutInit(&argc, argv); |
| 140 | glutInitWindowPosition(0, 0); |
| 141 | glutInitWindowSize(400, 400); |
| 142 | glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); |
| 143 | Win = glutCreateWindow(argv[0]); |
| 144 | glutReshapeFunc(Reshape); |
| 145 | glutKeyboardFunc(Key); |
| 146 | glutSpecialFunc(SpecialKey); |
| 147 | glutDisplayFunc(Draw); |
| 148 | if (Anim) |
| 149 | glutIdleFunc(Idle); |
| 150 | Init(); |
| 151 | glutMainLoop(); |
| 152 | return 0; |
| 153 | } |