Advertisement
salmancreation

Lab 2 GL

May 26th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. #include<Windows.h> // for MS Windows
  3. #include<GL\glut.h> // GLUT, include glu.h and gl.h
  4. //Note: GLglut.h path depending on the system in use
  5. void init()
  6. {
  7. // Set display window color to as glClearColor(R,G,B,Alpha)
  8. glClearColor(1.6, 1.9, 0.4, 0.0);
  9. // Set projection parameters.
  10. glMatrixMode(GL_PROJECTION);
  11. // Set 2D Transformation as gluOrtho2D(Min Width, Max Width, Min Height, Max Height)
  12. gluOrtho2D(1.0, 800, 0.0, 600);
  13. }
  14. void home()
  15. {
  16. //Roof
  17. glClear(GL_COLOR_BUFFER_BIT); // Clear display window
  18. // Set line segment color as glColor3f(R,G,B)
  19. glColor3f(1.3, 0.5, 0.8);
  20. glBegin(GL_POLYGON);
  21. glVertex2i(200, 500);
  22. glVertex2i(600, 500);
  23. glVertex2i(700, 350);
  24. glVertex2i(300, 350);
  25. glEnd();
  26. // Top of Front Wall
  27. glColor3f(0.1, 0.5, 0.0);
  28. glBegin(GL_TRIANGLES);
  29. glVertex2i(200, 500);
  30. glVertex2i(100, 350);
  31. glVertex2i(300, 350);
  32. glEnd();
  33. // Front Wall
  34. glColor3f(0.7, 0.2, 0.3);
  35. glBegin(GL_POLYGON);
  36. glVertex2i(100, 350);
  37. glVertex2i(300, 350);
  38. glVertex2i(300, 100);
  39. glVertex2i(100, 100);
  40. glEnd();
  41. // Front Door
  42. glColor3f(0.7, 0.2, 0.9);
  43. glBegin(GL_POLYGON);
  44. glVertex2i(150, 250);
  45. glVertex2i(250, 250);
  46. glVertex2i(250, 100);
  47. glVertex2i(150, 100);
  48. glEnd();
  49.  
  50.  
  51.  
  52. //side Wall
  53. glColor3f(0.1, 0.2, 0.3);
  54. glBegin(GL_POLYGON);
  55. glVertex2i(300, 350);
  56. glVertex2i(700, 350);
  57. glVertex2i(700, 100);
  58. glVertex2i(300, 100);
  59. glEnd();
  60. // window one
  61. glColor3f(0.2, 0.4, 0.3);
  62. glBegin(GL_POLYGON);
  63. glVertex2i(330, 320);
  64. glVertex2i(450, 320);
  65. glVertex2i(450, 230);
  66. glVertex2i(330, 230);
  67. glEnd();
  68. // line of window one
  69. glColor3f(0.1, 0.7, 0.5);
  70. glLineWidth(5);
  71. glBegin(GL_LINES);
  72. glVertex2i(330, 320);
  73. glVertex2i(450, 230);
  74. glVertex2i(330, 230);
  75. glVertex2i(450, 320);
  76. glEnd();
  77.  
  78. glColor3f(0.4, 0.3, 0.9);
  79. glBegin(GL_POLYGON);
  80. glVertex2i(455, 315);
  81. glVertex2i(500, 315);
  82. glVertex2i(500, 100);
  83. glVertex2i(455, 100);
  84. glEnd();
  85.  
  86.  
  87. // window two
  88. glColor3f(0.2, 0.4, 0.3);
  89. glBegin(GL_POLYGON);
  90. glVertex2i(530, 320);
  91. glVertex2i(650, 320);
  92. glVertex2i(650, 230);
  93. glVertex2i(530, 230);
  94. glEnd();
  95. // lines of window two
  96. glColor3f(0.1, 0.7, 0.5);
  97. glLineWidth(5);
  98. glBegin(GL_LINES);
  99. glVertex2i(530, 320);
  100. glVertex2i(650, 230);
  101. glVertex2i(650, 320);
  102. glVertex2i(530, 230);
  103. glEnd();
  104.  
  105.  
  106. glFlush();
  107. }
  108. int main(int argc, char ** argv)
  109. {
  110. // Initialize GLUT
  111. glutInit(&argc, argv);
  112. // Set display mode
  113. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  114. // Set top - left display window position.
  115. glutInitWindowPosition(100, 100);
  116. // Set display window width and height
  117. glutInitWindowSize(800, 600);
  118. // Create display window with the given title
  119. glutCreateWindow("2D House in OpenGL ");
  120. // Execute initialization procedure
  121. init();
  122. // Send graphics to display window
  123. glutDisplayFunc(home);
  124. // Display everything and wait.
  125. glutMainLoop();
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement