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.

vbo-drawrange.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Basic VBO */
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <GL/glew.h>
  8. #include <GL/glut.h>
  9. #define ELTOBJ 0
  10. struct {
  11. GLfloat pos[3];
  12. GLubyte color[4];
  13. } verts[] =
  14. {
  15. { { 0.9, -0.9, 0.0 },
  16. { 0x00, 0x00, 0xff, 0x00 }
  17. },
  18. { { 0.9, 0.9, 0.0 },
  19. { 0x00, 0xff, 0x00, 0x00 }
  20. },
  21. { { -0.9, 0.9, 0.0 },
  22. { 0xff, 0x00, 0x00, 0x00 }
  23. },
  24. { { -0.9, -0.9, 0.0 },
  25. { 0xff, 0xff, 0xff, 0x00 }
  26. },
  27. };
  28. GLuint indices[] = { 1, 2, 3 };
  29. GLuint arrayObj, elementObj;
  30. static void Init( void )
  31. {
  32. GLint errno;
  33. GLuint prognum;
  34. static const char *prog1 =
  35. "!!ARBvp1.0\n"
  36. "MOV result.color, vertex.color;\n"
  37. "MOV result.position, vertex.position;\n"
  38. "END\n";
  39. glGenProgramsARB(1, &prognum);
  40. glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
  41. glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  42. strlen(prog1), (const GLubyte *) prog1);
  43. assert(glIsProgramARB(prognum));
  44. errno = glGetError();
  45. printf("glGetError = %d\n", errno);
  46. if (errno != GL_NO_ERROR)
  47. {
  48. GLint errorpos;
  49. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  50. printf("errorpos: %d\n", errorpos);
  51. printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  52. }
  53. glEnableClientState( GL_VERTEX_ARRAY );
  54. glEnableClientState( GL_COLOR_ARRAY );
  55. glGenBuffersARB(1, &arrayObj);
  56. glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
  57. glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);
  58. #if ELTOBJ
  59. glGenBuffersARB(1, &elementObj);
  60. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, elementObj);
  61. glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(indices), indices, GL_STATIC_DRAW_ARB);
  62. #endif
  63. glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), 0 );
  64. glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(verts[0]), (void *)(3*sizeof(float)) );
  65. }
  66. static void Display( void )
  67. {
  68. glClearColor(0.3, 0.3, 0.3, 1);
  69. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  70. glEnable(GL_VERTEX_PROGRAM_ARB);
  71. #if ELTOBJ
  72. glDrawRangeElements( GL_TRIANGLES, 1, 3, 3, GL_UNSIGNED_INT, NULL );
  73. #else
  74. glDrawRangeElements( GL_TRIANGLES, 1, 3, 3, GL_UNSIGNED_INT, indices );
  75. #endif
  76. glFlush();
  77. }
  78. static void Reshape( int width, int height )
  79. {
  80. glViewport( 0, 0, width, height );
  81. glMatrixMode( GL_PROJECTION );
  82. glLoadIdentity();
  83. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  84. glMatrixMode( GL_MODELVIEW );
  85. glLoadIdentity();
  86. /*glTranslatef( 0.0, 0.0, -15.0 );*/
  87. }
  88. static void Key( unsigned char key, int x, int y )
  89. {
  90. (void) x;
  91. (void) y;
  92. switch (key) {
  93. case 27:
  94. exit(0);
  95. break;
  96. }
  97. glutPostRedisplay();
  98. }
  99. int main( int argc, char *argv[] )
  100. {
  101. glutInit( &argc, argv );
  102. glutInitWindowPosition( 0, 0 );
  103. glutInitWindowSize( 250, 250 );
  104. glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
  105. glutCreateWindow(argv[0]);
  106. glewInit();
  107. glutReshapeFunc( Reshape );
  108. glutKeyboardFunc( Key );
  109. glutDisplayFunc( Display );
  110. Init();
  111. glutMainLoop();
  112. return 0;
  113. }