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.

cva.c 3.4KB

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