3 * Test multisampling and polygon smoothing.
15 static GLfloat Zrot = 0;
16 static GLboolean Anim = GL_TRUE;
17 static GLboolean HaveMultisample = GL_TRUE;
21 PrintString(const char *s)
24 glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
31 Polygon( GLint verts, GLfloat radius, GLfloat z )
34 for (i = 0; i < verts; i++) {
35 float a = (i * 2.0 * 3.14159) / verts;
36 float x = radius * cos(a);
37 float y = radius * sin(a);
48 glBegin(GL_LINE_LOOP);
54 glBegin(GL_LINE_LOOP);
60 Polygon(12, 0.4, 0.3);
65 Polygon(12, 0.6, 0.2);
70 Polygon(12, 0.8, 0.1);
83 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
86 if (HaveMultisample) {
87 glRasterPos2f(-3.1, -1.6);
88 PrintString("MULTISAMPLE");
90 glRasterPos2f(-0.8, -1.6);
91 PrintString("No antialiasing");
92 glRasterPos2f(1.6, -1.6);
93 PrintString("GL_POLYGON_SMOOTH");
96 if (HaveMultisample) {
97 glEnable(GL_DEPTH_TEST);
98 glEnable(GL_MULTISAMPLE_ARB);
100 glTranslatef(-2.5, 0, 0);
102 glRotatef(Zrot, 0, 0, 1);
106 glDisable(GL_MULTISAMPLE_ARB);
107 glDisable(GL_DEPTH_TEST);
111 glEnable(GL_DEPTH_TEST);
113 glTranslatef(0, 0, 0);
115 glRotatef(Zrot, 0, 0, 1);
119 glDisable(GL_DEPTH_TEST);
122 glEnable(GL_POLYGON_SMOOTH);
123 glEnable(GL_LINE_SMOOTH);
126 glTranslatef(2.5, 0, 0);
128 glRotatef(Zrot, 0, 0, 1);
132 glDisable(GL_LINE_SMOOTH);
133 glDisable(GL_POLYGON_SMOOTH);
141 Reshape( int width, int height )
143 GLfloat ar = (float) width / (float) height;
144 glViewport( 0, 0, width, height );
145 glMatrixMode( GL_PROJECTION );
147 glOrtho(-2.0*ar, 2.0*ar, -2.0, 2.0, -1.0, 1.0);
148 glMatrixMode( GL_MODELVIEW );
156 Zrot = 0.01 * glutGet(GLUT_ELAPSED_TIME);
162 Key( unsigned char key, int x, int y )
164 const GLfloat step = 1.0;
176 Zrot = (int) (Zrot - step);
179 Zrot = (int) (Zrot + step);
192 /* GLUT imposes the four samples/pixel requirement */
194 glGetIntegerv(GL_SAMPLES_ARB, &s);
195 if (!glutExtensionSupported("GL_ARB_multisample") || s < 1) {
196 printf("Warning: multisample antialiasing not supported.\n");
197 HaveMultisample = GL_FALSE;
199 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
200 printf("GL_SAMPLES_ARB = %d\n", s);
202 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
203 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
204 glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
206 glGetIntegerv(GL_MULTISAMPLE_ARB, &s);
207 printf("GL_MULTISAMPLE_ARB = %d\n", s);
212 main( int argc, char *argv[] )
214 glutInit( &argc, argv );
215 glutInitWindowPosition( 0, 0 );
216 glutInitWindowSize( 600, 300 );
217 glutInitDisplayMode( GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE |
218 GLUT_DEPTH | GLUT_MULTISAMPLE );
219 glutCreateWindow(argv[0]);
220 glutReshapeFunc( Reshape );
221 glutKeyboardFunc( Key );
222 glutDisplayFunc( Display );
224 glutIdleFunc( Idle );