~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to progs/samples/accum.c

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
 
3
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
23
 */
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <stdlib.h>
 
27
#include <GL/glut.h>
 
28
 
 
29
 
 
30
GLenum doubleBuffer;
 
31
GLint thing1, thing2;
 
32
 
 
33
 
 
34
static void Init(void)
 
35
{
 
36
 
 
37
    glClearColor(0.0, 0.0, 0.0, 0.0);
 
38
    glClearAccum(0.0, 0.0, 0.0, 0.0);
 
39
 
 
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();
 
45
 
 
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();
 
51
}
 
52
 
 
53
static void Reshape(int width, int height)
 
54
{
 
55
 
 
56
    glViewport(0, 0, (GLint)width, (GLint)height);
 
57
 
 
58
    glMatrixMode(GL_PROJECTION);
 
59
    glLoadIdentity();
 
60
    glMatrixMode(GL_MODELVIEW);
 
61
    glLoadIdentity();
 
62
}
 
63
 
 
64
static void Key(unsigned char key, int x, int y)
 
65
{
 
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;
 
79
    }
 
80
 
 
81
    glutPostRedisplay();
 
82
}
 
83
 
 
84
static void Draw(void)
 
85
{
 
86
 
 
87
    glPushMatrix();
 
88
 
 
89
    glScalef(0.8, 0.8, 1.0);
 
90
 
 
91
    glClear(GL_COLOR_BUFFER_BIT);
 
92
    glCallList(thing1);
 
93
    glAccum(GL_LOAD, 0.5);
 
94
 
 
95
    glClear(GL_COLOR_BUFFER_BIT);
 
96
    glCallList(thing2);
 
97
    glAccum(GL_ACCUM, 0.5);
 
98
 
 
99
    glAccum(GL_RETURN, 1.0);
 
100
 
 
101
    glPopMatrix();
 
102
 
 
103
    glFlush();
 
104
 
 
105
    if (doubleBuffer) {
 
106
        glutSwapBuffers();
 
107
    }
 
108
}
 
109
 
 
110
static GLenum Args(int argc, char **argv)
 
111
{
 
112
    GLint i;
 
113
 
 
114
    doubleBuffer = GL_FALSE;
 
115
 
 
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;
 
124
        }
 
125
    }
 
126
    return GL_TRUE;
 
127
}
 
128
 
 
129
int main(int argc, char **argv)
 
130
{
 
131
    GLenum type;
 
132
 
 
133
    glutInit(&argc, argv);
 
134
 
 
135
    if (Args(argc, argv) == GL_FALSE) {
 
136
        exit(1);
 
137
    }
 
138
 
 
139
    glutInitWindowPosition(0, 0);
 
140
    glutInitWindowSize( 300, 300);
 
141
 
 
142
    type = GLUT_RGB | GLUT_ACCUM;
 
143
    type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
 
144
    glutInitDisplayMode(type);
 
145
 
 
146
    if (glutCreateWindow("Accum Test") == GL_FALSE) {
 
147
        exit(1);
 
148
    }
 
149
 
 
150
    Init();
 
151
 
 
152
    glutReshapeFunc(Reshape);
 
153
    glutKeyboardFunc(Key);
 
154
    glutDisplayFunc(Draw);
 
155
    glutMainLoop();
 
156
        return 0;
 
157
}