In this article I’ll show you how to compile an OpenSceneGraph (OSG) C++ project and open it with Qt creator under Ubuntu 13.10 or 13.04.
I’m going to assume that the OSG has been installed on a location known to your system. If you have problems installing the most stable release you can try the following three commands:
1 2 3 |
sudo apt-get build-dep openscenegraph sudo apt-get install libopenscenegraph-dev openscenegraph sudo apt-get install openscenegraph-doc openscenegraph-examples gxine xine-ui libxine1-doc |
Make sure you have a recent version of cmake ( > 2.6)
First create an empty directory for the new OSG project, enter the directory and create an empty CMakeLists.txt file.
1 2 3 |
mkdir osg_project cd osg_project gedit CMakeLists.txt |
Copy the following lines into the empty file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Set the name of the project and target: SET(TARGET "name_of_main_file") #Declare all source files the target consists of: SET(TARGET_SRC ${TARGET}.cpp #You can specify additional files here! ) cmake_minimum_required( VERSION 2.6 ) project( ${TARGET} ) find_package( OpenThreads ) find_package( osg ) find_package( osgDB ) find_package( osgUtil ) find_package( osgViewer ) macro( config_project PROJNAME LIBNAME ) include_directories( ${${LIBNAME}_INCLUDE_DIR} ) target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARY} ) endmacro() add_executable( ${TARGET} ${TARGET_SRC} ) config_project( ${TARGET} OPENTHREADS ) config_project( ${TARGET} OSG ) config_project( ${TARGET} OSGDB ) config_project( ${TARGET} OSGUTIL ) config_project( ${TARGET} OSGVIEWER ) |
The only parameter that need to be changed for every project is the name_of_main_file.cpp, which should be given without the suffix *.cpp
Before running the cmake you need to create file name_of_main_file.cpp which can be empty.
You can run cmake from the command line but here I’ll do it from Qt creator.
From Qt creator choose File->Open File or Project
Go to the directory you just created and pick the CMakeLists.txt file
This will launch the cmake wizard. In the first step you define the build location. By default this directory is different than the one created above. It is ok to use the same directory if you don’t build the project for different configurations.
Click Next and on the next step click Run CMake to configure the project.
Now you can start editing the name_of_main_file.cpp to create you OSG scene.
Qt creator should be able to provide autocompletion and suggestions for all the OSG classes.