3 * Test multisampling and polygon smoothing.
16 static GLfloat Zrot
= 0;
17 static GLboolean Anim
= GL_TRUE
;
18 static GLboolean HaveMultisample
= GL_TRUE
;
19 static GLboolean DoMultisample
= GL_TRUE
;
23 PrintString(const char *s
)
26 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
33 doPolygon( GLint verts
, GLfloat radius
, GLfloat z
)
36 for (i
= 0; i
< verts
; i
++) {
37 float a
= (i
* 2.0 * 3.14159) / verts
;
38 float x
= radius
* cos(a
);
39 float y
= radius
* sin(a
);
50 glBegin(GL_LINE_LOOP
);
51 doPolygon(12, 1.2, 0);
56 glBegin(GL_LINE_LOOP
);
57 doPolygon(12, 1.1, 0);
62 doPolygon(12, 0.4, 0.3);
67 doPolygon(12, 0.6, 0.2);
72 doPolygon(12, 0.8, 0.1);
77 doPolygon(12, 1.0, 0);
85 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
88 if (HaveMultisample
) {
89 glRasterPos2f(-3.1, -1.6);
91 PrintString("MULTISAMPLE");
93 PrintString("MULTISAMPLE (off)");
95 glRasterPos2f(-0.8, -1.6);
96 PrintString("No antialiasing");
97 glRasterPos2f(1.6, -1.6);
98 PrintString("GL_POLYGON_SMOOTH");
101 if (HaveMultisample
) {
102 glEnable(GL_DEPTH_TEST
);
104 glEnable(GL_MULTISAMPLE_ARB
);
106 glTranslatef(-2.5, 0, 0);
108 glRotatef(Zrot
, 0, 0, 1);
112 glDisable(GL_MULTISAMPLE_ARB
);
113 glDisable(GL_DEPTH_TEST
);
117 glEnable(GL_DEPTH_TEST
);
119 glTranslatef(0, 0, 0);
121 glRotatef(Zrot
, 0, 0, 1);
125 glDisable(GL_DEPTH_TEST
);
128 glEnable(GL_POLYGON_SMOOTH
);
129 glEnable(GL_LINE_SMOOTH
);
132 glTranslatef(2.5, 0, 0);
134 glRotatef(Zrot
, 0, 0, 1);
138 glDisable(GL_LINE_SMOOTH
);
139 glDisable(GL_POLYGON_SMOOTH
);
147 Reshape( int width
, int height
)
149 GLfloat ar
= (float) width
/ (float) height
;
150 glViewport( 0, 0, width
, height
);
151 glMatrixMode( GL_PROJECTION
);
153 glOrtho(-2.0*ar
, 2.0*ar
, -2.0, 2.0, -1.0, 1.0);
154 glMatrixMode( GL_MODELVIEW
);
162 Zrot
= 0.01 * glutGet(GLUT_ELAPSED_TIME
);
168 Key( unsigned char key
, int x
, int y
)
170 const GLfloat step
= 1.0;
182 DoMultisample
= !DoMultisample
;
185 Zrot
= (int) (Zrot
- step
);
188 Zrot
= (int) (Zrot
+ step
);
201 /* GLUT imposes the four samples/pixel requirement */
203 glGetIntegerv(GL_SAMPLES_ARB
, &s
);
204 if (!glutExtensionSupported("GL_ARB_multisample") || s
< 1) {
205 printf("Warning: multisample antialiasing not supported.\n");
206 HaveMultisample
= GL_FALSE
;
208 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
209 printf("GL_SAMPLES_ARB = %d\n", s
);
211 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
212 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
213 glBlendFunc(GL_SRC_ALPHA_SATURATE
, GL_ONE
);
215 glGetIntegerv(GL_MULTISAMPLE_ARB
, &s
);
216 printf("GL_MULTISAMPLE_ARB = %d\n", s
);
221 main( int argc
, char *argv
[] )
223 glutInit( &argc
, argv
);
224 glutInitWindowPosition( 0, 0 );
225 glutInitWindowSize( 600, 300 );
226 glutInitDisplayMode( GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
|
227 GLUT_DEPTH
| GLUT_MULTISAMPLE
);
228 glutCreateWindow(argv
[0]);
230 glutReshapeFunc( Reshape
);
231 glutKeyboardFunc( Key
);
232 glutDisplayFunc( Display
);
234 glutIdleFunc( Idle
);