Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <GL/glut.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #define W 800
- #define H 600
- int c=0,height,width,r=1;
- void reshape(int h, int w)
- {
- float aspectRatio;
- height=h;
- width=w;
- aspectRatio=(float)height/(float)width;
- glViewport(0,0,height,width);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0f, aspectRatio, 0.1f, 100.0f);
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(
- 0.0f,2.0f,6.0f,
- 0.0f,0.0f,0.0f,
- 0.0f,1.0f,0.0f
- );
- glPushMatrix();
- glRotatef(0.001f * c, 0.0f, 1.0f, 0.0f);
- glColor3f(0.8f, 0.7f, 0.01f);
- glutSolidCube(1.0);
- glPopMatrix();
- glPushMatrix();
- glRotatef(0.1f * c, 0.0f, 1.0f, 0.0f);
- glTranslatef(2.0f, 0.0f, 0.0f);
- glPushMatrix();
- glRotatef(0.15f * c, 0.0f, 1.0f, 0.0f);
- glTranslatef(0.5f, 0.0f, 0.0f);
- glRotatef(0.15f * c, 0.0f, 1.0f, 0.0f);
- glColor3f(0.4f, 0.4f, 0.4f);
- glutSolidCube(0.1);
- glPopMatrix();
- glRotatef(0.5f * c, 0.0f, 1.0f, 0.0f);
- glColor3f(0.3f, 0.7f, 0.9f);
- glutSolidCube(0.3);
- glPopMatrix();
- glPushMatrix();
- glRotatef(120.0f, 0.0f, 1.0f, 0.0f);
- glRotatef(0.07f * c, 0.0f, 1.0f, 0.0f);
- glTranslatef(3.0f, 0.0f, 0.0f);
- glPushMatrix();
- glRotatef(60.0f, 0.0f, 0.0f, 1.0f);
- glRotatef(0.12f * c, 0.0f, 1.0f, 0.0f);
- glTranslatef(0.5f, 0.0f, 0.0f);
- glRotatef(0.12f * c, 0.0f, 1.0f, 0.0f);
- glColor3f(0.4f, 0.4f, 0.4f);
- glutSolidCube(0.11);
- glPopMatrix();
- glRotatef(0.2f * c, 0.0f, 1.0f, 0.0f);
- glColor3f(0.5f, 0.01f, 0.01f);
- glutSolidCube(0.32);
- glPopMatrix();
- glutSwapBuffers();
- }
- void idle(void)
- {
- c=c+1;
- glutPostRedisplay();
- }
- void init(void)
- {
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glEnable(GL_DEPTH_TEST);
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- height=H;
- width=W;
- glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
- glutInitWindowSize(width,height);
- glutCreateWindow("opengl_2");
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutIdleFunc(idle);
- init();
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement