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.
57 #include "glut_wrap.h"
61 static int bgtoggle
= 1;
64 * Print out state values related to multisampling.
65 * Create display list with "pinwheel" of lines and
68 static void init(void)
70 static GLint buf
[1], sbuf
[1];
73 glClearColor(0.0, 0.0, 0.0, 0.0);
74 glGetIntegerv (GL_SAMPLE_BUFFERS_ARB
, buf
);
75 printf ("number of sample buffers is %d\n", buf
[0]);
76 glGetIntegerv (GL_SAMPLES_ARB
, sbuf
);
77 printf ("number of samples is %d\n", sbuf
[0]);
79 glNewList (1, GL_COMPILE
);
80 for (i
= 0; i
< 19; i
++) {
82 glRotatef(360.0*(float)i
/19.0, 0.0, 0.0, 1.0);
83 glColor3f (1.0, 1.0, 1.0);
84 glLineWidth((i
%3)+1.0);
86 glVertex2f (0.25, 0.05);
87 glVertex2f (0.9, 0.2);
89 glColor3f (0.0, 1.0, 1.0);
90 glBegin (GL_TRIANGLES
);
91 glVertex2f (0.25, 0.0);
92 glVertex2f (0.9, 0.0);
93 glVertex2f (0.875, 0.10);
99 glNewList (2, GL_COMPILE
);
100 glColor3f (1.0, 0.5, 0.0);
102 for (i
= 0; i
< 16; i
++) {
103 for (j
= 0; j
< 16; j
++) {
104 if (((i
+ j
) % 2) == 0) {
105 glVertex2f (-2.0 + (i
* 0.25), -2.0 + (j
* 0.25));
106 glVertex2f (-2.0 + (i
* 0.25), -1.75 + (j
* 0.25));
107 glVertex2f (-1.75 + (i
* 0.25), -1.75 + (j
* 0.25));
108 glVertex2f (-1.75 + (i
* 0.25), -2.0 + (j
* 0.25));
116 /* Draw two sets of primitives, so that you can
117 * compare the user of multisampling against its absence.
119 * This code enables antialiasing and draws one display list
120 * and disables and draws the other display list
122 static void display(void)
124 glClear(GL_COLOR_BUFFER_BIT
);
129 glEnable (GL_MULTISAMPLE_ARB
);
131 glTranslatef (-1.0, 0.0, 0.0);
135 glDisable (GL_MULTISAMPLE_ARB
);
137 glTranslatef (1.0, 0.0, 0.0);
143 static void reshape(int w
, int h
)
145 glViewport(0, 0, w
, h
);
146 glMatrixMode(GL_PROJECTION
);
149 gluOrtho2D (-2.0, 2.0,
150 -2.0*(GLfloat
)h
/(GLfloat
)w
, 2.0*(GLfloat
)h
/(GLfloat
)w
);
152 gluOrtho2D (-2.0*(GLfloat
)w
/(GLfloat
)h
,
153 2.0*(GLfloat
)w
/(GLfloat
)h
, -2.0, 2.0);
154 glMatrixMode(GL_MODELVIEW
);
158 static void keyboard(unsigned char key
, int x
, int y
)
163 bgtoggle
= !bgtoggle
;
166 case 27: /* Escape Key */
174 * Open window with initial window size, title bar,
175 * RGBA display mode, and handle input events.
177 int main(int argc
, char** argv
)
179 glutInit(&argc
, argv
);
180 glutInitDisplayMode (GLUT_DOUBLE
| GLUT_RGB
| GLUT_MULTISAMPLE
);
181 glutInitWindowSize (600, 300);
182 glutCreateWindow (argv
[0]);
184 glutReshapeFunc (reshape
);
185 glutKeyboardFunc (keyboard
);
186 glutDisplayFunc (display
);