Advertisement
IcaroPeretti

circleDrawingBase

May 30th, 2021 (edited)
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <GL/glut.h>
  4. #include <math.h>
  5.  
  6. #define PI 3.1415926535898
  7. #define window_height 400
  8. #define window_width 600
  9.  
  10. void display(void);
  11. void tela(GLsizei w, GLsizei h);
  12.  
  13. int main(int argc, char** argv)
  14. {
  15.     glutInit(&argc, argv); //Suporte a janelas
  16.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //padrao de cores
  17.  
  18.     glutInitWindowSize(window_width, window_height); //Tamanho janela
  19.     glutInitWindowPosition(100, 100);
  20.     glutCreateWindow("Push and Pop");
  21.  
  22.     //glutFullScreen();
  23.     glutReshapeFunc(tela);//configurar tela
  24.     glutDisplayFunc(display);
  25.     glutMainLoop(); //redesenhar
  26.  
  27.     return(0);
  28. }
  29.  
  30. void desenhar() {
  31.     GLfloat circ_pnt = 100;
  32.     GLfloat ang, raioX = 80.0f, raioY = 80.0f;
  33.     glColor3f(1.0, 0.0, 0.0);
  34.     glBegin(GL_LINE_LOOP);
  35.     for (int i = 0; i < circ_pnt; i++) {
  36.         ang = (2 * PI * i) / circ_pnt;
  37.         glVertex2f(cos(ang) * raioX, sin(ang) * raioY);
  38.         printf("%f %f\n", cos(ang) * raioX, sin(ang) * raioY);
  39.     }
  40.     glEnd();
  41.  
  42.     glPushMatrix(); //Empilhar e armazenar matriz
  43.  
  44.     glTranslatef(150, 0, 0); //Deslocar matriz
  45.  
  46.     glColor3f(0, 1.0, 0);
  47.     glBegin(GL_QUADS);
  48.     glVertex3f(40.0, 40.0, 0.0);
  49.     glVertex3f(-40.0, 40.0, 0.0);
  50.     glVertex3f(-40.0, -40.0, 0.0);
  51.     glVertex3f(40.0, -40.0, 0.0);
  52.     glEnd();
  53.  
  54.     glPopMatrix(); //Restaurar matriz da pilha
  55.  
  56.     glColor3f(255, 255.0, 0);
  57.     glBegin(GL_QUADS);
  58.     glVertex3f(20.0, 20.0, 0.0);
  59.     glVertex3f(-20.0, 20.0, 0.0);
  60.     glVertex3f(-20.0, -20.0, 0.0);
  61.     glVertex3f(20.0, -20.0, 0.0);
  62.     glEnd();
  63. }
  64.  
  65.  
  66. void display()
  67. {
  68.     glMatrixMode(GL_MODELVIEW); //coordenadas de desenho
  69.     glLoadIdentity();
  70.  
  71.     glClearColor(0, 0, 1, 1); //cor de fundo
  72.     glClear(GL_COLOR_BUFFER_BIT); //Executa limpeza
  73.  
  74.     //Especificar onde o desenho ocorre
  75.     glTranslatef(window_width / 2, window_height / 2, 0);
  76.  
  77.     glViewport(0, 0, window_width, window_height);
  78.     desenhar();
  79.  
  80.     glFlush(); //Executa o desenho
  81. }
  82.  
  83. void tela(GLsizei w, GLsizei h)
  84. {
  85.     glMatrixMode(GL_PROJECTION);
  86.     glLoadIdentity();
  87.  
  88.     //cria janela (esq,direita,em baixo,em cima)
  89.     gluOrtho2D(0, window_width, 0, window_height);
  90.  
  91.     glMatrixMode(GL_MODELVIEW);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement