3 * Test multisampling and polygon smoothing.
15 static GLfloat Zrot
= 0;
16 static GLboolean Anim
= GL_TRUE
;
17 static GLboolean HaveMultisample
= GL_TRUE
;
18 static GLboolean DoMultisample
= GL_TRUE
;
22 PrintString(const char *s
)
25 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
32 Polygon( GLint verts
, GLfloat radius
, GLfloat z
)
35 for (i
= 0; i
< verts
; i
++) {
36 float a
= (i
* 2.0 * 3.14159) / verts
;
37 float x
= radius
* cos(a
);
38 float y
= radius
* sin(a
);
49 glBegin(GL_LINE_LOOP
);
55 glBegin(GL_LINE_LOOP
);
61 Polygon(12, 0.4, 0.3);
66 Polygon(12, 0.6, 0.2);
71 Polygon(12, 0.8, 0.1);
84 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
87 if (HaveMultisample
) {
88 glRasterPos2f(-3.1, -1.6);
90 PrintString("MULTISAMPLE");
92 PrintString("MULTISAMPLE (off)");
94 glRasterPos2f(-0.8, -1.6);
95 PrintString("No antialiasing");
96 glRasterPos2f(1.6, -1.6);
97 PrintString("GL_POLYGON_SMOOTH");
100 if (HaveMultisample
) {
101 glEnable(GL_DEPTH_TEST
);
103 glEnable(GL_MULTISAMPLE_ARB
);
105 glTranslatef(-2.5, 0, 0);
107 glRotatef(Zrot
, 0, 0, 1);
111 glDisable(GL_MULTISAMPLE_ARB
);
112 glDisable(GL_DEPTH_TEST
);
116 glEnable(GL_DEPTH_TEST
);
118 glTranslatef(0, 0, 0);
120 glRotatef(Zrot
, 0, 0, 1);
124 glDisable(GL_DEPTH_TEST
);
127 glEnable(GL_POLYGON_SMOOTH
);
128 glEnable(GL_LINE_SMOOTH
);
131 glTranslatef(2.5, 0, 0);
133 glRotatef(Zrot
, 0, 0, 1);
137 glDisable(GL_LINE_SMOOTH
);
138 glDisable(GL_POLYGON_SMOOTH
);
146 Reshape( int width
, int height
)
148 GLfloat ar
= (float) width
/ (float) height
;
149 glViewport( 0, 0, width
, height
);
150 glMatrixMode( GL_PROJECTION
);
152 glOrtho(-2.0*ar
, 2.0*ar
, -2.0, 2.0, -1.0, 1.0);
153 glMatrixMode( GL_MODELVIEW
);
161 Zrot
= 0.01 * glutGet(GLUT_ELAPSED_TIME
);
167 Key( unsigned char key
, int x
, int y
)
169 const GLfloat step
= 1.0;
181 DoMultisample
= !DoMultisample
;
184 Zrot
= (int) (Zrot
- step
);
187 Zrot
= (int) (Zrot
+ step
);
200 /* GLUT imposes the four samples/pixel requirement */
202 glGetIntegerv(GL_SAMPLES_ARB
, &s
);
203 if (!glutExtensionSupported("GL_ARB_multisample") || s
< 1) {
204 printf("Warning: multisample antialiasing not supported.\n");
205 HaveMultisample
= GL_FALSE
;
207 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
208 printf("GL_SAMPLES_ARB = %d\n", s
);
210 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
211 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
212 glBlendFunc(GL_SRC_ALPHA_SATURATE
, GL_ONE
);
214 glGetIntegerv(GL_MULTISAMPLE_ARB
, &s
);
215 printf("GL_MULTISAMPLE_ARB = %d\n", s
);
220 main( int argc
, char *argv
[] )
222 glutInit( &argc
, argv
);
223 glutInitWindowPosition( 0, 0 );
224 glutInitWindowSize( 600, 300 );
225 glutInitDisplayMode( GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
|
226 GLUT_DEPTH
| GLUT_MULTISAMPLE
);
227 glutCreateWindow(argv
[0]);
228 glutReshapeFunc( Reshape
);
229 glutKeyboardFunc( Key
);
230 glutDisplayFunc( Display
);
232 glutIdleFunc( Idle
);