? This is a demo similar to the rotation of the earth around the sun
The original example is to use the keyboard to accept the event, I made a change, using the timer to turn him into a dynamic rotation of the
#import <Foundation/Foundation.h>#include<GLUT/GLUT.h>Static intYear=0, day=0;voidinit () {Glclearcolor (0,0,0,0); Glshademodel (Gl_flat);}voiddisplay () {glclear (gl_color_buffer_bit); glcolor3f (1,1,1); Glpushmatrix (); Glutwiresphere (1, -, -); GLROTATEF (glfloat) year,0,1,0); Gltranslated (2,0,0); Glrotatef (glfloat) Day,0,1,0); Glutwiresphere (0.2,Ten,8); Glpopmatrix (); Glutswapbuffers (); }voidReshape (intWinth) {Glviewport (0,0, (Glsizei) W, (Glsizei) h); Glmatrixmode (gl_projection); Glloadidentity (); Gluperspective ( -, (Glfloat) w/(glfloat) H,1, -); Glmatrixmode (Gl_modelview); Glloadidentity (); Glulookat (0,0,5,0,0,0,0,1,0);}voidFishboard () { Day= (day+Ten)% the; year= (year+5)% the; Glutpostredisplay ();}voidTimerproc (intID) {Fishboard (); Gluttimerfunc ( -, Timerproc,1);//need to be called again in the function to ensure that the loop}intMainintargcChar**argv) {Glutinit (&argc, argv); Glutinitdisplaymode (Glut_single|Glut_rgb); Glutinitwindowsize ( -, -); Glutinitwindowposition ( -, -); Glutcreatewindow ("Xcode Glut Demo"); Init (); Glutdisplayfunc (display); Glutreshapefunc (reshape); Gluttimerfunc ( -, Timerproc,1); Glutmainloop (); return 0;}
OpenGL Step to step (2)