Merge commit 'origin/master' into gallium-0.2
[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 }
20
21 static void Reshape(int width, int height)
22 {
23 Width = width;
24 Height = height;
25
26 glViewport(0, 0, (GLint)width, (GLint)height);
27
28 glMatrixMode(GL_PROJECTION);
29 glLoadIdentity();
30 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
31 glMatrixMode(GL_MODELVIEW);
32 }
33
34 static void Key(unsigned char key, int x, int y)
35 {
36 switch (key) {
37 case 27:
38 exit(1);
39 default:
40 return;
41 }
42 glutPostRedisplay();
43 }
44
45 static void Draw(void)
46 {
47 glEnable(GL_SCISSOR_TEST);
48
49 glClearColor(1, 0, 0, 0);
50 glScissor(0, 0, Width / 2, Height / 2);
51 glClear(GL_COLOR_BUFFER_BIT);
52
53 glClearColor(0, 1, 0, 0);
54 glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
55 glClear(GL_COLOR_BUFFER_BIT);
56
57 glClearColor(0, 0, 1, 0);
58 glScissor(0, Height / 2, Width / 2, Height - Height / 2);
59 glClear(GL_COLOR_BUFFER_BIT);
60
61 glClearColor(1, 1, 1, 0);
62 glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2);
63 glClear(GL_COLOR_BUFFER_BIT);
64
65 glFlush();
66
67 if (doubleBuffer) {
68 glutSwapBuffers();
69 }
70 }
71
72 static GLenum Args(int argc, char **argv)
73 {
74 GLint i;
75
76 doubleBuffer = GL_FALSE;
77
78 for (i = 1; i < argc; i++) {
79 if (strcmp(argv[i], "-sb") == 0) {
80 doubleBuffer = GL_FALSE;
81 } else if (strcmp(argv[i], "-db") == 0) {
82 doubleBuffer = GL_TRUE;
83 } else {
84 fprintf(stderr, "%s (Bad option).\n", argv[i]);
85 return GL_FALSE;
86 }
87 }
88 return GL_TRUE;
89 }
90
91 int main(int argc, char **argv)
92 {
93 GLenum type;
94
95 glutInit(&argc, argv);
96
97 if (Args(argc, argv) == GL_FALSE) {
98 exit(1);
99 }
100
101 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
102
103 type = GLUT_RGB | GLUT_ALPHA;
104 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
105 glutInitDisplayMode(type);
106
107 if (glutCreateWindow(argv[0]) == GL_FALSE) {
108 exit(1);
109 }
110
111 Init();
112
113 glutReshapeFunc(Reshape);
114 glutKeyboardFunc(Key);
115 glutDisplayFunc(Draw);
116 glutMainLoop();
117 return 0;
118 }