OpenSceneGraph
Quick Start Guide
A Quick Introduction to the
Cross-Platform Open Source
Scene Graph API
Paul Martz
Front cover image courtesy of Professor Mark Bryden and VRAC at Iowa State
University.
Back cover top two images were generated with 3DNature's NatureViewExpress and
Visual Nature Studio with Scene Express.
Back cover bottom image courtesy of Andes Computer Engineering.
The author and publisher have taken care in the publication of this book, but make no expressed
or implied warranty of any kind and assume no responsibility for errors or omissions. No liability
is assumed for any damages arising out of the use of the information or programs contained
herein.
Many of the designations used by manufacturers and sellers to designate their products are
claimed as trademarks. Where the designations appear in this manual and the author was aware of
a trademark claim, the designations have been printed with initial capital letters or in all capitals.
OpenSceneGraph Quick Start Guide
Copyright © 2007 Computer Graphics Systems Development Corporation, Mountain View,
California. Reproduced by permission.
Preparation of this manuscript was in part sponsored by the United States Air Force under
Contract No.: FA8650-05-C-6537.
This book is protected by the Creative Commons Attribution-NonCommercial-ShareAlike 2.0
license. You may copy, distribute, transmit, and alter this work for non-commercial purposes
provided you attribute the work to Paul Martz and Skew Matrix Software LLC and license any
altered or derivative works under similar terms. For more information, view the following URL:
http://creativecommons.org/licenses/by-nc-sa/2.0/
For inquiries regarding exceptions to this license, please contact the author and publisher:
Paul Martz
Skew Matrix Software LLC
284 W. Elm St.
Louisville, CO 80027 USA
pmartz@skew-matrix.com
This book is dedicated to all developers who are new to
scene graph technology.
Contents
Preface ............................................................................................... ix
Acknowledgements............................................................................xiii
1
An Overview of Scene Graphs and OpenSceneGraph................1
1.1 History of OpenSceneGraph ..............................................................................................1
1.2 Installing OSG ......................................................................................................................3
1.2.1 Hardware Requirements..............................................................................................4
1.2.2 Apple Mac OS X ..........................................................................................................4
1.2.3 Fedora Linux.................................................................................................................4
1.2.4 Microsoft Windows......................................................................................................5
1.2.5 Verifying Your OSG Installation ...............................................................................5
1.3 Running osgviewer ...............................................................................................................6
1.3.1 Getting Help .................................................................................................................7
1.3.2 Display Modes ..............................................................................................................8
1.3.3 Environment Variables................................................................................................8
1.3.4 Statistics Display...........................................................................................................9
1.3.5 Recording an Animation ...........................................................................................10
1.4 Compiling OSG Applications ...........................................................................................11
1.4.1 Apple Mac OS X ........................................................................................................11
1.4.2 Fedora Linux...............................................................................................................11
1.4.3 Microsoft Visual Studio.............................................................................................12
1.5 Introduction to Scene Graphs ..........................................................................................13
1.5.1 Scene Graph Features................................................................................................14
1.5.2 How Scene Graphs Render.......................................................................................16
1.6 Overview of OpenSceneGraph ........................................................................................17
1.6.1 Design and Architecture............................................................................................18
1.6.2 Naming Conventions.................................................................................................19
1.6.3 Components................................................................................................................19
OpenSceneGraph Quick Start Guide
v
vi
Contents
Building a Scene Graph............................................................. 31
2
2.1 Memory Management ........................................................................................................31
2.1.1 The Referenced Class.................................................................................................34
2.1.2 The ref_ptr<> Template Class ................................................................................34
2.1.3 Memory Management Examples..............................................................................35
2.2 Geodes and Geometry .......................................................................................................38
2.2.1 An Overview of Geometry Classes..........................................................................38
2.3 Group Nodes.......................................................................................................................38
2.3.1 The Child Interface ....................................................................................................38
2.3.2 The Parent Interface ..................................................................................................38
2.3.3 Transform Nodes.......................................................................................................38
2.3.4 The LOD Node..........................................................................................................38
2.3.5 The Switch Node........................................................................................................38
2.4 Rendering State ...................................................................................................................38
2.4.1 Attributes and Modes ................................................................................................38
2.4.2 State Inheritance.........................................................................................................38
2.4.3 Example Code for Setting State ...............................................................................38
2.4.4 Texture Mapping ........................................................................................................38
2.4.5 Lighting........................................................................................................................38
2.5 File I/O................................................................................................................................38
2.5.1 Interface.......................................................................................................................38
2.5.2 Plugin Discovery and Registration...........................................................................38
2.6 NodeKits and osgText .......................................................................................................38
2.6.1 osgText Components.................................................................................................38
2.6.2 Using osgText .............................................................................................................38
2.6.3 Text Example Code ...................................................................................................38
2.6.4 The .osg File Format..................................................................................................38
3 Using OpenSceneGraph in Your Application............................. 38
3.1 Rendering.............................................................................................................................38
3.1.1 The Viewer Class........................................................................................................38
3.1.2 CompositeViewer.......................................................................................................38
3.2 Dynamic Modification........................................................................................................38
3.2.1 Data Variance..............................................................................................................38
3.2.2 Callbacks......................................................................................................................38
3.2.3 NodeVisitors...............................................................................................................38
3.2.4 Picking..........................................................................................................................38
OpenSceneGraph Quick Start Guide
vii
Appendix: Where to Go From Here ...................................................38
Glossary.............................................................................................38
Bibliography .......................................................................................38
Index ..................................................................................................38
Revision History.................................................................................38
vii