Merge commit 'origin/master' into gallium-0.2
[mesa.git] / progs / trivial / clear-undefined.c
1 /*
2 * glClear + glScissor + Undefined content of framebuffer
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 fprintf(stderr, "Top right corner should be red\n");
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 glutPostRedisplay();
42 return;
43 }
44
45 }
46
47 static void Draw(void)
48 {
49 glColor4f(1.0, 0.0, 0.0, 1.0);
50 glBegin(GL_QUADS);
51 glVertex2d(0.0, 0.0);
52 glVertex2d(0.0, 1.0);
53 glVertex2d(1.0, 1.0);
54 glVertex2d(1.0, 0.0);
55 glEnd();
56
57 glBegin(GL_QUADS);
58 glVertex2d(0.0, 0.0);
59 glVertex2d(0.0, -1.0);
60 glVertex2d(1.0, -1.0);
61 glVertex2d(1.0, 0.0);
62 glEnd();
63
64 glEnable(GL_SCISSOR_TEST);
65 glClearColor(1, 1, 0, 0);
66 glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
67 glClear(GL_COLOR_BUFFER_BIT);
68
69 glClearColor(0, 0, 1, 0);
70 glScissor(0, Height / 2, Width / 2, Height - Height / 2);
71 glClear(GL_COLOR_BUFFER_BIT);
72 glDisable(GL_SCISSOR_TEST);
73
74 glColor4f(0.0, 1.0, 0.0, 1.0);
75 glBegin(GL_QUADS);
76 glVertex2d( 0.0, 0.0);
77 glVertex2d( 0.0, -1.0);
78 glVertex2d(-1.0, -1.0);
79 glVertex2d(-1.0, 0.0);
80 glEnd();
81
82 glFlush();
83
84 if (doubleBuffer) {
85 glutSwapBuffers();
86 }
87 }
88
89 static GLenum Args(int argc, char **argv)
90 {
91 GLint i;
92
93 doubleBuffer = GL_TRUE;
94
95 for (i = 1; i < argc; i++) {
96 if (strcmp(argv[i], "-sb") == 0) {
97 doubleBuffer = GL_FALSE;
98 } else if (strcmp(argv[i], "-db") == 0) {
99 doubleBuffer = GL_TRUE;
100 } else {
101 fprintf(stderr, "%s (Bad option).\n", argv[i]);
102 return GL_FALSE;
103 }
104 }
105 return GL_TRUE;
106 }
107
108 int main(int argc, char **argv)
109 {
110 GLenum type;
111
112 glutInit(&argc, argv);
113
114 if (Args(argc, argv) == GL_FALSE) {
115 exit(1);
116 }
117
118 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
119
120
121 type = GLUT_RGB | GLUT_ALPHA;
122 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
123 glutInitDisplayMode(type);
124
125 if (glutCreateWindow(argv[0]) == GL_FALSE) {
126 exit(1);
127 }
128
129 Init();
130 Reshape(Width, Height);
131
132 glutReshapeFunc(Reshape);
133 glutKeyboardFunc(Key);
134 glutDisplayFunc(Draw);
135 glutMainLoop();
136 return 0;
137 }