Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.15 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <GL/glut.h>
  3. #include <GL/gl.h>
  4. #include <GL/glu.h>
  5.  
  6. #define W 800
  7. #define H 600
  8.  
  9. int c=0,height,width,r=1;
  10.  
  11.  
  12. void reshape(int h, int w)
  13. {
  14.     float aspectRatio;
  15.     height=h;
  16.     width=w;
  17.     aspectRatio=(float)height/(float)width;
  18.     glViewport(0,0,height,width);
  19.     glMatrixMode(GL_PROJECTION);
  20.     glLoadIdentity();
  21.     gluPerspective(60.0f, aspectRatio, 0.1f, 100.0f);
  22. }
  23.  
  24.  
  25. void display(void)
  26. {      
  27.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  28.  
  29.     glMatrixMode(GL_MODELVIEW);
  30.     glLoadIdentity();
  31.     gluLookAt(
  32.             0.0f,2.0f,6.0f,
  33.             0.0f,0.0f,0.0f,
  34.             0.0f,1.0f,0.0f
  35.           );
  36.  
  37.     glPushMatrix();
  38.         glRotatef(0.001f * c, 0.0f, 1.0f, 0.0f);
  39.         glColor3f(0.8f, 0.7f, 0.01f);
  40.         glutSolidCube(1.0);
  41.     glPopMatrix();
  42.  
  43.     glPushMatrix();
  44.         glRotatef(0.1f * c, 0.0f, 1.0f, 0.0f);
  45.         glTranslatef(2.0f, 0.0f, 0.0f);
  46.         glPushMatrix();
  47.             glRotatef(0.15f * c, 0.0f, 1.0f, 0.0f);
  48.             glTranslatef(0.5f, 0.0f, 0.0f);
  49.             glRotatef(0.15f * c, 0.0f, 1.0f, 0.0f);
  50.             glColor3f(0.4f, 0.4f, 0.4f);
  51.             glutSolidCube(0.1);
  52.  
  53.         glPopMatrix();
  54.         glRotatef(0.5f * c, 0.0f, 1.0f, 0.0f);
  55.         glColor3f(0.3f, 0.7f, 0.9f);
  56.         glutSolidCube(0.3);
  57.  
  58.     glPopMatrix();
  59.  
  60.     glPushMatrix();
  61.         glRotatef(120.0f, 0.0f, 1.0f, 0.0f);
  62.         glRotatef(0.07f * c, 0.0f, 1.0f, 0.0f);
  63.         glTranslatef(3.0f, 0.0f, 0.0f);
  64.         glPushMatrix();
  65.             glRotatef(60.0f, 0.0f, 0.0f, 1.0f);
  66.             glRotatef(0.12f * c, 0.0f, 1.0f, 0.0f);
  67.             glTranslatef(0.5f, 0.0f, 0.0f);
  68.             glRotatef(0.12f * c, 0.0f, 1.0f, 0.0f);
  69.             glColor3f(0.4f, 0.4f, 0.4f);
  70.             glutSolidCube(0.11);
  71.  
  72.         glPopMatrix();
  73.         glRotatef(0.2f * c, 0.0f, 1.0f, 0.0f);
  74.         glColor3f(0.5f, 0.01f, 0.01f);
  75.         glutSolidCube(0.32);
  76.  
  77.     glPopMatrix();
  78.     glutSwapBuffers();
  79. }
  80.  
  81. void idle(void)
  82. {
  83.     c=c+1;
  84.     glutPostRedisplay();
  85. }
  86.  
  87. void init(void)
  88. {
  89.     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  90.     glEnable(GL_DEPTH_TEST);
  91. }
  92.  
  93. int main(int argc, char **argv)
  94. {
  95.     glutInit(&argc, argv);
  96.     height=H;
  97.     width=W;
  98.     glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
  99.  
  100.     glutInitWindowSize(width,height);
  101.     glutCreateWindow("opengl_2");
  102.     glutDisplayFunc(display);
  103.     glutReshapeFunc(reshape);
  104.     glutIdleFunc(idle);
  105.     init();
  106.  
  107.     glutMainLoop();
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement