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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* $Id: cva.c,v 1.4 2002/01/16 01:03:25 kschultz Exp $ */
  2. /*
  3. * Trivial CVA test, good for testing driver fastpaths (especially
  4. * indexed vertex buffers if they are supported).
  5. *
  6. * Gareth Hughes
  7. * November 2000
  8. */
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #ifdef _WIN32
  13. #include <windows.h>
  14. #endif
  15. #define GL_GLEXT_LEGACY
  16. #include <GL/glut.h>
  17. GLfloat verts[][4] = {
  18. { -0.5, -0.5, -2.0, 0.0 },
  19. { 0.5, -0.5, -2.0, 0.0 },
  20. { -0.5, 0.5, -2.0, 0.0 },
  21. { 0.5, 0.5, -2.0, 0.0 },
  22. };
  23. GLubyte color[][4] = {
  24. { 0xff, 0x00, 0x00, 0x00 },
  25. { 0x00, 0xff, 0x00, 0x00 },
  26. { 0x00, 0x00, 0xff, 0x00 },
  27. { 0xff, 0xff, 0xff, 0x00 },
  28. };
  29. GLuint indices[] = { 0, 1, 2, 3 };
  30. GLboolean compiled = GL_TRUE;
  31. GLboolean doubleBuffer = GL_TRUE;
  32. void init( void )
  33. {
  34. glClearColor( 0.0, 0.0, 0.0, 0.0 );
  35. glShadeModel( GL_SMOOTH );
  36. glFrontFace( GL_CCW );
  37. glCullFace( GL_BACK );
  38. glEnable( GL_CULL_FACE );
  39. glEnable( GL_DEPTH_TEST );
  40. glEnableClientState( GL_VERTEX_ARRAY );
  41. glEnableClientState( GL_COLOR_ARRAY );
  42. glMatrixMode( GL_PROJECTION );
  43. glLoadIdentity();
  44. glFrustum( -1.0, 1.0, -1.0, 1.0, 2.0, 10.0 );
  45. glMatrixMode( GL_MODELVIEW );
  46. glLoadIdentity();
  47. glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts );
  48. glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
  49. #ifdef GL_EXT_compiled_vertex_array
  50. if ( compiled ) {
  51. glLockArraysEXT( 0, 4 );
  52. }
  53. #endif
  54. }
  55. void display( void )
  56. {
  57. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  58. glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
  59. glFlush();
  60. if ( doubleBuffer ) {
  61. glutSwapBuffers();
  62. }
  63. }
  64. void keyboard( unsigned char key, int x, int y )
  65. {
  66. switch ( key ) {
  67. case 27:
  68. exit( 0 );
  69. break;
  70. }
  71. glutPostRedisplay();
  72. }
  73. GLboolean args( int argc, char **argv )
  74. {
  75. GLint i;
  76. doubleBuffer = GL_TRUE;
  77. for ( i = 1 ; i < argc ; i++ ) {
  78. if ( strcmp( argv[i], "-sb" ) == 0 ) {
  79. doubleBuffer = GL_FALSE;
  80. } else if ( strcmp( argv[i], "-db" ) == 0 ) {
  81. doubleBuffer = GL_TRUE;
  82. } else {
  83. fprintf( stderr, "%s (Bad option).\n", argv[i] );
  84. return GL_FALSE;
  85. }
  86. }
  87. return GL_TRUE;
  88. }
  89. int main( int argc, char **argv )
  90. {
  91. GLenum type;
  92. char *string;
  93. glutInit( &argc, argv );
  94. if ( args( argc, argv ) == GL_FALSE ) {
  95. exit( 1 );
  96. }
  97. type = GLUT_RGB | GLUT_DEPTH;
  98. type |= ( doubleBuffer ) ? GLUT_DOUBLE : GLUT_SINGLE;
  99. glutInitDisplayMode( type );
  100. glutInitWindowSize( 250, 250 );
  101. glutInitWindowPosition( 100, 100 );
  102. glutCreateWindow( "CVA Test" );
  103. /* Make sure the server supports GL 1.2 vertex arrays.
  104. */
  105. string = (char *) glGetString( GL_VERSION );
  106. if ( (!strstr( string, "1.2" ))&&(!strstr(string,"1.3"))) {
  107. fprintf( stderr, "This program requires OpenGL 1.2 vertex arrays.\n" );
  108. exit( -1 );
  109. }
  110. /* See if the server supports compiled vertex arrays.
  111. */
  112. string = (char *) glGetString( GL_EXTENSIONS );
  113. if ( !strstr( string, "GL_EXT_compiled_vertex_array" ) ) {
  114. fprintf( stderr, "Compiled vertex arrays not supported by this renderer.\n" );
  115. compiled = GL_FALSE;
  116. }
  117. init();
  118. glutDisplayFunc( display );
  119. glutKeyboardFunc( keyboard );
  120. glutMainLoop();
  121. return 0;
  122. }