Skip to content

Open scene graph

Simulation

OpenSceneGraph (OSG) is an open-source 3D graphics toolkit written in C++, built on top of OpenGL. It provides a high-level scene graph abstraction for building, rendering, and managing complex 3D scenes efficiently.

Common use case

Area Description
Simulation & Training Flight simulators, military simulators, driving trainers
Scientific Visualization Displaying large 3D datasets or terrains
Geospatial Systems Used by osgEarth to render real-world maps and terrain
Virtual Reality (VR) Basis for immersive 3D visualization
Game Engines / Tools Lightweight base for building visualization or engine tools

Install

1
2
3
4
5
6
7
8
git clone https://github.com/openscenegraph/OpenSceneGraph.git
cd OpenSceneGraph
mkdir build
cd build
cmake ..
make
sudo make install
suod ldconfig

Demo

#include <osgViewer/Viewer>
#include <osg/ShapeDrawable>

int main() {
    osg::ref_ptr<osg::Group> root = new osg::Group();
    root->addChild(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0,0,0), 1.0)));

    osgViewer::Viewer viewer;
    viewer.setSceneData(root);
    return viewer.run();
}
cmake_minimum_required(VERSION 3.10)
project(SimpleOSGApp)

set(CMAKE_CXX_STANDARD 17)

find_package(OpenSceneGraph REQUIRED COMPONENTS osg osgDB osgUtil osgViewer)

# Create executable
add_executable(osg_example hello.cpp)

# Link OSG libraries
target_link_libraries(osg_example
    PRIVATE
        osg
        osgDB
        osgUtil
        osgViewer
)

Learn path create by chatGPT

Each week builds on the previous one. For each topic, I’ve included:

  • πŸŽ“ Concepts β€” what you’ll learn
  • πŸ’» Practice Goals β€” what you’ll implement
  • πŸ“š Resources β€” where to learn more

πŸ—“οΈ Week 1 – Setup & Core Concepts

Goal: Understand what OSG is, how it organizes scenes, and render your first object.

πŸŽ“ Concepts - Scene graph structure (Nodes, Groups, Geodes) - Viewer and event loop (osgViewer::Viewer) - Geometry, Drawables, and simple shapes - Installing OSG and using CMake with VSCode

πŸ’» Practice

  • βœ… Install OSG (sudo apt install libopenscenegraph-dev)
  • βœ… Build your first program (sphere example)
  • βœ… Add multiple shapes (cube + sphere + cone)
  • βœ… Use osg::Group to attach nodes
  • βœ… Experiment with osgViewer::Viewer::run()

πŸ“š Resources

OSG Wiki – Getting Started


πŸ—“οΈ Week 2 – Transforms & Cameras

Goal: Learn to position objects and control the camera.

πŸŽ“ Concepts

  • Transform nodes (osg::MatrixTransform)
  • Local vs global coordinates
  • Orbit manipulator (osgGA::OrbitManipulator)
  • Camera node (osg::Camera)

πŸ’» Practice

  • βœ… Move an object using MatrixTransform
  • βœ… Animate a rotation using osg::AnimationPathCallback
  • βœ… Add a camera and control with mouse (OrbitManipulator)
  • βœ… Play with setHomeViewpoint() to set default view

πŸ“š Resources

Example: examples/osganimationpath

Camera Manipulators Doc


πŸ—“οΈ Week 3 – Models, Materials & Lighting

Goal: Load real 3D models and make your scene look realistic.

πŸŽ“ Concepts

  • Loading models (osgDB::readNodeFile)
  • Materials, textures, and lights
  • StateSets (managing OpenGL state)
  • Shaders overview

πŸ’» Practice

  • βœ… Load a .obj or .osgb model
  • βœ… Add texture using osg::Texture2D
  • βœ… Add a light source (osg::LightSource)
  • βœ… Adjust materials via osg::Material

πŸ“š Resources

  • Example: examples/osglight
  • Example: examples/osgshadercomp
  • Book: Beginner’s Guide Ch. 4–6

πŸ—“οΈ Week 4 – Interaction & Events

Goal: Make the scene respond to input.

πŸŽ“ Concepts

  • Event handlers (osgGA::GUIEventHandler)
  • Keyboard and mouse input
  • Picking (selecting objects with mouse)
  • Callbacks (update, cull, draw)

πŸ’» Practice

  • βœ… Create a custom event handler for key presses
  • βœ… Implement simple object movement (e.g., arrow keys to move)
  • βœ… Add text overlay using osgText::Text
  • βœ… Implement a basic β€œobject picker”

πŸ“š Resources


πŸ—“οΈ Week 5 – Performance & Advanced Features

Goal: Understand optimization and advanced scene graph concepts.

πŸŽ“ Concepts

  • Level of Detail (osg::LOD)
  • Culling and bounding volumes
  • Paging (loading large datasets dynamically)
  • Multithreaded rendering overview
  • Using shaders (GLSL in OSG)

πŸ’» Practice

  • βœ… Create LOD nodes for distant objects
  • βœ… Visualize bounding boxes (osg::BoundingBox)
  • βœ… Try replacing default shader with custom GLSL
  • βœ… Explore example: osgmultitexture

πŸ“š Resources

  • Example: examples/osglod
  • OSG Rendering Optimization

πŸ—“οΈ Week 6 – Integration & osgEarth

Goal: Combine what you learned and build a mini-project.

πŸŽ“ Concepts

  • osgEarth basics (MapNode, ImageLayer, ElevationLayer)
  • Adding UI (Qt or ImGui optional)
  • Combining 3D models + terrain
  • Exporting and saving scenes

πŸ’» Practice

  • βœ… Install osgEarth (sudo apt install osgEarth)
  • βœ… Load OpenStreetMap base layer
  • βœ… Add a model (e.g., aircraft or robot) at specific lat/lon
  • βœ… Use OrbitManipulator to explore the map
  • βœ… Export scene with osgDB::writeNodeFile()

πŸ“š Resources

  • osgEarth GitHub: https://github.com/gwaldron/osgearth

🧩 Optional Weeks (7+)

  • Week 7 β†’ integrate with Qt GUI (using osgQt::GLWidget)
  • Week 8 β†’ build plugin or viewer utility
  • Week 9 β†’ add VR support (OpenVR / Oculus)
  • Week 10 β†’ integrate with ROS 2 or simulation data (e.g., real sensor visualization)

Reference