1 Installing the FREEGLUT3 OpenGL Auxiliary class Library
sudo apt-get install Freeglut3-dev
2 Compiling commands
GCC Test.cpp-lglut-lgl-lglu
As can be seen from the above command, three classes of libraries are used
3 Animation test Program
Third party libraries: sudo apt-get install freeglut3-dev//which uses the Glut.h file//compile command: GCC test.cpp-lglut-lgl-lglu#include <gl/ glut.h> #include <stdlib.h>static glfloat spin = 0.0;void display (void) {glclear (gl_color_buffer_bit); Glpushmatrix (); GLROTATEF (Spin, 0.0, 0.0, 1.0); GLCOLOR3F (1.0, 1.0, 1.0); GLRECTF (-25.0,-25.0, 25.0, 25.0); Glpopmatrix (); Glutswapbuffers ();} void Spindisplay (void) {spin = spin + 2.0; if (Spin > 360.0) spin = spin-360.0; Glutpostredisplay ();} void init (void) {Glclearcolor (0.0, 0.0, 0.0, 0.0); Glshademodel (Gl_flat);} void reshape (int w, int h) {glviewport (0, 0, (Glsizei) W, (Glsizei) h); Glmatrixmode (gl_projection); Glloadidentity (); Glortho (-50.0, 50.0,-50.0, 50.0,-1.0, 1.0); Glmatrixmode (Gl_modelview); Glloadidentity ();} void Mouse (int button, int state, int x, int. y) {switch (button) {case Glut_left_button:if (state = = GLU T_down) Glutidlefunc (Spindisplay); BreakCase Glut_middle_button:case glut_right_button:if (state = = Glut_down) glutidlefunc (NULL); Break Default:break; }/* * Request double buffer display mode. * Register Mouse Input callback functions */int main (int argc, char** argv) {glutinit (&ARGC, argv); Glutinitdisplaymode (glut_double | GLUT_RGB); Glutinitwindowsize (250, 250); Glutinitwindowposition (100, 100); Glutcreatewindow (Argv[0]); Init (); Glutdisplayfunc (display); Glutreshapefunc (reshape); Glutidlefunc (Spindisplay); Glutmousefunc (mouse); Glutmainloop (); return 0; /* ANSI C requires main to return int. */}
Save as Test.cpp file and compile with command (2) to get a.out
4 run
./a.out
The result is a rotated rectangle animation.
Ubuntu14.04 OpenGL Animation test Program