progs/gallium: Move into src/gallium/tests
[mesa.git] / progs / trivial / clear-scissor.c
1 /*
2 * glClear + glScissor
3 */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <GL/glut.h>
9
10
11 GLenum doubleBuffer;
12 GLint Width = 200, Height = 150;
13
14 static void Init(void)
15 {
16 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
17 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
18 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
19 fflush(stderr);
20 }
21
22 static void Reshape(int width, int height)
23 {
24 Width = width;
25 Height = height;
26
27 glViewport(0, 0, (GLint)width, (GLint)height);
28
29 glMatrixMode(GL_PROJECTION);
30 glLoadIdentity();
31 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
32 glMatrixMode(GL_MODELVIEW);
33 }
34
35 static void Key(unsigned char key, int x, int y)
36 {
37 switch (key) {
38 case 27:
39 exit(1);
40 default:
41 break;
42 }
43 glutPostRedisplay();
44 }
45
46 static void Draw(void)
47 {
48 glEnable(GL_SCISSOR_TEST);
49
50 glClearColor(1, 0, 0, 0);
51 glScissor(0, 0, Width / 2, Height / 2);
52 glClear(GL_COLOR_BUFFER_BIT);
53
54 glClearColor(0, 1, 0, 0);
55 glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
56 glClear(GL_COLOR_BUFFER_BIT);
57
58 glClearColor(0, 0, 1, 0);
59 glScissor(0, Height / 2, Width / 2, Height - Height / 2);
60 glClear(GL_COLOR_BUFFER_BIT);
61
62 glClearColor(1, 1, 1, 0);
63 glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2);
64 glClear(GL_COLOR_BUFFER_BIT);
65
66 glFlush();
67
68 if (doubleBuffer) {
69 glutSwapBuffers();
70 }
71 }
72
73 static GLenum Args(int argc, char **argv)
74 {
75 GLint i;
76
77 doubleBuffer = GL_FALSE;
78
79 for (i = 1; i < argc; i++) {
80 if (strcmp(argv[i], "-sb") == 0) {
81 doubleBuffer = GL_FALSE;
82 } else if (strcmp(argv[i], "-db") == 0) {
83 doubleBuffer = GL_TRUE;
84 } else {
85 fprintf(stderr, "%s (Bad option).\n", argv[i]);
86 return GL_FALSE;
87 }
88 }
89 return GL_TRUE;
90 }
91
92 int main(int argc, char **argv)
93 {
94 GLenum type;
95
96 glutInit(&argc, argv);
97
98 if (Args(argc, argv) == GL_FALSE) {
99 exit(1);
100 }
101
102 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
103
104 type = GLUT_RGB | GLUT_ALPHA;
105 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
106 glutInitDisplayMode(type);
107
108 if (glutCreateWindow(argv[0]) == GL_FALSE) {
109 exit(1);
110 }
111
112 Init();
113
114 glutReshapeFunc(Reshape);
115 glutKeyboardFunc(Key);
116 glutDisplayFunc(Draw);
117 glutMainLoop();
118 return 0;
119 }