blob: 1569860f7a2bada27206b6ab593b9007172b2f0f [file] [log] [blame]
Jakob Bornecrantz39bd7eb2008-06-13 17:42:44 +02001/*
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
11GLenum doubleBuffer;
12GLint Width = 200, Height = 150;
13
14static 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
22static 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
35static 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
47static 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 glEnable(GL_SCISSOR_TEST);
58 glClearColor(1, 1, 0, 0);
59 glScissor(Width / 2, 0, Width - Width / 2, Height / 2);
60 glClear(GL_COLOR_BUFFER_BIT);
61
62 glClearColor(0, 0, 1, 0);
63 glScissor(0, Height / 2, Width / 2, Height - Height / 2);
64 glClear(GL_COLOR_BUFFER_BIT);
65 glDisable(GL_SCISSOR_TEST);
66
67 glColor4f(0.0, 1.0, 0.0, 1.0);
68 glBegin(GL_QUADS);
69 glVertex2d( 0.0, 0.0);
70 glVertex2d( 0.0, -1.0);
71 glVertex2d(-1.0, -1.0);
72 glVertex2d(-1.0, 0.0);
73 glEnd();
74
75 glFlush();
76
77 if (doubleBuffer) {
78 glutSwapBuffers();
79 }
80}
81
82static GLenum Args(int argc, char **argv)
83{
84 GLint i;
85
86 doubleBuffer = GL_TRUE;
87
88 for (i = 1; i < argc; i++) {
89 if (strcmp(argv[i], "-sb") == 0) {
90 doubleBuffer = GL_FALSE;
91 } else if (strcmp(argv[i], "-db") == 0) {
92 doubleBuffer = GL_TRUE;
93 } else {
94 fprintf(stderr, "%s (Bad option).\n", argv[i]);
95 return GL_FALSE;
96 }
97 }
98 return GL_TRUE;
99}
100
101int main(int argc, char **argv)
102{
103 GLenum type;
104
105 glutInit(&argc, argv);
106
107 if (Args(argc, argv) == GL_FALSE) {
108 exit(1);
109 }
110
111 glutInitWindowPosition(0, 0); glutInitWindowSize( Width, Height );
112
113
114 type = GLUT_RGB | GLUT_ALPHA;
115 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
116 glutInitDisplayMode(type);
117
118 if (glutCreateWindow(argv[0]) == GL_FALSE) {
119 exit(1);
120 }
121
122 Init();
123 Reshape(Width, Height);
124
125 glutReshapeFunc(Reshape);
126 glutKeyboardFunc(Key);
127 glutDisplayFunc(Draw);
128 glutMainLoop();
129 return 0;
130}