Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cva.c 3.3KB

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