Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #pragma comment (lib,"glut32.lib")
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <GL/glut.h>
- #define BLACK 1, 1, 1
- double angle_sun, angle_moon, angle_earth;
- void display () {
- //clear the display
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClearColor (BLACK, 0);
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity ();
- // defines a viewing transformation
- gluLookAt (.1, 0, 300, // eye
- 0, 0, 0, // lookat
- 0, 0, 1); // up
- // again select MODEL-VIEW
- glMatrixMode (GL_MODELVIEW);
- glColor3f (1, 0, 0);
- glPushMatrix (); {
- glTranslated (0, 0, 0);
- glRotatef (angle_sun, 1, 0, 0);
- glRotatef (90, 0, 1, 0);
- glutWireSphere (70, // GLdouble radius
- 30, // GLint slices
- 30); // GLint stacks
- glColor3f (0, 0, 1);
- glPushMatrix (); {
- glTranslated (0, 150, 0);
- glRotatef (angle_earth, 0, 0, 1);
- glRotatef (0, 1, 0, 0);
- glutWireSphere (40, // GLdouble radius
- 18, // GLint slices
- 18); // GLint stacks
- glColor3f (0, 0, 0);
- glPushMatrix (); {
- glTranslated (0, 100, 0);
- glRotatef (angle_moon, 0, 0, 1);
- glutWireSphere (25, // GLdouble radius
- 18, // GLint slices
- 18); // GLint stacks
- } glPopMatrix ();
- } glPopMatrix ();
- } glPopMatrix ();
- // ADD this line in the end --- if you use double buffer (i.e. GL_DOUBLE)
- glutSwapBuffers ();
- }
- void animate(){
- angle_sun += .1;
- angle_earth += .5;
- angle_moon += 2;
- glutPostRedisplay();
- }
- void init () {
- glClearColor (BLACK, 0);
- glMatrixMode (GL_PROJECTION); // load the projection matrix
- glLoadIdentity (); // initialize the matrix
- gluPerspective (70, 1, 0.1, 10000.0); // perspective parameters
- }
- int main (int argc, char **argv) {
- glutInit (&argc,argv);
- glutInitWindowSize (900, 700);
- glutInitWindowPosition (300, 200);
- glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB); // depth, double buffer, RGB color
- glutCreateWindow ("ID");
- init ();
- glEnable (GL_DEPTH_TEST); // enable depth testing
- glutDisplayFunc (display); // display callback function
- glutIdleFunc (animate); //what you want to do in the idle time (when no drawing is occuring)
- glutMainLoop (); // main loop of OpenGL
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment