Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Test multisampling and polygon smoothing.
  3. *
  4. * Brian Paul
  5. * 4 November 2002
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #include <GL/glew.h>
  11. #include <GL/glut.h>
  12. static GLfloat Zrot = 0;
  13. static GLboolean Anim = GL_TRUE;
  14. static GLboolean HaveMultisample = GL_TRUE;
  15. static GLboolean DoMultisample = GL_TRUE;
  16. static void
  17. PrintString(const char *s)
  18. {
  19. while (*s) {
  20. glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
  21. s++;
  22. }
  23. }
  24. static void
  25. doPolygon( GLint verts, GLfloat radius, GLfloat z )
  26. {
  27. int i;
  28. for (i = 0; i < verts; i++) {
  29. float a = (i * 2.0 * 3.14159) / verts;
  30. float x = radius * cos(a);
  31. float y = radius * sin(a);
  32. glVertex3f(x, y, z);
  33. }
  34. }
  35. static void
  36. DrawObject( void )
  37. {
  38. glLineWidth(3.0);
  39. glColor3f(1, 1, 1);
  40. glBegin(GL_LINE_LOOP);
  41. doPolygon(12, 1.2, 0);
  42. glEnd();
  43. glLineWidth(1.0);
  44. glColor3f(1, 1, 1);
  45. glBegin(GL_LINE_LOOP);
  46. doPolygon(12, 1.1, 0);
  47. glEnd();
  48. glColor3f(1, 0, 0);
  49. glBegin(GL_POLYGON);
  50. doPolygon(12, 0.4, 0.3);
  51. glEnd();
  52. glColor3f(0, 1, 0);
  53. glBegin(GL_POLYGON);
  54. doPolygon(12, 0.6, 0.2);
  55. glEnd();
  56. glColor3f(0, 0, 1);
  57. glBegin(GL_POLYGON);
  58. doPolygon(12, 0.8, 0.1);
  59. glEnd();
  60. glColor3f(1, 1, 1);
  61. glBegin(GL_POLYGON);
  62. doPolygon(12, 1.0, 0);
  63. glEnd();
  64. }
  65. static void
  66. Display( void )
  67. {
  68. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  69. glColor3f(1, 1, 1);
  70. if (HaveMultisample) {
  71. glRasterPos2f(-3.1, -1.6);
  72. if (DoMultisample)
  73. PrintString("MULTISAMPLE");
  74. else
  75. PrintString("MULTISAMPLE (off)");
  76. }
  77. glRasterPos2f(-0.8, -1.6);
  78. PrintString("No antialiasing");
  79. glRasterPos2f(1.6, -1.6);
  80. PrintString("GL_POLYGON_SMOOTH");
  81. /* multisample */
  82. if (HaveMultisample) {
  83. glEnable(GL_DEPTH_TEST);
  84. if (DoMultisample)
  85. glEnable(GL_MULTISAMPLE_ARB);
  86. glPushMatrix();
  87. glTranslatef(-2.5, 0, 0);
  88. glPushMatrix();
  89. glRotatef(Zrot, 0, 0, 1);
  90. DrawObject();
  91. glPopMatrix();
  92. glPopMatrix();
  93. glDisable(GL_MULTISAMPLE_ARB);
  94. glDisable(GL_DEPTH_TEST);
  95. }
  96. /* non-aa */
  97. glEnable(GL_DEPTH_TEST);
  98. glPushMatrix();
  99. glTranslatef(0, 0, 0);
  100. glPushMatrix();
  101. glRotatef(Zrot, 0, 0, 1);
  102. DrawObject();
  103. glPopMatrix();
  104. glPopMatrix();
  105. glDisable(GL_DEPTH_TEST);
  106. /* polygon smooth */
  107. glEnable(GL_POLYGON_SMOOTH);
  108. glEnable(GL_LINE_SMOOTH);
  109. glEnable(GL_BLEND);
  110. glPushMatrix();
  111. glTranslatef(2.5, 0, 0);
  112. glPushMatrix();
  113. glRotatef(Zrot, 0, 0, 1);
  114. DrawObject();
  115. glPopMatrix();
  116. glPopMatrix();
  117. glDisable(GL_LINE_SMOOTH);
  118. glDisable(GL_POLYGON_SMOOTH);
  119. glDisable(GL_BLEND);
  120. glutSwapBuffers();
  121. }
  122. static void
  123. Reshape( int width, int height )
  124. {
  125. GLfloat ar = (float) width / (float) height;
  126. glViewport( 0, 0, width, height );
  127. glMatrixMode( GL_PROJECTION );
  128. glLoadIdentity();
  129. glOrtho(-2.0*ar, 2.0*ar, -2.0, 2.0, -1.0, 1.0);
  130. glMatrixMode( GL_MODELVIEW );
  131. glLoadIdentity();
  132. }
  133. static void
  134. Idle( void )
  135. {
  136. Zrot = 0.01 * glutGet(GLUT_ELAPSED_TIME);
  137. glutPostRedisplay();
  138. }
  139. static void
  140. Key( unsigned char key, int x, int y )
  141. {
  142. const GLfloat step = 1.0;
  143. (void) x;
  144. (void) y;
  145. switch (key) {
  146. case 'a':
  147. Anim = !Anim;
  148. if (Anim)
  149. glutIdleFunc(Idle);
  150. else
  151. glutIdleFunc(NULL);
  152. break;
  153. case 'm':
  154. DoMultisample = !DoMultisample;
  155. break;
  156. case 'z':
  157. Zrot = (int) (Zrot - step);
  158. break;
  159. case 'Z':
  160. Zrot = (int) (Zrot + step);
  161. break;
  162. case 27:
  163. exit(0);
  164. break;
  165. }
  166. glutPostRedisplay();
  167. }
  168. static void
  169. Init( void )
  170. {
  171. /* GLUT imposes the four samples/pixel requirement */
  172. int s;
  173. glGetIntegerv(GL_SAMPLES_ARB, &s);
  174. if (!glutExtensionSupported("GL_ARB_multisample") || s < 1) {
  175. printf("Warning: multisample antialiasing not supported.\n");
  176. HaveMultisample = GL_FALSE;
  177. }
  178. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  179. printf("GL_SAMPLES_ARB = %d\n", s);
  180. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  181. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  182. glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
  183. glGetIntegerv(GL_MULTISAMPLE_ARB, &s);
  184. printf("GL_MULTISAMPLE_ARB = %d\n", s);
  185. }
  186. int
  187. main( int argc, char *argv[] )
  188. {
  189. glutInit( &argc, argv );
  190. glutInitWindowPosition( 0, 0 );
  191. glutInitWindowSize( 600, 300 );
  192. glutInitDisplayMode( GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE |
  193. GLUT_DEPTH | GLUT_MULTISAMPLE );
  194. glutCreateWindow(argv[0]);
  195. glewInit();
  196. glutReshapeFunc( Reshape );
  197. glutKeyboardFunc( Key );
  198. glutDisplayFunc( Display );
  199. if (Anim)
  200. glutIdleFunc( Idle );
  201. Init();
  202. glutMainLoop();
  203. return 0;
  204. }