Advertisement
Guest User

Untitled

a guest
May 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<glut.h>
  3. float z_pos = -10.0f; float rot = 0.0f;
  4. float y_pos = 0.0f; float x_pos = 0.0f;
  5. float x_rot = 0.0f; float y_rot = 0.0f;
  6. float z_rot = 0.0f;
  7. void resize(int width, int height)
  8. {
  9. glViewport(0, 0, width, height);
  10. glMatrixMode(GL_PROJECTION);
  11. glLoadIdentity();
  12. gluPerspective(160, (float)width / (float)height, 1.0, 300.0);
  13. glMatrixMode(GL_MODELVIEW);
  14. glLoadIdentity();
  15. }
  16.  
  17. void putaran(int id)
  18. {
  19. rot += 0;
  20. glutPostRedisplay(); // request redisplay
  21. glutTimerFunc(100, putaran, 0); // request next timer event
  22. }
  23.  
  24.  
  25. void keyboardku(unsigned char key, int x, int y)
  26. {
  27. if ((key == '<') || (key == ',')) z_pos -= 0.1f;
  28. if ((key == '>') || (key == '.')) z_pos += 0.1f;
  29. if ((key == 's') || (key == 'S')) y_pos -= 0.1f;
  30. if ((key == 'w') || (key == 'W')) y_pos += 0.1f;
  31. if ((key == 'a') || (key == 'A')) x_pos -= 0.1f;
  32. if ((key == 'd') || (key == 'D')) x_pos += 0.1f;
  33. if ((key == 'x') || (key == 'X')) //Rotasi sumbu x kanan
  34. {
  35. x_rot = 1.0f;
  36. y_rot = 0.0f;
  37. z_rot = 0.0f;
  38. rot += 10;
  39. }
  40. }
  41.  
  42. void mydisplay(void)
  43. {
  44. glClear(GL_COLOR_BUFFER_BIT);
  45. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  46. glLoadIdentity();
  47. glTranslatef(x_pos, y_pos, z_pos);
  48. glRotatef(rot, x_rot, y_rot, z_rot);
  49.  
  50. // sisi kirir
  51. glColor3f(0, 1, 1);
  52. glBegin(GL_POLYGON);
  53. glVertex3f(3, -4, 0);
  54. glVertex3f(3, -6, 0);
  55. glVertex3f(3, -4, 3);
  56. glVertex3f(3, -6, 3);
  57. glEnd();
  58.  
  59. //// sisi kanan
  60. //glColor3f(0, 1, 1);
  61. //glBegin(GL_POLYGON);
  62. //glVertex3f(-2, -5, 5);
  63. //glVertex3f(-2, -6, 5);
  64. //glVertex3f(-1, -6, 5);
  65. //glVertex3f(-1, -5, 5);
  66. //glEnd();
  67.  
  68. //glColor3f(0, 1, 1);//shape1
  69. //glBegin(GL_POLYGON);
  70. //glVertex3f(-2, -5, 0);
  71. //glVertex3f(-2, -6, 0);
  72. //glVertex3f(-2, -6, 5);
  73. //glVertex3f(-2, -5, 5);
  74. //glEnd();
  75. //glColor3f(0, 1, 1);
  76. //glBegin(GL_POLYGON);
  77. //glVertex3f(-2, -6, 0);
  78. //glVertex3f(-1, -6, 0);
  79. //glVertex3f(-1, -6, 5);
  80. //glVertex3f(-2, -6, 5);
  81. //glEnd();
  82. //glColor3f(0, 1, 1);
  83. //glBegin(GL_POLYGON);
  84. //glVertex3f(-1, -6, 0);
  85. //glVertex3f(-1, -5, 0);
  86. //glVertex3f(-1, -5, 5);
  87. //glVertex3f(-1, -6, 5);
  88. //glEnd();
  89. //glColor3f(0, 1, 1);
  90. //glBegin(GL_POLYGON);
  91. //glVertex3f(-1, -5, 0);
  92. //glVertex3f(-2, -5, 0);
  93. //glVertex3f(-2, -5, 5);
  94. //glVertex3f(-1, -5, 5);
  95. //glEnd();
  96.  
  97.  
  98. //glColor3f(0, 1, 1);
  99. //glBegin(GL_POLYGON);//alas2
  100. //glVertex3f(-2, -10, 0);
  101. //glVertex3f(-1, -11, 0);
  102. //glVertex3f(-1, -11, 0);
  103. //glVertex3f(-2, -10, 0);
  104. //glEnd();
  105. //glColor3f(0, 1, 1);
  106. //glBegin(GL_POLYGON);
  107. //glVertex3f(-2, -10, 5);
  108. //glVertex3f(-1, -10, 5);
  109. //glVertex3f(-1, -11, 5);
  110. //glVertex3f(-2, -11, 5);
  111. //glEnd();
  112.  
  113. //glColor3f(0, 1, 1);//shape2
  114. //glBegin(GL_POLYGON);
  115. //glVertex3f(-2, -10, 0);
  116. //glVertex3f(-1, -10, 0);
  117. //glVertex3f(-1, -10, 5);
  118. //glVertex3f(-2, -10, 5);
  119. //glEnd();
  120. //glColor3f(0, 1, 1);
  121. //glBegin(GL_POLYGON);
  122. //glVertex3f(-1, -10, 0);
  123. //glVertex3f(-1, -11, 0);
  124. //glVertex3f(-1, -11, 5);
  125. //glVertex3f(-1, -10, 5);
  126. //glEnd();
  127. //glColor3f(0, 1, 1);
  128. //glBegin(GL_POLYGON);
  129. //glVertex3f(-1, -11, 0);
  130. //glVertex3f(-2, -11, 0);
  131. //glVertex3f(-2, -11, 5);
  132. //glVertex3f(-1, -11, 5);
  133. //glEnd();
  134. //glColor3f(0, 1, 1);
  135. //glBegin(GL_POLYGON);
  136. //glVertex3f(-2, -11, 0);
  137. //glVertex3f(-2, -10, 0);
  138. //glVertex3f(-2, -10, 5);
  139. //glVertex3f(-2, -11, 5);
  140. //glEnd();
  141.  
  142. //glColor3f(0, 1, 1);
  143. //glBegin(GL_POLYGON);//alas3
  144. //glVertex3f(7, -5, 0);
  145. //glVertex3f(7, -6, 0);
  146. //glVertex3f(8, -6, 0);
  147. //glVertex3f(8, -5, 0);
  148. //glEnd();
  149. //glColor3f(0, 1, 1);
  150. //glBegin(GL_POLYGON);
  151. //glVertex3f(7, -5, 5);
  152. //glVertex3f(7, -6, 5);
  153. //glVertex3f(8, -6, 5);
  154. //glVertex3f(8, -5, 5);
  155. //glEnd();
  156.  
  157. //glColor3f(0, 1, 1);//shape3
  158. //glBegin(GL_POLYGON);
  159. //glVertex3f(7, -5, 0);
  160. //glVertex3f(7, -6, 0);
  161. //glVertex3f(7, -6, 5);
  162. //glVertex3f(7, -5, 5);
  163. //glEnd();
  164. //glColor3f(0, 1, 1);
  165. //glBegin(GL_POLYGON);
  166. //glVertex3f(7, -6, 0);
  167. //glVertex3f(8, -6, 0);
  168. //glVertex3f(8, -6, 5);
  169. //glVertex3f(7, -6, 5);
  170. //glEnd();
  171. //glColor3f(0, 1, 1);
  172. //glBegin(GL_POLYGON);
  173. //glVertex3f(8, -6, 0);
  174. //glVertex3f(8, -5, 0);
  175. //glVertex3f(8, -5, 5);
  176. //glVertex3f(8, -6, 5);
  177. //glEnd();
  178. //glColor3f(0, 1, 1);
  179. //glBegin(GL_POLYGON);
  180. //glVertex3f(8, -5, 0);
  181. //glVertex3f(7, -5, 0);
  182. //glVertex3f(7, -5, 5);
  183. //glVertex3f(8, -5, 5);
  184. //glEnd();
  185.  
  186.  
  187. //glColor3f(1, 0, 0);
  188. //glBegin(GL_POLYGON);//alas4
  189. //glVertex3f(7, -10, 0);
  190. //glVertex3f(8, -10, 0);
  191. //glVertex3f(8, -11, 0);
  192. //glVertex3f(7, -11, 0);
  193. //glEnd();
  194. //glColor3f(1, 0, 0);
  195. //glBegin(GL_POLYGON);
  196. //glVertex3f(7, -10, 5);
  197. //glVertex3f(8, -10, 5);
  198. //glVertex3f(8, -11, 5);
  199. //glVertex3f(7, -11, 5);
  200. //glEnd();
  201.  
  202. //glColor3f(1, 0, 0);//shape4
  203. //glBegin(GL_POLYGON);
  204. //glVertex3f(7, -10, 0);
  205. //glVertex3f(8, -10, 0);
  206. //glVertex3f(8, -10, 5);
  207. //glVertex3f(7, -10, 5);
  208. //glEnd();
  209. //glColor3f(1, 0, 0);
  210. //glBegin(GL_POLYGON);
  211. //glVertex3f(8, -10, 0);
  212. //glVertex3f(8, -11, 0);
  213. //glVertex3f(8, -11, 5);
  214. //glVertex3f(8, -10, 5);
  215. //glEnd();
  216. //glColor3f(1, 0, 0);
  217. //glBegin(GL_POLYGON);
  218. //glVertex3f(8, -11, 0);
  219. //glVertex3f(7, -11, 0);
  220. //glVertex3f(7, -11, 5);
  221. //glVertex3f(8, -11, 5);
  222. //glEnd();
  223. //glColor3f(1, 0, 0);
  224. //glBegin(GL_POLYGON);
  225. //glVertex3f(7, -11, 0);
  226. //glVertex3f(7, -10, 0);
  227. //glVertex3f(7, -10, 5);
  228. //glVertex3f(7, -11, 5);
  229. //glEnd();
  230.  
  231. //glColor3f(1, 1, 1);
  232. //glBegin(GL_POLYGON);//alas5
  233. //glVertex3f(-2, -5, 5);
  234. //glVertex3f(8, -5, 5);
  235. //glVertex3f(8, -11, 5);
  236. //glVertex3f(-2, -11, 5);
  237. //glEnd();
  238. //glColor3f(1, 1, 1);
  239. //glBegin(GL_POLYGON);
  240. //glVertex3f(-2, -5, 6);
  241. //glVertex3f(8, -5, 6);
  242. //glVertex3f(8, -11, 6);
  243. //glVertex3f(-2, -11, 6);
  244. //glEnd();
  245.  
  246. //glColor3f(0, 1, 1);//shape5
  247. //glBegin(GL_POLYGON);
  248. //glVertex3f(-2, -5, 5);
  249. //glVertex3f(8, -5, 5);
  250. //glVertex3f(8, -5, 5);
  251. //glVertex3f(-2, -5, 5);
  252. //glEnd();
  253. //glColor3f(0, 1, 1);
  254. //glBegin(GL_POLYGON);
  255. //glVertex3f(8, -5, 5);
  256. //glVertex3f(8, -11, 5);
  257. //glVertex3f(8, -11, 6);
  258. //glVertex3f(8, -5, 6);
  259. //glEnd();
  260. //glColor3f(0, 1, 1);
  261. //glBegin(GL_POLYGON);
  262. //glVertex3f(8, -5, 5);
  263. //glVertex3f(-2, -5, 5);
  264. //glVertex3f(-2, -5, 6);
  265. //glVertex3f(8, -5, 6);
  266. //glEnd();
  267. //glColor3f(0, 1, 1);
  268. //glBegin(GL_POLYGON);
  269. //glVertex3f(-2, -5, 5);
  270. //glVertex3f(-2, -11, 5);
  271. //glVertex3f(-2, -11, 6);
  272. //glVertex3f(-2, -5, 6);
  273. //glEnd();
  274.  
  275. glFlush();
  276. glutSwapBuffers();
  277. }
  278.  
  279. void init() {
  280. glEnable(GL_DEPTH_TEST);
  281. glClearColor(1.0, 1.0, 1.0, 1.0);
  282. glMatrixMode(GL_PROJECTION);
  283. glLoadIdentity();
  284. gluPerspective(45, (GLdouble)500.0 / (GLdouble)500.0, 0, 100);
  285. glMatrixMode(GL_MODELVIEW);
  286. return;
  287. }
  288.  
  289. int main(int argc, char** argv)
  290. {
  291. glutInit(&argc, argv);
  292. glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
  293. glutInitWindowSize(800, 800);
  294. glutInitWindowPosition(0, 0);
  295. glutCreateWindow("Galang Aprilian");
  296. glutDisplayFunc(mydisplay);
  297. glutTimerFunc(100, putaran, 0);
  298. glutKeyboardFunc(keyboardku);
  299. glutReshapeFunc(resize);
  300. init();
  301. glutMainLoop();
  302. return 0;
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement