OpenSceneGraph Quick Start Guide A Quick Introduction to the Cross-Platform Open Source Scene Graph APl Paul Martz SKEW MATRIX S O F T W A R E
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 lowa State University. Back cover top two images 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 Skew Matrix Software LLC 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 Marts and Skew Matrix Sofvare LLCand lcense 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
Front cover image courtesy of Professor Mark Bryden and VRAC at Iowa State University. Back cover top two images 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 Skew Matrix Software LLC 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 new to scene graφh technolog
This book is dedicated to all developers new to scene graph technology
Contents Preface....... Acknowledgements.… iⅸ 1 An Overview of Scene Graphs and OpenSceneGraph...................1 1./History of OpenSceneGraph.. 1 1.2 Installing OSG...... 3 1.2./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 6 1.3Running 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......... 4.10 1.4 Compiling OSG Applications... .11 1.5 Introduction to Scene Graphs ..13 1.5./Scene Graph Features....... .14 1.5.2 How Scene Graphs Render... 15 1.6 Overview of OpenSceneGraph 17 1.6./Design and Architecture.... .17 1.6.2 Naming Conventions.. 18 1.6.3 Components.… 18 2 Building a Scene Graph................ 31 OpenSceneGraph Quick Start Guide
OpenSceneGraph Quick Start Guide i Contents Preface.................................................................................................... v Acknowledgements ................................................................................ ix 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....................................................................................6 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.5 Introduction to Scene Graphs ...............................................................................................13 1.5.1 Scene Graph Features.....................................................................................................14 1.5.2 How Scene Graphs Render ...........................................................................................15 1.6 Overview of OpenSceneGraph .............................................................................................17 1.6.1 Design and Architecture.................................................................................................17 1.6.2 Naming Conventions......................................................................................................18 1.6.3 Components.....................................................................................................................18 2 Building a Scene Graph.................................................................31
Contents 2./Memory Management ..... 31 2.1./The Referenced Class..... 33 2.1.2 The ref_ptr<>Template Class 34 2.1.3 Memory Management Examples............... 34 2.2 Geodes and Geometry...... .36 2.2.1 An Overview of Geometry Classes. 40 2.3 Group Nodes.. .44 2.3./The Child Interface 44 2.3.2The Parent Interface 45 2.3.3Transform Nodes............. .46 2.3.4The LOD Node............. 50 2.3.5The Switch Node.... 51 2.4 Rendering State.… 53 2.4./Attributes and Modes ............. 54 2.4.2State Inheritance..... 56 2.4.3 Example Code for Setting State 57 2Texture Mapping..... 61 2.4.51 ighting… 64 2.5 File I/O.. 69 2.5.1 Interface… …70 2.5.2 Plugin Discovery and Registration .71 2.6 NodeKits and osgText............ 72 2.6./osgText Components..... 73 2.6.2 Using osgText.… 73 2.6.3 Text Example Code... 77 2.6.4 The .osg File Format.... 78 3 Using OpenSceneGraph in Your Application......................83 3./Rendering... 83 3.1./The Viewer Class.................. 84 3.1.2 SimpleViewer and CompositeViewer. 87 3.2 Dynamic Modification............ 88 3.2.1 Data Variance..… 88 322Cabacks89 3.2 NOde ViSitOrS94 3.2.4 Picking.… .95 Appendix:Where to Go From Here............103
ii Contents 2.1 Memory Management ............................................................................................................ 31 2.1.1 The Referenced Class..................................................................................................... 33 2.1.2 The ref_ptr<> Template Class .................................................................................... 34 2.1.3 Memory Management Examples.................................................................................. 34 2.2 Geodes and Geometry ........................................................................................................... 36 2.2.1 An Overview of Geometry Classes.............................................................................. 40 2.3 Group Nodes........................................................................................................................... 44 2.3.1 The Child Interface ........................................................................................................ 44 2.3.2 The Parent Interface ...................................................................................................... 45 2.3.3 Transform Nodes........................................................................................................... 46 2.3.4 The LOD Node.............................................................................................................. 50 2.3.5 The Switch Node............................................................................................................ 51 2.4 Rendering State ....................................................................................................................... 53 2.4.1 Attributes and Modes .................................................................................................... 54 2.4.2 State Inheritance............................................................................................................. 56 2.4.3 Example Code for Setting State ................................................................................... 57 2.4.4 Texture Mapping ............................................................................................................ 61 2.4.5 Lighting............................................................................................................................ 64 2.5 File I/O.................................................................................................................................... 69 2.5.1 Interface........................................................................................................................... 70 2.5.2 Plugin Discovery and Registration............................................................................... 71 2.6 NodeKits and osgText ........................................................................................................... 72 2.6.1 osgText Components..................................................................................................... 73 2.6.2 Using osgText ................................................................................................................. 73 2.6.3 Text Example Code ....................................................................................................... 77 2.6.4 The .osg File Format...................................................................................................... 78 3 Using OpenSceneGraph in Your Application.................................83 3.1 Rendering................................................................................................................................. 83 3.1.1 The Viewer Class............................................................................................................ 84 3.1.2 SimpleViewer and CompositeViewer .......................................................................... 87 3.2 Dynamic Modification............................................................................................................ 88 3.2.1 Data Variance.................................................................................................................. 88 3.2.2 Callbacks.......................................................................................................................... 89 3.2.3 NodeVisitors................................................................................................................... 94 3.2.4 Picking.............................................................................................................................. 95 Appendix: Where to Go From Here .....................................................103