Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <gl/glut.h>
  3. GLfloat angle, fAspect;
  4. // Função callback chamada para fazer o desenho
  5. void Desenha(void)
  6. {
  7. // Limpa a janela e o depth buffer
  8. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  9. // Especifica sistema de coordenadas de projeção
  10. glMatrixMode(GL_PROJECTION);
  11. glLoadIdentity();
  12. gluPerspective(angle, fAspect, 0.4, 500);
  13. // Especifica sistema de coordenadas do modelo
  14. glMatrixMode(GL_MODELVIEW);
  15. glLoadIdentity();
  16. gluLookAt(0, 250, 300, 0, 0, 0, 0, 1, 0);
  17. // Desenha o teapot com a cor corrente (solid)
  18. glColor3f(0.6f, 0.4f, 0.1f);
  19. glutSolidTeapot(50.0f);
  20. glutSwapBuffers();
  21. }
  22. // Inicializa parâmetros de iluminação
  23. void Inicializa(void)
  24. {
  25. GLfloat luzAmbiente[4] = { 0.2,0.2,0.2,1.0 };
  26. GLfloat luzDifusa[4] = { 0.7,0.7,0.7,1.0 }; // "cor"
  27. GLfloat luzEspecular[4] = { 1.0, 1.0, 1.0, 1.0 };// "brilho"
  28. GLfloat posicaoLuz[4] = { 0.0, 50.0, 50.0, 1.0 };
  29. // Capacidade de brilho do material
  30. GLfloat especularidade[4] = { 1.0,1.0,1.0,1.0 };
  31. GLint especMaterial = 60;
  32. // Especifica que a cor de fundo da janela será preta
  33. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  34. // Habilita o modelo de colorização de Gouraud
  35. glShadeModel(GL_SMOOTH);
  36. // Define a refletância do material
  37. glMaterialfv(GL_FRONT, GL_SPECULAR, especularidade);
  38. // Define a concentração do brilho
  39. glMateriali(GL_FRONT, GL_SHININESS, especMaterial);
  40. // Ativa o uso da luz ambiente
  41. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, luzAmbiente);
  42. // Define os parâmetros da luz de número 0
  43. glLightfv(GL_LIGHT0, GL_AMBIENT, luzAmbiente);
  44. glLightfv(GL_LIGHT0, GL_DIFFUSE, luzDifusa);
  45. glLightfv(GL_LIGHT0, GL_SPECULAR, luzEspecular);
  46. glLightfv(GL_LIGHT0, GL_POSITION, posicaoLuz);
  47. // Habilita a definição da cor do material a partir da cor
  48. // corrente
  49. glEnable(GL_COLOR_MATERIAL);
  50. //Habilita o uso de iluminação
  51. glEnable(GL_LIGHTING);
  52. // Habilita a luz de número 0
  53. glEnable(GL_LIGHT0);
  54. // Habilita o depth-buffering
  55. glEnable(GL_DEPTH_TEST);
  56. angle = 45;
  57. }
  58. // Função callback chamada quando o tamanho da janela é alterado
  59. void AlteraTamanhoJanela(GLsizei w, GLsizei h)
  60. {
  61. // Para previnir uma divisão por zero
  62. if (h == 0) h = 1;
  63. // Especifica o tamanho da viewport
  64. glViewport(0, 0, w, h);
  65. // Calcula a correção de aspecto
  66. fAspect = (GLfloat)w / (GLfloat)h;
  67. glutPostRedisplay();
  68. }
  69. // Função callback chamada para gerenciar eventos do mouse
  70. void GerenciaMouse(int button, int state, int x, int y)
  71. {
  72. if (button == GLUT_LEFT_BUTTON)
  73. if (state == GLUT_DOWN) { // Zoom-in
  74. if (angle >= 10) angle -= 5;
  75. }
  76. if (button == GLUT_RIGHT_BUTTON)
  77. if (state == GLUT_DOWN) { // Zoom-out
  78. if (angle <= 130) angle += 5;
  79. }
  80. glutPostRedisplay();
  81. }
  82. // Programa Principal
  83. int main(int argc, char** argv)
  84. {
  85. glutInit(&argc, argv);
  86. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  87. glutInitWindowSize(400, 350);
  88. glutCreateWindow("Bule Iluminado");
  89. glutDisplayFunc(Desenha);
  90. glutReshapeFunc(AlteraTamanhoJanela);
  91. glutMouseFunc(GerenciaMouse);
  92. Inicializa();
  93. glutMainLoop();
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement