openscenegraph-cross-platform-examples icon indicating copy to clipboard operation
openscenegraph-cross-platform-examples copied to clipboard

OpenSceneGraph cross-platform examples: specific things you can do with OSG across platforms

Table of contents

  • Overview
  • Libraries
  • Building
    • Desktop
    • Android
    • iOS
    • Web
  • Examples
    • 01. Embed resource into executable
    • 02. Use PNG images with PNG plugins
    • 03. Implement HTTP client to perform GET/POST requests
    • 04. Debug application remotely
    • 05. Node selection
    • 06. Command sequence
  • Help

Overview

OpenSceneGraph is an open source high performance 3D graphics toolkit, used by application developers in fields such as visual simulation, games, virtual reality, scientific visualization and modelling.

This document is a logical continuation of OpenSceneGraph cross-platform guide. Here you'll find a collection of examples to perform specific tasks.

Examples run on the following platforms:

  • Linux
  • macOS
  • Android
  • iOS
  • Web

Note: Windows builds have not yet been tested.

Libraries

Each example uses OpenSceneGraph. OpenSceneGraph is built as part of each example: examples don't use OpenSceneGraph libraries built separately, instead each example includes OpenSceneGraph sources directly. This was necessary to simplify building OpenSceneGraph across platforms. Here's custom CMakeLists.txt we use to build OpenSceneGraph across platforms (excluding iOS).

Certain examples use other libraries like Mongoose and libpng-android to achieve specific functionality. Those libraries are part of corresponding examples, too.

Building

Each example contains four implementations to cover all supported platforms:

  • desktop (Linux, macOS, Windows)
  • android
  • ios
  • web

Let's see how to build the first example for each platform.

Notes:

  • you must have OpenSceneGraph sources alongside this repository
  • you must have mongoose, libpng-android sources alongside this repository, too, for certain examples

Desktop

To build the first example, run the following commands:

cd 01.EmbedResource/desktop
mkdir build
cd build
cmake ..
make

Screenshot

To launch the first example, run the following command:

./ex01-embed-resource

Android

Screenshot

Notes:

  • Android project is built for armeabi-v7a architecture by default
    • update abiFilters value in android/app/build.gradle if you want other platforms
  • make sure to run Tools -> Android -> Sync Project with Gradle Files in Android Studio after opening a project, this is necessary for Android Studio to create internal project files

To build and run the first example for Android, open 01.EmbedResource/android in Android Studio and run the project.

iOS

Screenshot

To build and run the first example for iOS, open 01.EmbedResource/ios/ex01.xcodeproj in Xcode and run the project.

Web

To build the first example for web, run the following commands:

cd 01.EmbedResource/web
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emscripten/<version>/cmake/Modules/Platform/Emscripten.cmake ..
make

Notes:

  • you must have Emscripten installed (see Emscripten documentation for details)
  • make sure to specify path to Emscripten's CMake toolchain file

Screenshot

To launch the first example, open ex01-embed-resource.html file in Firefox.

To launch the example in any web browser, you need to serve example files with a web server.

Serving example with Python web server

If you have have Python installed, here's what you need to do:

  • serve example with a web server:

    cd 01.EmbedResource/web/build
    python -m SimpleHTTPServer
    
  • open http://localhost:8000 in any web browser

  • select ex01-embed-resource.html file

Examples

01. Embed resource into executable

Screenshot

Learn how to embed a binary resource into application with xxd Unix utility and use the resource across platforms.

02. Use PNG images with PNG plugins

Screenshot

Learn how to use PNG images across platforms with PNG plugins.

03. Implement HTTP client to perform GET/POST requests

Screenshot

Learn how to implement HTTP client across platforms to perform GET/POST requests.

04. Debug application remotely

Screenshot

Learn how to work with debug-broker to perform remote debugging.

05. Node selection

Screenshot

Learn how to select a node.

06. Command sequence

Screenshot

Learn how to compose a sequence of asynchronous commands to combine animations with other operations.

Help

Feel free to ask questions in the issues. Your questions help us improve examples.