2 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
4 * Permission to use, copy, modify, and distribute this software for
5 * any purpose and without fee is hereby granted, provided that the above
6 * copyright notice appear in all copies and that both the copyright notice
7 * and this permission notice appear in supporting documentation, and that
8 * the name of Silicon Graphics, Inc. not be used in advertising
9 * or publicity pertaining to distribution of the software without specific,
10 * written prior permission.
12 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
13 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
14 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
15 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
16 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
17 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
18 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
19 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
20 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
21 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
23 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
25 * US Government Users Restricted Rights
26 * Use, duplication, or disclosure by the Government is subject to
27 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
28 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
29 * clause at DFARS 252.227-7013 and/or in similar or successor
30 * clauses in the FAR or the DOD or NASA FAR Supplement.
31 * Unpublished-- rights reserved under the copyright laws of the
32 * United States. Contractor/manufacturer is Silicon Graphics,
33 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
35 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
40 * This program draws filled polygons with antialiased
41 * edges. The special GL_SRC_ALPHA_SATURATE blending
43 * Pressing the 't' key turns the antialiasing on and off.
49 GLboolean polySmooth
= GL_TRUE
;
51 static void init(void)
54 glEnable (GL_CULL_FACE
);
55 glBlendFunc (GL_SRC_ALPHA_SATURATE
, GL_ONE
);
56 glClearColor (0.0, 0.0, 0.0, 0.0);
61 static void drawCube(GLdouble x0
, GLdouble x1
, GLdouble y0
, GLdouble y1
,
62 GLdouble z0
, GLdouble z1
)
64 static GLfloat v
[8][3];
65 static GLfloat c
[8][4] = {
66 {0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 1.0},
67 {0.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0},
68 {0.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 1.0, 1.0},
69 {0.0, 1.0, 1.0, 1.0}, {1.0, 1.0, 1.0, 1.0}
72 /* indices of front, top, left, bottom, right, back faces */
73 static GLubyte indices
[NFACE
][4] = {
74 {4, 5, 6, 7}, {2, 3, 7, 6}, {0, 4, 7, 3},
75 {0, 1, 5, 4}, {1, 5, 6, 2}, {0, 3, 2, 1}
78 v
[0][0] = v
[3][0] = v
[4][0] = v
[7][0] = x0
;
79 v
[1][0] = v
[2][0] = v
[5][0] = v
[6][0] = x1
;
80 v
[0][1] = v
[1][1] = v
[4][1] = v
[5][1] = y0
;
81 v
[2][1] = v
[3][1] = v
[6][1] = v
[7][1] = y1
;
82 v
[0][2] = v
[1][2] = v
[2][2] = v
[3][2] = z0
;
83 v
[4][2] = v
[5][2] = v
[6][2] = v
[7][2] = z1
;
86 glEnableClientState (GL_VERTEX_ARRAY
);
87 glEnableClientState (GL_COLOR_ARRAY
);
88 glVertexPointer (3, GL_FLOAT
, 0, v
);
89 glColorPointer (4, GL_FLOAT
, 0, c
);
90 glDrawElements (GL_QUADS
, NFACE
*4, GL_UNSIGNED_BYTE
, indices
);
91 glDisableClientState (GL_VERTEX_ARRAY
);
92 glDisableClientState (GL_COLOR_ARRAY
);
94 printf ("If this is GL Version 1.0, ");
95 printf ("vertex arrays are not supported.\n");
100 /* Note: polygons must be drawn from front to back
101 * for proper blending.
103 static void display(void)
106 glClear (GL_COLOR_BUFFER_BIT
);
108 glEnable (GL_POLYGON_SMOOTH
);
109 glDisable (GL_DEPTH_TEST
);
112 glClear (GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
113 glDisable (GL_BLEND
);
114 glDisable (GL_POLYGON_SMOOTH
);
115 glEnable (GL_DEPTH_TEST
);
119 glTranslatef (0.0, 0.0, -8.0);
120 glRotatef (30.0, 1.0, 0.0, 0.0);
121 glRotatef (60.0, 0.0, 1.0, 0.0);
122 drawCube(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5);
128 static void reshape(int w
, int h
)
130 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
131 glMatrixMode(GL_PROJECTION
);
133 gluPerspective(30.0, (GLfloat
) w
/(GLfloat
) h
, 1.0, 20.0);
134 glMatrixMode(GL_MODELVIEW
);
139 static void keyboard(unsigned char key
, int x
, int y
)
144 polySmooth
= !polySmooth
;
148 exit(0); /* Escape key */
157 int main(int argc
, char** argv
)
159 glutInit(&argc
, argv
);
160 glutInitDisplayMode (GLUT_SINGLE
| GLUT_RGB
161 | GLUT_ALPHA
| GLUT_DEPTH
);
162 glutInitWindowSize(200, 200);
163 glutCreateWindow(argv
[0]);
165 glutReshapeFunc (reshape
);
166 glutKeyboardFunc (keyboard
);
167 glutDisplayFunc (display
);