gallium: change remaining util functions to use cso sampler views
[mesa/mesa-lb.git] / progs / trivial / clear-scissor.c
blob2b6dee77a96d1d669e972cd9bff24f30eb2b09d5
1 /*
2 * glClear + glScissor
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 fflush(stderr);
22 static void Reshape(int width, int height)
24 Width = width;
25 Height = height;
27 glViewport(0, 0, (GLint)width, (GLint)height);
29 glMatrixMode(GL_PROJECTION);
30 glLoadIdentity();
31 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
32 glMatrixMode(GL_MODELVIEW);
35 static void Key(unsigned char key, int x, int y)
37 switch (key) {
38 case 27:
39 exit(1);
40 default:
41 break;
43 glutPostRedisplay();
46 static void Draw(void)
48 glEnable(GL_SCISSOR_TEST);
50 glClearColor(1, 0, 0, 0);
51 glScissor(0, 0, Width / 2, Height / 2);
52 glClear(GL_COLOR_BUFFER_BIT);
54 glClearColor(0, 1, 0, 0);
55 glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
56 glClear(GL_COLOR_BUFFER_BIT);
58 glClearColor(0, 0, 1, 0);
59 glScissor(0, Height / 2, Width / 2, Height - Height / 2);
60 glClear(GL_COLOR_BUFFER_BIT);
62 glClearColor(1, 1, 1, 0);
63 glScissor(Width / 2, Height / 2, Width - Width / 2, Height - Height / 2);
64 glClear(GL_COLOR_BUFFER_BIT);
66 glFlush();
68 if (doubleBuffer) {
69 glutSwapBuffers();
73 static GLenum Args(int argc, char **argv)
75 GLint i;
77 doubleBuffer = GL_FALSE;
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;
89 return GL_TRUE;
92 int main(int argc, char **argv)
94 GLenum type;
96 glutInit(&argc, argv);
98 if (Args(argc, argv) == GL_FALSE) {
99 exit(1);
102 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
104 type = GLUT_RGB | GLUT_ALPHA;
105 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
106 glutInitDisplayMode(type);
108 if (glutCreateWindow(argv[0]) == GL_FALSE) {
109 exit(1);
112 Init();
114 glutReshapeFunc(Reshape);
115 glutKeyboardFunc(Key);
116 glutDisplayFunc(Draw);
117 glutMainLoop();
118 return 0;