gallium: add target-helpers/wrap_screen.c to C_SOURCES
[mesa/mesa-lb.git] / progs / samples / accum.c
blob24dfc07d2a6ffba71ee54df22f67171914f8bd48
1 /*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13 * ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <GL/glut.h>
30 GLenum doubleBuffer;
31 GLint thing1, thing2;
34 static void Init(void)
37 glClearColor(0.0, 0.0, 0.0, 0.0);
38 glClearAccum(0.0, 0.0, 0.0, 0.0);
40 thing1 = glGenLists(1);
41 glNewList(thing1, GL_COMPILE);
42 glColor3f(1.0, 0.0, 0.0);
43 glRectf(-1.0, -1.0, 1.0, 0.0);
44 glEndList();
46 thing2 = glGenLists(1);
47 glNewList(thing2, GL_COMPILE);
48 glColor3f(0.0, 1.0, 0.0);
49 glRectf(0.0, -1.0, 1.0, 1.0);
50 glEndList();
53 static void Reshape(int width, int height)
56 glViewport(0, 0, (GLint)width, (GLint)height);
58 glMatrixMode(GL_PROJECTION);
59 glLoadIdentity();
60 glMatrixMode(GL_MODELVIEW);
61 glLoadIdentity();
64 static void Key(unsigned char key, int x, int y)
66 (void) x;
67 (void) y;
68 switch (key) {
69 case 27:
70 exit(1);
71 case '1':
72 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
73 break;
74 case '2':
75 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
76 break;
77 default:
78 return;
81 glutPostRedisplay();
84 static void Draw(void)
87 glPushMatrix();
89 glScalef(0.8, 0.8, 1.0);
91 glClear(GL_COLOR_BUFFER_BIT);
92 glCallList(thing1);
93 glAccum(GL_LOAD, 0.5);
95 glClear(GL_COLOR_BUFFER_BIT);
96 glCallList(thing2);
97 glAccum(GL_ACCUM, 0.5);
99 glAccum(GL_RETURN, 1.0);
101 glPopMatrix();
103 glFlush();
105 if (doubleBuffer) {
106 glutSwapBuffers();
110 static GLenum Args(int argc, char **argv)
112 GLint i;
114 doubleBuffer = GL_FALSE;
116 for (i = 1; i < argc; i++) {
117 if (strcmp(argv[i], "-sb") == 0) {
118 doubleBuffer = GL_FALSE;
119 } else if (strcmp(argv[i], "-db") == 0) {
120 doubleBuffer = GL_TRUE;
121 } else {
122 printf("%s (Bad option).\n", argv[i]);
123 return GL_FALSE;
126 return GL_TRUE;
129 int main(int argc, char **argv)
131 GLenum type;
133 glutInit(&argc, argv);
135 if (Args(argc, argv) == GL_FALSE) {
136 exit(1);
139 glutInitWindowPosition(0, 0);
140 glutInitWindowSize( 300, 300);
142 type = GLUT_RGB | GLUT_ACCUM;
143 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
144 glutInitDisplayMode(type);
146 if (glutCreateWindow("Accum Test") == GL_FALSE) {
147 exit(1);
150 Init();
152 glutReshapeFunc(Reshape);
153 glutKeyboardFunc(Key);
154 glutDisplayFunc(Draw);
155 glutMainLoop();
156 return 0;