Development Environment:
Ubuntu9.10 desktop x86, netbeans6.8, opengl2.1
Library required for installation and development
OpenGL website has such a sentence (http://www.opengl.org/wiki/Getting_started#Linux ):
Linux comes with mesa libraries, which implements the OpenGL API as a software Rasterizer.
On the mesa website, the latest version is 7.7, which supports opengl2.1. However, restricted by specific drivers, it is not guaranteed that all APIs are fully supported.
You can download the source code for compilation and installation, but first install the compiled Mesa library and Development files on Ubuntu.
First, make sure that the compiler and other libraries have been installed:
Sudo apt-Get install build-essential
Run the following command to install mesa7.6.0 to the system.
Sudo apt-Get install libgl1-mesa-dev
The following two libraries are installed:
Sudo apt-Get install libglu1-mesa-dev
This library is an enhancement to OpenGL.
Sudo apt-Get install libglut-Dev
This library is used to enhance the OpenGL window and the enhancement library above.
Now write the code :( copied, refer to the http://wiki.ubuntu-tw.org/index.php? Title = howto_install_opengl_development_environment)
# Include <Gl/glut. h>
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 ();
Gludisplayfunc (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 ();
}
To set the library required by link in the netbeans project, refer:
Continue to select the libglu. So and libglut. So files.
Then the compilation link is passed,
/Usr/bin/make-F nbproject/Makefile-Debug.mk subprojects =. Build-Conf
Make [1]: Entering the directory '/home/chenshu/svnclient/mycodes/opengl1'
/Usr/bin/make-F nbproject/Makefile-Debug.mk Dist/debug/GNU-Linux-x86/opengl1
Make [2]: Entering the directory '/home/chenshu/svnclient/mycodes/opengl1'
Mkdir-P build/debug/GNU-Linux-x86
Rm-F build/debug/GNU-Linux-x86/Main. o. D
G ++-C-g-MMD-MP-MF build/debug/GNU-Linux-x86/Main. o. D-o build/debug/GNU-Linux-x86/Main. O main. cpp
Mkdir-P Dist/debug/GNU-Linux-x86
G ++-O Dist/debug/GNU-Linux-x86/opengl1 build/debug/GNU-Linux-x86/Main. O-lgl-lglu-lglut
Make [2]: leaving the directory '/home/chenshu/svnclient/mycodes/opengl1'
Make [1]: leaving the directory '/home/chenshu/svnclient/mycodes/opengl1'
Building successful (total time: 804 Ms)
Run the program:
This is today. We will continue to explore the functions of these Apis tomorrow.