ait-survey

GL_TRIANGLE_STRIP-linux

Nov 4th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #ifndef GL_GLEXT_PROTOTYPES
  4. #define GL_GLEXT_PROTOTYPES
  5. #endif
  6. #include <GL/gl.h>
  7. #include <GL/glu.h>
  8. #include <GL/glext.h>
  9. #include <GL/glut.h>
  10. using namespace std;
  11.  
  12.  
  13. unsigned int   vbo[2];
  14. short          positions[12] = { 1, -1, 0,
  15.                                  1,  1, 0,
  16.                                 -1, -1, 0,
  17.                                 -1,  1, 0};
  18. unsigned short indices[4]  = {0,1,2,3};
  19.  
  20. static void init ()
  21. {
  22.     glGenBuffers (2, vbo);
  23.     cout << "Created vbo = " << vbo[0] << ", " << vbo[1] << "\n";
  24.     glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
  25.     glBufferData (GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
  26.     glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
  27.     glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
  28. }
  29.  
  30. static void display ()
  31. {
  32.     glClearColor (0,0,1.f,1.f);
  33.     glClear      (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  34.  
  35.     glMatrixMode(GL_MODELVIEW);
  36.     glLoadIdentity();
  37.  
  38.     glEnableClientState  (GL_VERTEX_ARRAY);
  39.  
  40.     // 頂点データ
  41.     glBindBuffer         (GL_ARRAY_BUFFER, vbo[0]);
  42.     glVertexPointer      (3, GL_SHORT, 0, 0);
  43.  
  44.     // インデックス
  45.     glBindBuffer         (GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
  46.     glDrawElements       (GL_TRIANGLE_STRIP, sizeof(indices)/sizeof(indices[0]), GL_UNSIGNED_SHORT, 0);
  47.    
  48.     glDisableClientState (GL_VERTEX_ARRAY);
  49.  
  50.     glutSwapBuffers();
  51. }
  52.  
  53. static void reshape (int w, int h)
  54. {
  55.     glViewport     (0, 0, w, h);
  56.     glMatrixMode   (GL_PROJECTION);
  57.     glLoadIdentity ();
  58.     glOrtho        (-2, 2, -2, 2, -2, 2);
  59. }
  60.  
  61.  
  62. static void keyboard(unsigned char key, int x, int y)
  63. {
  64.     if (key == 113) {
  65.         exit (0);
  66.     }
  67.     glutPostRedisplay();
  68. }
  69.  
  70. /**
  71.  * メインプログラム
  72.  */
  73. int main(int argc, char *argv[])
  74. {
  75.     glutInit            (&argc, argv);
  76.     glutInitDisplayMode (GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
  77.     glutCreateWindow    (argv[0]);
  78.     glutDisplayFunc     (display);
  79.     glutReshapeFunc     (reshape);
  80.  
  81.     init ();
  82.  
  83.     glutKeyboardFunc   (keyboard);
  84.     glutMainLoop       ();
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment