|
Fedora under OpenGl development environment configuration
OpenGL development project requires three libraries and corresponding header files:
libglut.so, libGLU.so, libGL.so, gl.h, glu.h, glut.h
These libraries have linux system default, use the locate command to verify that all the standard library directory (/ usr / lib) below:
[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
But the first document is not, use locate the file might not be found to verify before you install the development package.
Installation Development Kit (SDK requires three):
yum install mesa-libGL-devel mesa-libGLU-devel // These two are the core library opengl
yum install freeglut-devel // OpenGL Utility ToolKit
After installing the package and verify the installation files that are installed using the rpm query command and installed in any position (to glut-devel as an example):
[Root @ localhost etc] # rpm -qa | grep glut
freeglut-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
Followed by the visible installation freeglut in / usr / include / GL / directory adds glut.h, in / usr / lib / next replaced libglut.so file.
You can use ls in / usr / include / GL authentication header files about the installation of:
[Root @ localhost GL] # ls
freeglut_ext.h freeglut_std.h gl.h glu.h glut.h glx.h glx_mangle.h glxproto.h internal
freeglut.h glext.h gl_mangle.h glu_mangle.h glxext.h glxint.h glxmd.h glxtokens.h
Well, associated libraries and header files are ready, we can write a simple example program:
#include < GL / glut.h >
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;
}
Use the following command to compile:
gcc simple.c -o app -lglut -lGL -lGLU -lm -lX11 -lm
A run ./app painted white rectangular window:
===
Ubuntu installed OpenGL configuration
OpenGL was developed by a company out of the SGI graphics library, which is a set of C language functions for the development of 2D and 3D graphics apps. OpenGL allows program developers do not take into account the underlying operating display card is the same problem, OpenGL hardware to communicate the core, so as long as the graphics card supports OpenGL, you do not need to re-transplant program, and program developers should not You need to learn a set of libraries to migrate apps.
installation
First is the essential and basic compiler library, if the system is not already installed, install in accordance with the following manner:
$ 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 set built on top of OpenGL Library of tools provides many convenient functions make OpenGL more powerful and easier to use.
Install OpenGL Utility Toolkit
$ Sudo apt-get install libglut-dev
OpenGL Utility Toolkit is built on top of OpenGL Utilities toolbox, in addition to strengthening the OpenGL Utilities deficiencies outside, but also increases the OpenGL interface for Windows support.
Note: In this step, it may appear the following conditions, shell prompt:
Reading package lists ... Done
Building dependency tree
Reading state information ... Done
E: Unable to locate package libglut-dev
Above $ sudo apt-get install libglut-dev command into $ sudo apt-get install freeglut3-dev can be.
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, 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;
}
When compiling the program, execute the following command:
$ Gcc -o test test.c -lGL -lGLU -lglut
carried out:
$ ./test
Configured IDE, use as a build tool cmake
In fact, opengl program cmake wording is very simple, because in linux, the header file has been automatically placed in the system include path, so just need to add link library, and front with gcc / g ++ compiler in the link, when almost the same, the argument is nothing more than the written CMakeLists.txt. Such as using clion as IDE, then the corresponding CMakeLists.txt as follows:
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 new behavior
Of course, if you think it is easy to write makefile, it can also go to write, the key point is to join link library GL GLU glut three.
About cmake usage, you can refer to CMake Quick Start tutorial. If you would like to see further pkg-config is how to play, you can refer to use pkg-config, that view corresponding pc file in / usr / lib64 / pkgconfig path.
glew.h header
There is no use glew.h headers, front fedora installation nor the relevant installation. installation method:
sudo dnf install glew-devel
# Install glew-devel rpm package and two libGLEWmx
If it is ubuntu, installation should look like this:
sudo apt-get install libglew-dev |
|
|
|