OpenGL Step to step (2)

Source: Internet
Author: User

? 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.