Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from OpenGL.GLUT import *
- from OpenGL.GLU import *
- from OpenGL.GL import *
- import sys
- xRotated, yRotated, zRotated = 0,0,0;
- radius=0.5;
- def redisplayFunc():
- global xRotated
- global yRotated
- global zRotated
- glMatrixMode(GL_MODELVIEW);
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- glTranslatef(0.0,0.0,-4.5);
- glColor3f(1.0, 1.0, 0.0);
- glRotatef(yRotated,0.0,1.0,0.0);
- glutSolidSphere(radius,20,30);
- glTranslate(0.0,0.0,-1.0);
- glColor3f(0, 0, 1);
- glutSolidSphere(radius/2,10,30);
- glRotatef(yRotated*2,0.0,1.0,0.0);
- glTranslatef(0.0,0.125,0.5);
- glColor3f(1, 1, 1);
- glutSolidSphere(radius/4,10,30);
- glutSwapBuffers();
- def reshapeFunc(x, y):
- if (y == 0 or x == 0):
- return; #Nothing is visible then, so return
- #Set a new projection matrix
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- #Angle of view:40 degrees
- #Near clipping plane distance: 0.5
- #Far clipping plane distance: 20.0
- gluPerspective(40.0,x/y,0.5,20.0);
- glMatrixMode(GL_MODELVIEW);
- glViewport(0,0,x,y); #Use the whole window for rendering
- def idleFunc():
- global xRotated
- global yRotated
- global zRotated
- ## xRotated += 0.01;
- ## zRotated += 0.01;
- yRotated += 0.5;
- # :: testing
- if yRotated >= 360:
- yRotated = 0
- redisplayFunc();
- def myinit():
- mat_ambient=[0.3,0.3,0.3,1.0];
- mat_diffuse=[0.6,0.6,0.6,1.0];
- mat_specular=[0.9,0.9,0.9,1.0];
- mat_shininess=[100.0];
- glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,mat_ambient);
- glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diffuse);
- glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular);
- glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_shininess);
- light0_ambient=[0.5,0.5,0.5,1.0];
- light0_diffuse=[1.0,1.0,1.0,1.0];
- light0_specular=[1.0,1.0,1.0,1.0];
- light0_position=[5.0,5.0,5.0,0.0];
- glLightfv(GL_LIGHT0,GL_AMBIENT,light0_ambient);
- glLightfv(GL_LIGHT0,GL_DIFFUSE,light0_diffuse);
- glLightfv(GL_LIGHT0,GL_SPECULAR,light0_specular);
- glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
- glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,light0_ambient);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- #glEnable(GL_DEPTH_TEST);
- glShadeModel(GL_SMOOTH);
- #glEnable(GL_NORMALIZE);
- def main():
- global xRotated
- global yRotated
- global zRotated
- # Initialize GLUT
- glutInit(sys.argv);
- # double buffering used to avoid flickering problem in animation
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- # window size
- glutInitWindowSize(400,400);
- # create the window
- glutCreateWindow(b"Sphere Rotating Animation");
- #glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
- glClearColor(0.0,0.0,0.0,0.0);
- #Assign the function used in events
- glutDisplayFunc(redisplayFunc);
- glutReshapeFunc(reshapeFunc);
- glutIdleFunc(idleFunc);
- #Let start glut loop
- #myinit()
- glutMainLoop();
- if __name__ == '__main__': main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement