Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <windows.h>
  3. GLfloat xangle=0.0, yangle=0.0;
  4. void init (void) {
  5. glClearColor (1.0, 1.0, 1.0, 0.0);
  6. glLineWidth (1.0);
  7. glColor3f (1.0, 0.0, 0.0);
  8. glMatrixMode (GL_PROJECTION);
  9. glLoadIdentity ();
  10. glOrtho (-6,6, -6,6, -6,6);
  11. }
  12. void display (void) {
  13. glClear (GL_COLOR_BUFFER_BIT);
  14. glPushMatrix();
  15. glBegin (GL_LINES);
  16. glVertex2f (-5.5,0.0);
  17. glColor3f(1.0, 0.0, 0.0);
  18. glVertex2f (5.5,0.0);
  19. glEnd ();
  20. glBegin (GL_LINES);
  21. glVertex2f (0.0,-5.5);
  22. glColor3f(1.0, 0.0, 0.0);
  23. glVertex2f (0.0, 5.5);
  24. glEnd ();
  25. glRotatef(xangle, 0.0, 1.0, 0.0);
  26. glBegin (GL_POLYGON);
  27. glColor3f(-1.0, 0.0, 0.0);
  28. glVertex2f (1.0, 1.0);
  29. glColor3f(-1.0, 0.0, 0.0);
  30. glVertex2f (4.0, 1.0);
  31. glColor3f(0.0, 1.0, 0.0);
  32. glVertex2f (1.0, 5.0);
  33. glEnd ();
  34. glPopMatrix();
  35. glutSwapBuffers();
  36. glFlush ();
  37. }
  38. void KeyboardAssign (GLubyte key, GLint x, GLint y) { switch (key) {
  39.  
  40. case 'g':
  41. xangle +=10.0;
  42. glColor3f (0.0, 0.0, 1.0);
  43. glutPostRedisplay ();
  44. break;
  45. }
  46. }
  47. int main (int argc, char** argv) {
  48. glutInit (&argc, argv);
  49. glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
  50. glutInitWindowPosition (0, 0);
  51. glutInitWindowSize (1500, 1500);
  52. glutCreateWindow ("Latihan Menggerakkan Objek");
  53. init();
  54. glutDisplayFunc (display);
  55. glutKeyboardFunc (KeyboardAssign);
  56. glutMainLoop ();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement