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-tri.c 2.7KB

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