Precondition

  • OSG library has been built in x32 or x64
  • OSG Example data has been downloaded.
  • assuming OSGPATH is setting as D:\OSG
    • include - D:\OSG\include
    • lib - D:\OSG\lib
    • bin - D:\OSG\bin
    • data - D:\OSG\data
  • System environment has been set corroctly
    • PATH - add D:\OSG\bin to PATH
    • OSG_FILE_PATH - create this key with value D:\OSG\data

Overview

Normally you can find many instructions to say “Hello World” in OSG style.
It should look like following steps:

  1. Create a empty win32 console application.
  2. Add OSG lib to project properties.
  3. Add codes to show a 3D model.
  4. Compile and run application.

Create Project

Create an empty win32 console appliction project.

Create new project

file -> new -> project…
select -> Win32 -> Win32 Console Application -> OK

create new project

Application Settings -> check Empty project -> Finish

application settings

Configure Project Properties

project -> Properties -> VC++ Directories
Executable Directories - add D:\OSG\bin
Include Directories - add D:\OSG\include
Library Directories - add D:\OSG\lib

project properties

Notice
pay more attention to using same x64 or x86 Platform configuration!

Add Codes

Normally codes will be like this:

#ifdef _DEBUG
#pragma comment(lib, "osgViewerd.lib")
#pragma comment(lib, "osgDBd.lib")
#pragma comment(lib, "OpenThreadsd.lib")
#pragma comment(lib, "osgd.lib")
#else
#pragma comment(lib, "osgViewer.lib")
#pragma comment(lib, "osgDB.lib")
#pragma comment(lib, "OpenThreads.lib")
#pragma comment(lib, "osg.lib")
#endif

#if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
#include <windows.h>
#endif

#include <osgviewer/viewer>
#include <osgdb/readfile>

int main()
{
	osg::ref_ptr <osgViewer::Viewer> viewer = new osgViewer::Viewer;
	viewer->setSceneData(osgDB::readNodeFile("glider.osg"));
	return viewer->run();
}

Compile and Run

A 3D model should be displayed on the screen correctly.

HelloOsg run

OSG VS2015 Troubleshooting If building or running above project with problems, please check another tutorial. LEARN MORE

Leave a Comment