3 * Test multisampling and polygon smoothing.
12 #include <glad/glad.h>
13 #include "glut_wrap.h"
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( GLenum mode
, GLint verts
, GLfloat radius
, GLfloat z
)
37 for (i
= 0; i
< verts
; i
++) {
38 float a
= (i
* 2.0 * 3.14159) / verts
;
39 float x
= radius
* cos(a
);
40 float y
= radius
* sin(a
);
52 doPolygon(GL_LINE_LOOP
, 12, 1.2, 0);
56 doPolygon(GL_LINE_LOOP
, 12, 1.1, 0);
59 doPolygon(GL_POLYGON
, 12, 0.4, 0.3);
62 doPolygon(GL_POLYGON
, 12, 0.6, 0.2);
65 doPolygon(GL_POLYGON
, 12, 0.8, 0.1);
68 doPolygon(GL_POLYGON
, 12, 1.0, 0);
75 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
79 glRasterPos2f(-3.1, -1.6);
80 PrintString("No antialiasing");
82 glRasterPos2f(-0.8, -1.6);
83 if (HaveMultisample
) {
85 PrintString(" MULTISAMPLE");
87 PrintString("MULTISAMPLE (off)");
90 PrintString("MULTISAMPLE (N/A)");
92 glRasterPos2f(1.6, -1.6);
93 PrintString("GL_POLYGON_SMOOTH");
96 glEnable(GL_DEPTH_TEST
);
98 glTranslatef(-2.5, 0, 0);
100 glRotatef(Zrot
, 0, 0, 1);
104 glDisable(GL_DEPTH_TEST
);
107 glEnable(GL_DEPTH_TEST
);
108 if (HaveMultisample
&& DoMultisample
)
109 glEnable(GL_MULTISAMPLE_ARB
);
111 glTranslatef(0, 0, 0);
113 glRotatef(Zrot
, 0, 0, 1);
117 glDisable(GL_MULTISAMPLE_ARB
);
118 glDisable(GL_DEPTH_TEST
);
121 glEnable(GL_POLYGON_SMOOTH
);
122 glEnable(GL_LINE_SMOOTH
);
125 glTranslatef(2.5, 0, 0);
127 glRotatef(Zrot
, 0, 0, 1);
131 glDisable(GL_LINE_SMOOTH
);
132 glDisable(GL_POLYGON_SMOOTH
);
140 Reshape( int width
, int height
)
142 GLfloat ar
= (float) width
/ (float) height
;
143 glViewport( 0, 0, width
, height
);
144 glMatrixMode( GL_PROJECTION
);
146 glOrtho(-2.0*ar
, 2.0*ar
, -2.0, 2.0, -1.0, 1.0);
147 glMatrixMode( GL_MODELVIEW
);
155 Zrot
= 0.01 * glutGet(GLUT_ELAPSED_TIME
);
161 Key( unsigned char key
, int x
, int y
)
163 const GLfloat step
= 1.0;
175 DoMultisample
= !DoMultisample
;
178 Zrot
= (int) (Zrot
- step
);
181 Zrot
= (int) (Zrot
+ step
);
194 /* GLUT imposes the four samples/pixel requirement */
196 glGetIntegerv(GL_SAMPLES_ARB
, &s
);
197 if (!glutExtensionSupported("GL_ARB_multisample") || s
< 1) {
198 printf("Warning: multisample antialiasing not supported.\n");
199 HaveMultisample
= GL_FALSE
;
201 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
202 printf("GL_SAMPLES_ARB = %d\n", s
);
204 glBlendFunc(GL_SRC_ALPHA
, GL_ONE
);
205 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
206 glBlendFunc(GL_SRC_ALPHA_SATURATE
, GL_ONE
);
208 glGetIntegerv(GL_MULTISAMPLE_ARB
, &s
);
209 printf("GL_MULTISAMPLE_ARB = %d\n", s
);
214 main( int argc
, char *argv
[] )
216 glutInit( &argc
, argv
);
217 glutInitWindowPosition( 0, 0 );
218 glutInitWindowSize( 600, 300 );
219 glutInitDisplayMode( GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
|
220 GLUT_DEPTH
| GLUT_MULTISAMPLE
);
221 glutCreateWindow(argv
[0]);
223 glutReshapeFunc( Reshape
);
224 glutKeyboardFunc( Key
);
225 glutDisplayFunc( Display
);
227 glutIdleFunc( Idle
);