Guest User

Untitled

a guest
Jan 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <windows.h>
  3. #include <GL/glut.h>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. float angle = 0;
  8. float t,s=0.5,m=0;
  9.  
  10. void myinit(void){
  11. glClearColor(1.0,1.0,1.0,0.0);
  12. glMatrixMode(GL_PROJECTION);
  13. glLoadIdentity();
  14. glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
  15. }
  16. void keyboard(unsigned char key, int x, int y){
  17. if(key==27)
  18. {
  19. exit(0);
  20.  
  21. }else if(key == 82 || key == 114){
  22. angle-=0.1;
  23.  
  24. glRotatef(angle,0,0,1);
  25. glutPostRedisplay();
  26.  
  27. }else if(key == 84 || key == 116 )
  28. {
  29. t+=0.01;
  30. glTranslatef(t,0,0);
  31. glutPostRedisplay();
  32. }else if(key == 43){
  33. s+=0.01;
  34.  
  35. // m-=0.1;
  36. // glTranslatef(m,m,0.0);
  37. glScalef(s,s,0);
  38. glutPostRedisplay();
  39. }
  40. (void)(x);
  41. (void)(y);
  42. }
  43. void hut(void){
  44.  
  45. glClear(GL_COLOR_BUFFER_BIT);
  46.  
  47. glBegin(GL_TRIANGLE_FAN);
  48. glVertex3f(0.5,0.4,0.0);
  49. glVertex3f(0.42,0.5,0.0); // GREEN
  50. glVertex3f(0.44,0.5,0.0);
  51. glColor3f(1.5,1.0,0.0);
  52. glVertex3f(0.46,0.5,0.0);
  53. glColor3f(0.25,0.0,0.0);
  54. glVertex3f(0.57,0.5,0.0);
  55. glEnd();
  56. glFlush();
  57.  
  58. glColor3f(1.5,1.0,0.0);
  59. glBegin(GL_TRIANGLE_FAN);
  60. glVertex3f(0.44,0.55,0.0);
  61. glVertex3f(0.42,0.5,0.0);
  62. glVertex3f(0.46,0.5,0.0);
  63. glColor3f(0.25,0.0,0.0);
  64. glVertex3f(0.48,0.55,0.0);
  65. glEnd();
  66.  
  67. glColor3f(1.5,1.0,0.0);
  68. glBegin(GL_TRIANGLE_FAN);
  69. glVertex3f(0.48,0.55,0.0);
  70. glVertex3f(0.46,0.5,0.0);
  71. glVertex3f(0.50,0.5,0.0);
  72. glColor3f(0.25,0.0,0.0);
  73. glVertex3f(0.52,0.55,0.0);
  74. glEnd();
  75.  
  76. glColor3f(1.5,1.0,0.0);
  77. glBegin(GL_TRIANGLE_FAN);
  78. glVertex3f(0.52,0.55,0.0);
  79. glVertex3f(0.50,0.5,0.0);
  80. glVertex3f(0.54,0.5,0.0);
  81. glColor3f(0.25,0.0,0.0);
  82. glVertex3f(0.56,0.55,0.0);
  83. glEnd();
  84. glColor3f(1.5,1.0,0.0);
  85. glBegin(GL_TRIANGLE_FAN);
  86. glVertex3f(0.56,0.55,0.0);
  87. glVertex3f(0.54,0.5,0.0);
  88. glVertex3f(0.57,0.5,0.0);
  89. glEnd();
  90. glFlush();
  91.  
  92. }
  93. int main(int argc,char** argv){
  94. glutInit(&argc,argv);
  95. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  96. glutInitWindowPosition(100,100);
  97. glutInitWindowSize(640,480);
  98. glutCreateWindow("Polygon with viewport");
  99. myinit();
  100. glutDisplayFunc(hut);
  101.  
  102. glutKeyboardFunc(keyboard);
  103. glutMainLoop();
  104.  
  105.  
  106. }
Add Comment
Please, Sign In to add comment