Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OpenGL/OpenGL.h>
- #include <GLUT/glut.h>
- #include <iostream>
- #include <vector>
- using namespace std;
- const float width= 800, height=600;
- vector<GLfloat> data;
- GLuint buffer;
- void init(void)
- {
- glEnable(GL_DEPTH_TEST);
- glViewport(0,0,width,height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, width/height , 1.0, 1000.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0, 0.0, 100.0, width/2, height/2, 0.0, 0.0, 1.0, 0.0);
- data= vector<GLfloat> {
- width/2+20,height/2+20,0.0,
- width/2+20,height/2-20,0.0,
- width/2-20, height/2-20,0.0,
- width/2-20, height/2+20,0.0
- };
- glGenBuffers(1, &buffer);
- glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glBufferData(GL_ARRAY_BUFFER, 12*sizeof(GLfloat), data.data(), GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- void display(void)
- {
- glClearColor(1.0, 1.0, 1.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColor3f(1, 0, 0);
- glBindBuffer(GL_ARRAY_BUFFER, buffer);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, data.data());
- glDrawArrays(GL_QUADS, 0, 4);
- glDisableClientState(GL_VERTEX_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glutSwapBuffers();
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(width,height);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("Interaction");
- glutDisplayFunc(display);
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement