Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. // opengl.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "glut.h"
  5. #include "math.h"
  6. float x=0,y=0;
  7. void drawCircle (float xc, float yc, float rad)
  8. {
  9. //
  10. // draw a circle centered at (xc,yc) with radius rad
  11. //
  12. glPushMatrix();
  13. glTranslatef(xc,yc,0);
  14. glBegin(GL_LINE_LOOP);
  15. //
  16. for (int angle=0; angle<365; angle=angle+5)
  17. {
  18. float angle_radians = angle * (float)3.14159 / (float)180;
  19. float x = rad * (float)cos(angle_radians);
  20. float y = rad * (float)sin(angle_radians);
  21. glVertex3f(x,y,0);
  22. }
  23. //
  24. glEnd();
  25. glPopMatrix();
  26. }
  27. void display(void)
  28.  
  29. {
  30.     /* clear window */
  31.  
  32.      glClear(GL_COLOR_BUFFER_BIT);
  33. glPushMatrix();
  34. glTranslatef(x,y,0);
  35. //glRotatef(kat,0,0,1); rotacja w okolo osi z
  36.  
  37.     /* draw unit square polygon */
  38.  
  39.     glBegin(GL_POLYGON);
  40.         glVertex2f(-0.5, -0.5);
  41.         glVertex2f(-0.5, 0.5);
  42.         glVertex2f(0.5, 0.5);
  43.         glVertex2f(0.5, -0.5);
  44.     glEnd();
  45.    
  46.     /* flush GL buffers */
  47. glPopMatrix();
  48.     glFlush();
  49.  
  50. }
  51.  
  52.  
  53. static void Key(unsigned char key, int x_d, int y_d)
  54. {
  55.  
  56.     switch (key) {
  57.       case '1':
  58.     x+=.1;
  59.     y+=.1;
  60.     glutPostRedisplay();
  61.     break;
  62.     case '2':
  63.     x-=.1;
  64.     y-=.1;
  65.     glutPostRedisplay();
  66.     break;
  67.       case 27:
  68.     exit(0);
  69.     }
  70. }
  71. void init()
  72. {
  73.  
  74.     /* set clear color to black */
  75.  
  76.     glClearColor (0.0, 0.0, 0.0, 0.0);
  77.     /* set fill  color to white */
  78.  
  79.     glColor3f(1.0, 1.0, 1.0);
  80.  
  81.     /* set up standard orthogonal view with clipping */
  82.     /* box as cube of side 2 centered at origin */
  83.     /* This is default view and these statement could be removed */
  84.  
  85.     glMatrixMode (GL_PROJECTION);
  86.     glLoadIdentity ();
  87.     glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);  
  88. glMatrixMode (GL_MODELVIEW);
  89.     glLoadIdentity ();
  90. }
  91. int main(int argc, char* argv[])
  92. {
  93.     glutInit(&argc,argv);
  94.     glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);  
  95.     glutInitWindowSize(500,500);
  96.     glutInitWindowPosition(0,0);
  97.     glutCreateWindow("simple");
  98.     glutDisplayFunc(display);
  99.     glutKeyboardFunc(Key);
  100.     init();
  101.     glutMainLoop();
  102.  
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement