Foreword OpenGL is a set of drawing function libraries developed by SGI. It is a set of C language functions for the development of 2D and 3D graphics applications. OpenGL makes it unnecessary for program developers to consider whether the underlying operations of various display cards are the same. The hardware is communicated by the OpenGL core. Therefore, as long as the display card supports OpenGL, the program does not need to be transplanted again, program developers do not need to re-learn a set of function libraries to transplant programs. Next, we will step by step at the end of Ubuntu
Preface
OpenGL is a drawing function library developed by SGI. It is a set of C-language functions used for the development of 2D and 3D graphics applications.
OpenGL makes it unnecessary for program developers to consider whether the underlying operations of various display cards are the same. The hardware is communicated by the OpenGL core. Therefore, as long as the display card supports OpenGL, the program does not need to be transplanted again, program developers do not need to re-learn a set of function libraries to transplant programs.
Next, we will establish an environment for developing OpenGL applications under Ubuntu step by step.
Install
Create a basic compilation environment
The first indispensable thing is the compiler and the basic library. if the system is not installed, install it as follows:
$ Sudo apt-get install build-essential
Install OpenGL Library
Next we will install the Library we will use. First install the OpenGL Library
$ Sudo apt-get install libgl1-mesa-dev
Install OpenGL Utilities
OpenGL Utilities is a group of tools built on OpenGL Library. It provides many convenient functions to make OpenGL more powerful and easy to use. Next we will install OpenGL Utilities
$ Sudo apt-get install libglu1-mesa-dev
Install OpenGL Utility Toolkit
OpenGL Utility Toolkit is a Toolkit built on OpenGL Utilities. Besides strengthening OpenGL Utilities, It also adds OpenGL support for Windows interfaces.
$ Sudo apt-get install libglut-dev
Note that in this step, the following conditions may occur: shell prompts: Reading the package list... the dependency tree of the software package being analyzed is reading status information... finished E: no software package libglut-dev if the above situation occurs, enter the above $ sudo apt-get install libglut-dev command into $ sudo apt-get install freeglut3-dev to pull,
Set compilation parameters and compilation
Before that, we need a test example. example. c is as follows:
# Include
Void init ();
Void display ();
Int main (int argc, char * argv [])
{
Gluinit (& argc, argv );
Fig );
Gluinitwindowposition (0, 0 );
Gluinitwindowsize (300,300 );
Valley createwindow ("OpenGL 3D View ");
Init (); fig (display );
Glumainloop ();
Return 0;
}
Void init ()
{
GlClearColor (0.0, 0.0, 0.0, 0.0 );
GlMatrixMode (GL_PROJECTION );
GlOrtho (-5, 5,-5, 5, 5, 15 );
GlMatrixMode (GL_MODELVIEW );
GluLookAt (0, 0, 10, 0, 0, 0, 0, 1, 0 );
}
Void display ()
{
GlClear (GL_COLOR_BUFFER_BIT );
GlColor3f (1.0, 0, 0 );
Gluwireteapot (3 );
GlFlush ();
}
With the test example and basic compiling environment related to various OpenGL libraries, all we need to do is to tell the compiler that we have installed the OpenGL library, which should be linked during program compilation.
$ Gcc example. c-lGL-lGLU-lglut
Because we have installed OpenGL Utility Toolkit, which is built on OpenGL Utilities and OpenGL Library, we can simply link the Library of OpenGL Utility Toolkit to achieve our goal. The following compilation parameters have the same effect as above:
$ Gcc example. c-lglut
The gcc parameters used are briefly described below.
-L Tell gcc to link the specified Library-o Output name of the specified execution File
Run
Next, let's take a look at our results. If we see the teapot image, it means it is successful!
$./Example. out
Complete.
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2