The OpenGl development environment under Fedora requires three library files and the corresponding header file: libglut. so, libGLU. so, libGL. so, gl. h, glu. h, glut. h these libraries are available in the linux system by default. The locate command is used for verification in the standard library directory (/usr/lib): [root @ localhostGL] # locatelibglut. so/usr/lib/Fedora OpenGl Development Environment Configuration
To develop an OpenGL project, three library files and corresponding header files are required:
Libglut. so, libGLU. so, libGL. so, gl. h, glu. h, glut. h
These libraries are available in linux by default. The locate command is used to verify that they are all in the standard library directory (/usr/lib:
[root@localhost GL]# locate libglut.so/usr/lib/libglut.so.3/usr/lib/libglut.so.3.9.0[root@localhost GL]# locate libGLU.so/usr/lib/libGLU.so/usr/lib/libGLU.so.1/usr/lib/libGLU.so.1.3.070700[root@localhost GL]# locate libGL.so/usr/lib/libGL.so/usr/lib/libGL.so.1/usr/lib/libGL.so.1.2
However, the header file does not exist. You cannot find the relevant file using locate for verification before installing the development kit.
Install the Development Kit (three Development Kits are required ):
Yum install mesa-libGL-devel mesa-libGLU-devel // these two are opengl core libraries yum install freeglut-devel // OpenGL Utility ToolKit
After installation, run the rpm command to verify the installation package and query the installation file and the location of the installation (taking glut-devel as an example ):
[root@localhost etc]# rpm -qa | grep glutfreeglut-devel-2.6.0-1.fc12.i686[root@localhost etc]# rpm -ql freeglut-devel/usr/include/GL/freeglut.h/usr/include/GL/freeglut_ext.h/usr/include/GL/freeglut_std.h/usr/include/GL/glut.h/usr/lib/libglut.so
After freeglut is installed, glut. h is added to the/usr/include/GL/directory, and the libglut. so file is replaced with/usr/lib.
You can use ls in/usr/include/GL to verify the installed header file:
[root@localhost GL]# lsfreeglut_ext.h freeglut_std.h gl.h glu.h glut.h glx.h glx_mangle.h glxproto.h internalfreeglut.h glext.h gl_mangle.h glu_mangle.h glxext.h glxint.h glxmd.h glxtokens.h
All right, the relevant library and header file are all ready. We can write the simplest example program:
#include
void display(){ glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); glFlush();}int main(int argc,char *argv[]){ glutInit(&argc,argv); glutCreateWindow("Simple"); glutDisplayFunc(display); glutMainLoop(); return 0;}
Compile with the following command:
gcc simple.c -o app -lglut -lGL -lGLU -lm -lX11 -lm
Run./app. a window with a white rectangle is displayed:
===
Install OpenGL configuration in Ubuntu
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.
Install
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
$ sudo apt-get install libgl1-mesa-dev
Install OpenGL Utilities
$ sudo apt-get install libglu1-mesa-dev
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.
Install OpenGL Utility Toolkit
$ Sudo apt-get install libglut-dev OpenGL Utility Toolkit is a Toolkit built on OpenGL Utilities. Besides strengthening OpenGL Utilities, It also adds OpenGL support for Windows interfaces. Note: The following situations may occur during this step. The shell prompts: 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
Sample test. c source code:
#include
void init(void) { 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); 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(300, 300); glutCreateWindow("OpenGL 3D View"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }
Run the following command when compiling a program:
$ gcc -o test test.c -lGL -lGLU -lglut
Run:
$ ./test
Configure the IDE and use cmake as the build tool
In fact, the cmake method of opengl program is very simple, because in linux, the header file has been automatically put into the include path of the system, so you only need to add the link library when linking, this is the same as the setting for compiling with gcc/gw.gov.txt. For example, if clionis used as the idea, the corresponding cmakelists.txt is:
Cmake_minimum_required (VERSION 3.3) project (hello) set (CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS}-std = c ++ 11") set (SOURCE_FILES main. cpp) add_executable (hello $ {SOURCE_FILES}) target_link_libraries ($ {PROJECT_NAME} gl glu glut) # This action is added
Of course, if you think it is easy to write makefile, you can also write it. The key point is to add gl glu glut to the Link Library.
For cmake usage instructions, refer to the CMake quick tutorial. If you want to see how pkg-config works, you can refer to the usage of pkg-config, that is/usr/lib64/pkgconfig
To view the corresponding pc file.
Glew. h header file
Currently, the glew. h header file is not used, and no relevant installation is available in the installation of fedora. Installation Method:
Sudo dnf install glew-devel # Two rpm packages, glew-devel and libGLEWmx, will be installed
For ubuntu, it looks like this:
sudo apt-get install libglew-dev
OpenGL programming guide (original book version 8th) -- computing coloring tool http://www.linuxidc.com/Linux/2015-08/122232.htm
OpenGL programming guide (8th) English PDF high definition http://www.linuxidc.com/Linux/2015-08/122230.htm
OpenGL programming guide (Original book version 7thFor more information, see http://www.linuxidc.com/Linux/2012-08/67925.htm.
OpenGL super baodian 4th Chinese Version PDF + English version + source codeSee http://www.linuxidc.com/Linux/2013-10/91413.htm
OpenGL rendering Article http://www.linuxidc.com/Linux/2011-10/45756.htm
Ubuntu 13.04 install OpenGL http://www.linuxidc.com/Linux/2013-05/84815.htm
OpenGL 3D sphere data generation and drawing [Source Code] http://www.linuxidc.com/Linux/2013-04/83235.htm
Basic Analysis of OpenGL programming http://www.linuxidc.com/Linux/2013-03/81675.htm under Ubuntu
How to configure OpenGL http://www.linuxidc.com/Linux/2012-11/74191.htm with eclipse for c ++ in Ubuntu
For more information about "OpenGL super learning notes", seeHttp://www.linuxidc.com/search.aspx? Where = nkey & keyword = 34581
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-10/124449.htm