1 /* $Id: antialias.c,v 1.2 2003/03/29 16:42:57 brianp Exp $ */
4 * Test multisampling and polygon smoothing.
16 static GLfloat Zrot
= 0;
17 static GLboolean Anim
= GL_TRUE
;
18 static GLboolean HaveMultisample
= 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);
89 PrintString("MULTISAMPLE");
91 glRasterPos2f(-0.8, -1.6);
92 PrintString("No antialiasing");
93 glRasterPos2f(1.6, -1.6);
94 PrintString("GL_POLYGON_SMOOTH");
97 if (HaveMultisample
) {
98 glEnable(GL_DEPTH_TEST
);
99 glEnable(GL_MULTISAMPLE_ARB
);
101 glTranslatef(-2.5, 0, 0);
103 glRotatef(Zrot
, 0, 0, 1);
107 glDisable(GL_MULTISAMPLE_ARB
);
108 glDisable(GL_DEPTH_TEST
);
112 glEnable(GL_DEPTH_TEST
);
114 glTranslatef(0, 0, 0);
116 glRotatef(Zrot
, 0, 0, 1);
120 glDisable(GL_DEPTH_TEST
);
123 glEnable(GL_POLYGON_SMOOTH
);
124 glEnable(GL_LINE_SMOOTH
);
127 glTranslatef(2.5, 0, 0);
129 glRotatef(Zrot
, 0, 0, 1);
133 glDisable(GL_LINE_SMOOTH
);
134 glDisable(GL_POLYGON_SMOOTH
);
142 Reshape( int width
, int height
)
144 GLfloat ar
= (float) width
/ (float) height
;
145 glViewport( 0, 0, width
, height
);
146 glMatrixMode( GL_PROJECTION
);
148 glOrtho(-2.0*ar
, 2.0*ar
, -2.0, 2.0, -1.0, 1.0);
149 glMatrixMode( GL_MODELVIEW
);
157 Zrot
= 0.01 * glutGet(GLUT_ELAPSED_TIME
);
163 Key( unsigned char key
, int x
, int y
)
165 const GLfloat step
= 1.0;
177 Zrot
= (int) (Zrot
- step
);
180 Zrot
= (int) (Zrot
+ step
);
193 /* GLUT imposes the four samples/pixel requirement */
195 glGetIntegerv(GL_SAMPLES_ARB
, &s
);
196 if (!glutExtensionSupported("GL_ARB_multisample") || s
< 1) {
197 printf("Warning: multisample antialiasing not supported.\n");
198 HaveMultisample
= GL_FALSE
;
200 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
201 printf("GL_SAMPLES_ARB = %d\n", s
);
203 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
204 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
205 glBlendFunc(GL_SRC_ALPHA_SATURATE
, GL_ONE
);
207 glGetIntegerv(GL_MULTISAMPLE_ARB
, &s
);
208 printf("GL_MULTISAMPLE_ARB = %d\n", s
);
213 main( int argc
, char *argv
[] )
215 glutInit( &argc
, argv
);
216 glutInitWindowPosition( 0, 0 );
217 glutInitWindowSize( 600, 300 );
218 glutInitDisplayMode( GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
|
219 GLUT_DEPTH
| GLUT_MULTISAMPLE
);
220 glutCreateWindow(argv
[0]);
221 glutReshapeFunc( Reshape
);
222 glutKeyboardFunc( Key
);
223 glutDisplayFunc( Display
);
225 glutIdleFunc( Idle
);