Code:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
int x;
void init(void){
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
}
void idle(void){
x++;
x%=360;
glutPostRedisplay();
}
void reshape(int w,int h){
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,1.0,1.5,20.0);
glMatrixMode(GL_MODELVIEW);
}
void display(void){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,(GLsizei)250,(GLsizei)500);
gluPerspective(60.0,1.0,1.5,20.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glutWireSphere(0.3,10,10);
glRotatef(x,0.0,1.0,0.0);
glScalef(1.0,2.0,1.0);
glutWireCube(1.0);
glutSwapBuffers();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,(GLsizei)250,(GLsizei)500);
gluPerspective(60.0,1.0,1.5,20.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glutWireSphere(0.3,10,10);
glRotatef(x,0.0,1.0,0.0);
glScalef(1.0,2.0,1.0);
glutWireCube(1.0);
glutSwapBuffers();
}
int main(int argc,char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}