nvfx: expose GLSL
[mesa/mesa-lb.git] / progs / trivial / clear-undefined.c
blob5ec33bf3d78d6fda74c3a38afc1b674a8da903a0
1 /*
2 * glClear + glScissor + Undefined content of framebuffer
3 */
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <GL/glut.h>
11 GLenum doubleBuffer;
12 GLint Width = 200, Height = 150;
14 static void Init(void)
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 fflush(stderr);
23 static void Reshape(int width, int height)
25 Width = width;
26 Height = height;
28 glViewport(0, 0, (GLint)width, (GLint)height);
30 glMatrixMode(GL_PROJECTION);
31 glLoadIdentity();
32 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
33 glMatrixMode(GL_MODELVIEW);
36 static void Key(unsigned char key, int x, int y)
38 switch (key) {
39 case 27:
40 exit(1);
41 default:
42 glutPostRedisplay();
43 return;
48 static void Draw(void)
50 glColor4f(1.0, 0.0, 0.0, 1.0);
51 glBegin(GL_QUADS);
52 glVertex2d(0.0, 0.0);
53 glVertex2d(0.0, 1.0);
54 glVertex2d(1.0, 1.0);
55 glVertex2d(1.0, 0.0);
56 glEnd();
58 glBegin(GL_QUADS);
59 glVertex2d(0.0, 0.0);
60 glVertex2d(0.0, -1.0);
61 glVertex2d(1.0, -1.0);
62 glVertex2d(1.0, 0.0);
63 glEnd();
65 glEnable(GL_SCISSOR_TEST);
66 glClearColor(1, 1, 0, 0);
67 glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
68 glClear(GL_COLOR_BUFFER_BIT);
70 glClearColor(0, 0, 1, 0);
71 glScissor(0, Height / 2, Width / 2, Height - Height / 2);
72 glClear(GL_COLOR_BUFFER_BIT);
73 glDisable(GL_SCISSOR_TEST);
75 glColor4f(0.0, 1.0, 0.0, 1.0);
76 glBegin(GL_QUADS);
77 glVertex2d( 0.0, 0.0);
78 glVertex2d( 0.0, -1.0);
79 glVertex2d(-1.0, -1.0);
80 glVertex2d(-1.0, 0.0);
81 glEnd();
83 glFlush();
85 if (doubleBuffer) {
86 glutSwapBuffers();
90 static GLenum Args(int argc, char **argv)
92 GLint i;
94 doubleBuffer = GL_TRUE;
96 for (i = 1; i < argc; i++) {
97 if (strcmp(argv[i], "-sb") == 0) {
98 doubleBuffer = GL_FALSE;
99 } else if (strcmp(argv[i], "-db") == 0) {
100 doubleBuffer = GL_TRUE;
101 } else {
102 fprintf(stderr, "%s (Bad option).\n", argv[i]);
103 return GL_FALSE;
106 return GL_TRUE;
109 int main(int argc, char **argv)
111 GLenum type;
113 glutInit(&argc, argv);
115 if (Args(argc, argv) == GL_FALSE) {
116 exit(1);
119 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
122 type = GLUT_RGB | GLUT_ALPHA;
123 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
124 glutInitDisplayMode(type);
126 if (glutCreateWindow(argv[0]) == GL_FALSE) {
127 exit(1);
130 Init();
131 Reshape(Width, Height);
133 glutReshapeFunc(Reshape);
134 glutKeyboardFunc(Key);
135 glutDisplayFunc(Draw);
136 glutMainLoop();
137 return 0;