2 * Copyright (c) 1993-2003, Silicon Graphics, Inc.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose and without fee is hereby granted, provided that the above
7 * copyright notice appear in all copies and that both the copyright
8 * notice and this permission notice appear in supporting documentation,
9 * and that the name of Silicon Graphics, Inc. not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission.
13 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
14 * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
16 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
17 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
18 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF
20 * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD
21 * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF
22 * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE
24 * OR PERFORMANCE OF THIS SOFTWARE.
26 * US Government Users Restricted Rights
27 * Use, duplication, or disclosure by the Government is subject to
28 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
29 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
30 * clause at DFARS 252.227-7013 and/or in similar or successor clauses
31 * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights
32 * reserved under the copyright laws of the United States.
34 * Contractor/manufacturer is:
35 * Silicon Graphics, Inc.
36 * 1500 Crittenden Lane
37 * Mountain View, CA 94043
38 * United State of America
40 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
45 * This program draws shows how to use multisampling to
46 * draw anti-aliased geometric primitives. The same
47 * display list, a pinwheel of triangles and lines of
48 * varying widths, is rendered twice. Multisampling is
49 * enabled when the left side is drawn. Multisampling is
50 * disabled when the right side is drawn.
52 * Pressing the 'b' key toggles drawing of the checkerboard
53 * background. Antialiasing is sometimes easier to see
54 * when objects are rendered over a contrasting background.
60 static int bgtoggle
= 1;
63 * Print out state values related to multisampling.
64 * Create display list with "pinwheel" of lines and
67 static void init(void)
69 static GLint buf
[1], sbuf
[1];
72 glClearColor(0.0, 0.0, 0.0, 0.0);
73 glGetIntegerv (GL_SAMPLE_BUFFERS_ARB
, buf
);
74 printf ("number of sample buffers is %d\n", buf
[0]);
75 glGetIntegerv (GL_SAMPLES_ARB
, sbuf
);
76 printf ("number of samples is %d\n", sbuf
[0]);
78 glNewList (1, GL_COMPILE
);
79 for (i
= 0; i
< 19; i
++) {
81 glRotatef(360.0*(float)i
/19.0, 0.0, 0.0, 1.0);
82 glColor3f (1.0, 1.0, 1.0);
83 glLineWidth((i
%3)+1.0);
85 glVertex2f (0.25, 0.05);
86 glVertex2f (0.9, 0.2);
88 glColor3f (0.0, 1.0, 1.0);
89 glBegin (GL_TRIANGLES
);
90 glVertex2f (0.25, 0.0);
91 glVertex2f (0.9, 0.0);
92 glVertex2f (0.875, 0.10);
98 glNewList (2, GL_COMPILE
);
99 glColor3f (1.0, 0.5, 0.0);
101 for (i
= 0; i
< 16; i
++) {
102 for (j
= 0; j
< 16; j
++) {
103 if (((i
+ j
) % 2) == 0) {
104 glVertex2f (-2.0 + (i
* 0.25), -2.0 + (j
* 0.25));
105 glVertex2f (-2.0 + (i
* 0.25), -1.75 + (j
* 0.25));
106 glVertex2f (-1.75 + (i
* 0.25), -1.75 + (j
* 0.25));
107 glVertex2f (-1.75 + (i
* 0.25), -2.0 + (j
* 0.25));
115 /* Draw two sets of primitives, so that you can
116 * compare the user of multisampling against its absence.
118 * This code enables antialiasing and draws one display list
119 * and disables and draws the other display list
121 static void display(void)
123 glClear(GL_COLOR_BUFFER_BIT
);
128 glEnable (GL_MULTISAMPLE_ARB
);
130 glTranslatef (-1.0, 0.0, 0.0);
134 glDisable (GL_MULTISAMPLE_ARB
);
136 glTranslatef (1.0, 0.0, 0.0);
142 static void reshape(int w
, int h
)
144 glViewport(0, 0, w
, h
);
145 glMatrixMode(GL_PROJECTION
);
148 gluOrtho2D (-2.0, 2.0,
149 -2.0*(GLfloat
)h
/(GLfloat
)w
, 2.0*(GLfloat
)h
/(GLfloat
)w
);
151 gluOrtho2D (-2.0*(GLfloat
)w
/(GLfloat
)h
,
152 2.0*(GLfloat
)w
/(GLfloat
)h
, -2.0, 2.0);
153 glMatrixMode(GL_MODELVIEW
);
157 static void keyboard(unsigned char key
, int x
, int y
)
162 bgtoggle
= !bgtoggle
;
165 case 27: /* Escape Key */
173 * Open window with initial window size, title bar,
174 * RGBA display mode, and handle input events.
176 int main(int argc
, char** argv
)
178 glutInit(&argc
, argv
);
179 glutInitDisplayMode (GLUT_DOUBLE
| GLUT_RGB
| GLUT_MULTISAMPLE
);
180 glutInitWindowSize (600, 300);
181 glutCreateWindow (argv
[0]);
183 glutReshapeFunc (reshape
);
184 glutKeyboardFunc (keyboard
);
185 glutDisplayFunc (display
);