Skip to content

Files

Latest commit

b461191 · Jun 30, 2017

History

History

1.9.SampleUnderIOS

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 31, 2017
May 31, 2017
Jun 30, 2017

Table of contents

This tutorial is part of OpenSceneGraph cross-platform guide.

In this tutorial we build and run sample OpenSceneGraph application under iOS. The application displays provided model with simple GLSL shaders.

Note: this tutorial requires

YouTube | Download

Video depicts running and building sample OpenSceneGraph application for iOS simulator with iOS 10.

Note: steps below use frames from the video as screenshots. Watch the video to see all details.

Screenshot

Create build directory for iOS simulator build of osgNativeLib, a native C++ library to be used in Objective-C.

osgNativeLib also builds OpenSceneGraph inside /path/to/openscenegraph-cross-platform-guide-application/../OpenSceneGraph/build/Simulator.

Note: iOS simulator build only works under iOS simulator. If you need to build for a real device, you need to build osgNativeLib with BUILD_SIMULATOR=NO in a separate directory. In such a case OpenSceneGraph is built inside /path/to/openscenegraph-cross-platform-guide-application/../OpenSceneGraph/build/Device.

Screenshot

Open CMake

Screenshot

Specify build and source directories.

Screenshot

Press Configure. Select Xcode generator when prompted.

Screenshot

Press Generate to generate Xcode specific project file.

Screenshot

Build osgNativeLib and OpenSceneGraph with the following commands:

cd /path/to/build/dir

xcodebuild -IDEBuildOperationMaxNumberOfConcurrentCompileTasks=8 -configuration Release

At the end the build process combines osgNativeLib and several OpenSceneGraph libraries into single libosglib.a library. This is done for convenience.

Screenshot

Start a new Xcode project.

Screenshot

Select Single View Application.

Screenshot

Select Objective-C language and provide application specific information like title, organization, etc.

Screenshot

Select project directory and finish project creation.

Screenshot

Copy combined library into project directory with the following command:

cp /path/to/build/dir/libosglib.a /path/to/xcode/project/subdir/

Screenshot

Copy view controller and model with the following command:

cp -R /path/to/openscenegraph-cross-platform-guide-application/ios/project/* /path/to/xcode/project/subdir

Sample OpenSceneGraph application's ios/project directory contains a box model and RenderVC. RenderVC is a view controller that renders the model with osgNativeLib.

Screenshot

For Xcode to see the files, they should be added to the project.

Screenshot

Go to General project page and select RenderVC.storyboard as the main interface.

Screenshot

Since we have not added osgNativeLib headers to the project, we should reference them to be able to call osgNativeLib functions.

Go to project's Build Settings, find Header Search Paths section, then add the following search paths:

/path/to/openscenegraph-cross-platform-guide-application/ios/src

/path/to/openscenegraph-cross-platform-guide-application/ios/src-gen

Screenshot

Select iPhone simulator and run the project. You should see red cube displayed.