Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #ifndef GL_GLEXT_PROTOTYPES
- #define GL_GLEXT_PROTOTYPES
- #endif
- #include <OpenGL/gl.h>
- #include <OpenGL/glu.h>
- #include <OpenGL/glext.h>
- #include <GLUT/glut.h>
- using namespace std;
- unsigned int vbo[2];
- short positions[12] = { 1, -1, 0,
- 1, 1, 0,
- -1, -1, 0,
- -1, 1, 0};
- unsigned short indices[4] = {0,1,2,3};
- static void init ()
- {
- glGenBuffers (2, vbo);
- cout << "Created vbo = " << vbo[0] << ", " << vbo[1] << "\n";
- glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
- glBufferData (GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
- glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
- }
- static void display ()
- {
- glClearColor (0,0,1.f,1.f);
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glEnableClientState (GL_VERTEX_ARRAY);
- // 頂点データ
- glBindBuffer (GL_ARRAY_BUFFER, vbo[0]);
- glVertexPointer (3, GL_SHORT, 0, 0);
- // インデックス
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, vbo[1]);
- //glDrawElements(GL_TRIANGLE_STRIP, sizeof(indices)/sizeof(indices[0]),GL_UNSIGNED_SHORT, 0);
- glDrawElements(GL_POINTS, sizeof(indices)/sizeof(indices[0]),GL_UNSIGNED_SHORT, 0);
- glDisableClientState (GL_VERTEX_ARRAY);
- glutSwapBuffers();
- }
- static void reshape (int w, int h)
- {
- glViewport (0, 0, w, h);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- glOrtho (-2, 2, -2, 2, -2, 2);
- }
- static void keyboard(unsigned char key, int x, int y)
- {
- if (key == 113) {
- exit (0);
- }
- glutPostRedisplay();
- }
- /**
- * メインプログラム
- */
- int main(int argc, char *argv[])
- {
- glutInit (&argc, argv);
- glutInitDisplayMode (GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
- glutCreateWindow (argv[0]);
- glutDisplayFunc (display);
- glutReshapeFunc (reshape);
- init ();
- glutKeyboardFunc (keyboard);
- glutMainLoop ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement