Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. /*
  2. -----------------------------------------------------------------------------
  3. OpenGL Tutorial
  4. VOXAR Labs
  5. Computer Science Center - CIn
  6. Federal University of Pernambuco - UFPE
  7. http://www.cin.ufpe.br/~voxarlabs
  8.  
  9. -----------------------------------------------------------------------------
  10. */
  11.  
  12. #include "openGL_tutorial.h"
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. /*
  16. http://www.inf.pucrs.br/~manssour/OpenGL/Tutorial.html
  17. esse link!!!!
  18. nãoo vou parar aquui pra mostrar mais coisas de C/C++ hj..
  19. */
  20. /////////////////////////////////////////////////////////////////////////////
  21.  
  22.  
  23. #include <iostream>
  24. #include <vector>
  25.  
  26. const int WINDOW_W = 500;
  27. const int WINDOW_H = 500;
  28.  
  29. using namespace std;
  30.  
  31. class Ponto
  32. {
  33. public:
  34. float x, y;
  35. Ponto(float x, float y) : x(x), y(y) {};
  36.  
  37. };
  38.  
  39. vector <Ponto> pontos;
  40.  
  41. void display()
  42. {
  43. glClear(GL_COLOR_BUFFER_BIT);
  44. glLoadIdentity();
  45.  
  46. if (pontos.size() > 0)
  47. {
  48. glPointSize(5.0f);
  49. glBegin(GL_POINTS);
  50. glColor3f(1.0f, 1.0f, 0.0f);
  51. for (int i = 0; i < pontos.size(); i++)
  52. glVertex2d(pontos.at(i).x, pontos.at(i).y);
  53.  
  54. glEnd();
  55.  
  56. glBegin(GL_LINE_STRIP);
  57. glColor3f(1.0f, 1.0f, 1.0f);
  58. for (int i = 0; i < pontos.size(); i++)
  59. glVertex2d(pontos.at(i).x, pontos.at(i).y);
  60. glEnd();
  61. }
  62.  
  63. glFlush();
  64. }
  65.  
  66. void reshape(int w, int h)
  67. {
  68. glViewport(0, 0, (GLsizei)w, (GLsizei)h);
  69.  
  70. glMatrixMode(GL_PROJECTION);
  71. glLoadIdentity();
  72. glOrtho(0.0f, WINDOW_W, WINDOW_H, 0.0f, -5.0, 5.0);
  73. glMatrixMode(GL_MODELVIEW);
  74. glLoadIdentity();
  75. }
  76.  
  77. void handleKeypress(unsigned char key, int x, int y)
  78. {
  79. static int x1 = 0;
  80. switch (key){
  81. case 27: // ESC
  82. exit(0);
  83. break;
  84. case 119:
  85. glLineWidth(5.0f);
  86. pontos.push_back(Ponto(x, y));
  87. glutPostRedisplay();
  88. x1++;
  89. break;
  90. }
  91.  
  92. }
  93.  
  94. void handleMouseClick(int button, int state, int x, int y)
  95. {
  96. if (button == GLUT_LEFT_BUTTON)
  97. if (state == GLUT_DOWN)
  98. pontos.push_back(Ponto(x, y));
  99.  
  100. glutPostRedisplay(); // avisa que a janela atual deve ser reimpressa
  101. }
  102.  
  103. int main(int argc, char ** argv)
  104. {
  105. glutInit(&argc, argv);
  106. glutInitWindowPosition(0, 0); // a janela irá iniciar to topo esquerdo
  107. glutInitWindowSize(WINDOW_W, WINDOW_H);
  108. glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
  109.  
  110. glutCreateWindow("Exemplo OpenGL");
  111. glMatrixMode(GL_MODELVIEW); // estou alterando a matrix de do modelo da cena
  112. glLoadIdentity();
  113.  
  114. glutDisplayFunc(display);
  115. glutKeyboardFunc(handleKeypress);
  116. glutMouseFunc(handleMouseClick);
  117. glutReshapeFunc(reshape);
  118.  
  119. glutMainLoop();
  120.  
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement