IcaroPeretti

ComGraficaTemplate

May 15th, 2021
519
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <GL/glut.h>
  3. #include <math.h>
  4. #define WINDOW_HEIGHT 400
  5. #define WINDOW_WIDTH 400
  6.  
  7. void keyboard(unsigned char key, int x, int y);
  8. void resize(GLsizei w, GLsizei h);
  9. void display(void);
  10. void house(void);
  11. void door(void);
  12. void roof(void);
  13. void floor(void);
  14. void window(void);
  15. void point(void);
  16.  
  17. int main(int argc, char** argv) {
  18.   // controla se o sistema operacional tem suporte a janelas
  19.   glutInit(&argc, argv);
  20.  
  21.   // quantidade de buffer de cores e que padrão de cores é RGB ou RGBA
  22.   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  23.  
  24.   // tamanho da janela
  25.   glutInitWindowSize(400, 400);
  26.  
  27.   // posicao inicial da janela
  28.   glutInitWindowPosition(WINDOW_HEIGHT, WINDOW_WIDTH);
  29.  
  30.   // cria janela
  31.   glutCreateWindow("GLUT Test Vinicius ---- exercicio glut");
  32.  
  33.   glutKeyboardFunc(&keyboard);
  34.  
  35.   glutReshapeFunc(&resize);
  36.  
  37.   glutDisplayFunc(display);
  38.  
  39.   glutMainLoop();
  40.  
  41.   return EXIT_SUCCESS;
  42. }
  43.  
  44. void keyboard(unsigned char key, int x, int y) {
  45.   switch (key) {
  46.   case '\x1b':
  47.     exit(EXIT_SUCCESS);
  48.     break;
  49.   }
  50. }
  51.  
  52. void resize(GLsizei w, GLsizei h) {
  53.   // evite divisao por zero
  54.   if (h == 0)
  55.     h = 1;
  56.   // Especifica as dimensões do Viewport
  57.   glViewport(0, 0, w, h);
  58.  
  59.   // inicializa os sistemas de cordernadas
  60.   glMatrixMode(GL_PROJECTION);
  61.   // limpa memoria
  62.   glLoadIdentity();
  63.  
  64.   if (w <= h) {
  65.     gluOrtho2D(0.0f, WINDOW_HEIGHT, 0.0f, WINDOW_WIDTH * h / w);
  66.   } else {
  67.     gluOrtho2D(0.0f, WINDOW_HEIGHT * w / h, 0.0f, WINDOW_WIDTH);
  68.   }
  69.   glMatrixMode(GL_MODELVIEW);
  70. }
  71.  
  72. void display() {
  73.   glMatrixMode(GL_MODELVIEW);
  74.   // LIMPAR toda a matriz
  75.   glLoadIdentity();
  76.   // cor de fundo
  77.   glClearColor(0, 0, 1, 1);
  78.   // limpa a tela com a cor de fundo
  79.   glClear(GL_COLOR_BUFFER_BIT);
  80.    
  81.   //centralizar plano cartesiano
  82.   glTranslatef(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 0);
  83.  
  84.   glBegin(GL_QUADS);
  85.   glColor3f(255.0, 255.0, 0.0);
  86.   glVertex2f(-100, -100);
  87.   glVertex2f(-100, 100);
  88.   glVertex2f(100, 100);
  89.   glVertex2f(100, -100);
  90.   glEnd();
  91.  
  92.   glFlush();
  93. }
RAW Paste Data