Here is a good link, in order to prevent link invalidation, copy the content as follows.
Link http://blog.csdn.net/zhangliang_571/article/details/25241911
Content:
OpenGL is a library of drawing functions developed by SGI, a set of C-language functions for the development of 2D and 3D graphics applications. OpenGL lets programmers do not have to take into account the various display card underlying operation is the same problem, the hardware is communicated by the OpenGL core, so as long as the display card support OpenGL, then the program does not need to re-transplant, and the program developers do not need to re-learn a set of library to migrate the program.
Installation
The first essential is the compiler and the basic function library, if the system is not installed, according to the following way to install:
- $ sudo apt-get install build-essential
Installing the OpenGL Library
- $ sudo apt-get install Libgl1-mesa-dev
Installing OpenGL Utilities
- $ sudo apt-get install Libglu1-mesa-dev
OpenGL Utilities is a group of tools built on the OpenGL Library, providing many handy functions that make OpenGL more powerful and easier to use.
Installing OpenGL Utility Toolkit
- $ sudo apt-get install Libglut-dev
OpenGL Utility Toolkit is a toolkit built on OpenGL Utilities, adding OpenGL support for Windows interfaces in addition to the lack of OpenGL Utilities.
Note: At this point, the following scenario may occur, the shell tip:
- Reading Package Lists ... Done
- Building Dependency Tree
- Reading state information ... Done
- E:unable to locate package Libglut-dev
Change the above $ sudo apt-get install Libglut-dev command to $ sudo apt-get install Freeglut3-dev.
Test
Example TEST.C Source code:
- #include <gl/glut. h>
- void init(void)
- {
- Glclearcolor(0. 0, 0. 0, 0. 0, 0. 0);
- Glmatrixmode(gl_projection);
- Glortho(-5, 5,-5, 5, 5,);
- Glmatrixmode(Gl_modelview);
- Glulookat(0, 0,ten, 0, 0, 0, 0, 1, 0);
- return;
- }
- void display(void)
- {
- Glclear(gl_color_buffer_bit);
- glcolor3f(1. 0, 0, 0);
- Glutwireteapot(3);
- Glflush();
- return;
- }
- int main(int argc, char*argv[])
- {
- Glutinit(&argc, argv);
- Glutinitdisplaymode(Glut_rgb | Glut_single);
- Glutinitwindowposition(0, 0);
- Glutinitwindowsize(a);
- Glutcreatewindow("OpenGL 3D View");
- Init();
- Glutdisplayfunc(display);
- Glutmainloop();
- return 0;
- }
When compiling the program, execute the following command:
- $ gcc-o Test Test.c-lgl-lglu-lglut
Perform:
- $./test
Ubuntu Settings OpenGL Environment