Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -----------------------------------------------------------------------------
- OpenGL Tutorial
- VOXAR Labs
- Computer Science Center - CIn
- Federal University of Pernambuco - UFPE
- http://www.cin.ufpe.br/~voxarlabs
- -----------------------------------------------------------------------------
- */
- #include "openGL_tutorial.h"
- /////////////////////////////////////////////////////////////////////////////
- /*
- http://www.inf.pucrs.br/~manssour/OpenGL/Tutorial.html
- esse link!!!!
- nãoo vou parar aquui pra mostrar mais coisas de C/C++ hj..
- */
- /////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <vector>
- const int WINDOW_W = 500;
- const int WINDOW_H = 500;
- using namespace std;
- class Ponto
- {
- public:
- float x, y;
- Ponto(float x, float y) : x(x), y(y) {};
- };
- vector <Ponto> pontos;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- if (pontos.size() > 0)
- {
- glPointSize(5.0f);
- glBegin(GL_POINTS);
- glColor3f(1.0f, 1.0f, 0.0f);
- for (int i = 0; i < pontos.size(); i++)
- glVertex2d(pontos.at(i).x, pontos.at(i).y);
- glEnd();
- glBegin(GL_LINE_STRIP);
- glColor3f(1.0f, 1.0f, 1.0f);
- for (int i = 0; i < pontos.size(); i++)
- glVertex2d(pontos.at(i).x, pontos.at(i).y);
- glEnd();
- }
- glFlush();
- }
- void reshape(int w, int h)
- {
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0f, WINDOW_W, WINDOW_H, 0.0f, -5.0, 5.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void handleKeypress(unsigned char key, int x, int y)
- {
- static int x1 = 0;
- switch (key){
- case 27: // ESC
- exit(0);
- break;
- case 119:
- glLineWidth(5.0f);
- pontos.push_back(Ponto(x, y));
- glutPostRedisplay();
- x1++;
- break;
- }
- }
- void handleMouseClick(int button, int state, int x, int y)
- {
- if (button == GLUT_LEFT_BUTTON)
- if (state == GLUT_DOWN)
- pontos.push_back(Ponto(x, y));
- glutPostRedisplay(); // avisa que a janela atual deve ser reimpressa
- }
- int main(int argc, char ** argv)
- {
- glutInit(&argc, argv);
- glutInitWindowPosition(0, 0); // a janela irá iniciar to topo esquerdo
- glutInitWindowSize(WINDOW_W, WINDOW_H);
- glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
- glutCreateWindow("Exemplo OpenGL");
- glMatrixMode(GL_MODELVIEW); // estou alterando a matrix de do modelo da cena
- glLoadIdentity();
- glutDisplayFunc(display);
- glutKeyboardFunc(handleKeypress);
- glutMouseFunc(handleMouseClick);
- glutReshapeFunc(reshape);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement