Advertisement
Kojima0502

openGL_PBO

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