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.

drawarrays.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Basic VBO */
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #define GL_GLEXT_PROTOTYPES
  8. #include <GL/glut.h>
  9. struct {
  10. GLfloat pos[3];
  11. GLubyte color[4];
  12. } verts[] =
  13. {
  14. { { 0.9, -0.9, 0.0 },
  15. { 0x00, 0x00, 0xff, 0x00 }
  16. },
  17. { { 0.9, 0.9, 0.0 },
  18. { 0x00, 0xff, 0x00, 0x00 }
  19. },
  20. { { -0.9, 0.9, 0.0 },
  21. { 0xff, 0x00, 0x00, 0x00 }
  22. },
  23. { { -0.9, -0.9, 0.0 },
  24. { 0xff, 0xff, 0xff, 0x00 }
  25. },
  26. };
  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. glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts[0].pos );
  53. glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(verts[0]), verts[0].color );
  54. }
  55. static void Display( void )
  56. {
  57. glClearColor(0.3, 0.3, 0.3, 1);
  58. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  59. glEnable(GL_VERTEX_PROGRAM_ARB);
  60. // glDrawArrays( GL_TRIANGLES, 0, 3 );
  61. glDrawArrays( GL_TRIANGLES, 1, 3 );
  62. glFlush();
  63. }
  64. static void Reshape( int width, int height )
  65. {
  66. glViewport( 0, 0, width, height );
  67. glMatrixMode( GL_PROJECTION );
  68. glLoadIdentity();
  69. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  70. glMatrixMode( GL_MODELVIEW );
  71. glLoadIdentity();
  72. /*glTranslatef( 0.0, 0.0, -15.0 );*/
  73. }
  74. static void Key( unsigned char key, int x, int y )
  75. {
  76. (void) x;
  77. (void) y;
  78. switch (key) {
  79. case 27:
  80. exit(0);
  81. break;
  82. }
  83. glutPostRedisplay();
  84. }
  85. int main( int argc, char *argv[] )
  86. {
  87. glutInit( &argc, argv );
  88. glutInitWindowPosition( 0, 0 );
  89. glutInitWindowSize( 250, 250 );
  90. glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
  91. glutCreateWindow(argv[0]);
  92. glutReshapeFunc( Reshape );
  93. glutKeyboardFunc( Key );
  94. glutDisplayFunc( Display );
  95. Init();
  96. glutMainLoop();
  97. return 0;
  98. }