Advertisement
Guest User

Untitled

a guest
Jun 6th, 2013
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <windows.h>
  2. #include <GL/glut.h>
  3. #include <GL/gl.h>
  4.  
  5. int a[3]={10,10,10}, b[3]={10,-10,10},
  6.     c[3]={-10,-10,10}, d[3]={-10,10,10},
  7.     e[3]={10,10,-10}, f[3]={10,-10,-10},
  8.     g[3]={-10,-10,-10}, h[3]={-10,10,-10};
  9.  
  10. float angle=1.0;
  11.  
  12. void drawcube(void)
  13. {
  14.   glClear(GL_COLOR_BUFFER_BIT);
  15.   glColor3f(1.0, 1.0, 1.0);
  16.  
  17.   glMatrixMode(GL_MODELVIEW);
  18.   glRotatef(angle, 0.0, 1.0, 0.0);
  19.   glBegin(GL_LINE_LOOP);
  20.     glVertex3iv(a);
  21.     glVertex3iv(b);
  22.     glVertex3iv(c);
  23.     glVertex3iv(d);
  24.   glEnd();
  25.   glBegin(GL_LINE_LOOP);
  26.     glVertex3iv(a);
  27.     glVertex3iv(e);
  28.     glVertex3iv(f);
  29.     glVertex3iv(b);
  30.   glEnd();
  31.   glBegin(GL_LINE_LOOP);
  32.     glVertex3iv(d);
  33.     glVertex3iv(h);
  34.     glVertex3iv(g);
  35.     glVertex3iv(c);
  36.   glEnd();
  37.   glBegin(GL_LINE_LOOP);
  38.     glVertex3iv(e);
  39.     glVertex3iv(f);
  40.     glVertex3iv(g);
  41.     glVertex3iv(h);
  42.   glEnd();
  43.  
  44.   glFlush();
  45.   glutSwapBuffers();
  46. }
  47.  
  48. void keyboard(unsigned char key, int x, int y)
  49. {
  50.   switch (key)
  51.   {
  52.     case 0x1B:
  53.     case 'q':
  54.     case 'Q':
  55.       exit(0);
  56.     break;
  57.   }
  58. }
  59.  
  60. void mouse(int btn, int state, int x, int y)
  61. {
  62.   if (state == GLUT_DOWN)
  63.   {
  64.     if (btn == GLUT_LEFT_BUTTON)
  65.       angle = angle + 1.0f;
  66.     else if (btn == GLUT_RIGHT_BUTTON)
  67.       angle = angle - 1.0f;
  68.     else
  69.       angle = 0.0f;
  70.   }
  71. }
  72.  
  73. int main(int argc, char **argv)
  74. {
  75.   glutInit(&argc, argv);
  76.   glutInitWindowSize(500, 500);
  77.   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  78.   glutCreateWindow("Glut rotate");
  79.   glutMouseFunc(mouse);
  80.   glutKeyboardFunc(keyboard);
  81.   glutDisplayFunc(drawcube);
  82.   glutIdleFunc(drawcube);
  83.  
  84.   glMatrixMode(GL_PROJECTION);
  85.   glLoadIdentity();
  86.   glOrtho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0);
  87.   glRotatef(30.0, 1.0, 0.0, 0.0);
  88.   glMatrixMode(GL_MODELVIEW);
  89.   glClearColor(0.0, 0.0, 0.0, 0.0);
  90.  
  91.   glutMainLoop();
  92.   return(0);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement