OpenSceneGraph 3.0

Book description

This book is a concise introduction to the main features of OpenSceneGraph which then leads you into the fundamentals of developing virtual reality applications. Practical instructions and explanations accompany you every step of the way.

  • Gain a comprehensive view of the structure and main functionalities of OpenSceneGraph
  • An ideal introduction for developing applications using OpenSceneGraph
  • Develop applications around the concepts of scene graphs and design patterns
  • Extend your own scene elements from the base interfaces of OpenSceneGraph
  • Packed with examples, this book explains each knowledge point in detail and makes you practice your knowledge for better understanding

In Detail

Virtual reality has quite a lot of demand in computer science today and OpenSceneGraph, being one of the best 3D graphics toolkits, is being used widely. Although you can use the powerful OpenSceneGraph, based on the low-level OpenGL API, to implement virtual-reality applications that simulate different environments in the 3D world, developing picture-perfect applications is easier said than done.

This book has been written with the goal of helping readers become familiar with the structure and main functionalities of OpenSceneGraph (OSG), and guide them to develop virtual-reality applications using this powerful 3D graphics engine. This book covers the essence of OpenSceneGraph (OSG), providing programmers with detailed explanations and examples of scene graph APIs.

This book helps you take full advantages of the key features and functionalities of OpenSceneGraph (OSG). You will learn almost all of the core elements required in a virtual reality application, including memory management, geometry creation, the structure of the scene graph, realistic rendering effects, scene navigation, animation, interaction with input devices and external user interfaces, file reading and writing, and so on.

With the essential knowledge contained in this book, you will be able to start using OSG in your own projects and research fields, and extend its functionalities by referring to OSG's source code, official examples and API documentation.

This handy book divides the core functionalities of the proved and comprehensive OpenSceneGraph (OSG) 3D graphics engine into different aspects, which are introduced in separate chapters. Each chapter can be treated as an individual part that covers one important field of OSG programming, along with several examples illustrating concrete usages and solutions. But the sequence of chapters is also organized from the easy to the more difficult, to help you get to grips with OSG.

By the end of the whole book, you will have gained a ready-to-use OSG development environment for yourself and have the general ability to develop OSG-based applications and extend practical functionalities for your own purposes.

With plenty of examples to get you started quickly, you'll master developing with OpenSceneGraph in no time, the 3D graphics engine based on OpenGL

Table of contents

  1. OpenSceneGraph 3.0
    1. Table of Contents
    2. OpenSceneGraph 3.0
    3. Credits
    4. Foreword
    5. About the Authors
    6. Acknowledgement
    7. About the Reviewers
    8. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    9. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Time for action—heading
        1. What just happened?
        2. Pop quiz—heading
        3. Have a go hero—heading
      6. Reader feedback
      7. Customer support
        1. Errata
        2. Piracy
        3. Questions
    10. 1. The Journey into OpenSceneGraph
      1. A quick overview of rendering middleware
      2. Scene graphs
      3. The Birth and development of OSG
      4. Components
      5. Why OSG?
      6. Who uses OSG?
      7. Have a quick taste
      8. Time for action—say "Hello World" OSG style
        1. What just happened?
      9. Live in community
      10. Summary
    11. 2. Compilation and Installation of OpenSceneGraph
      1. System requirements
      2. Using the installer
      3. Time for action—installing OSG
        1. What just happened?
      4. Running utilities
      5. Time for action—playing with osgviewer
        1. What just happened?
        2. Pop quiz—dependencies of osgviewer
        3. Have a go hero—playing with osgconv
      6. Using the project wizard
      7. Time for action—creating your solution with one click
        1. What just happened?
        2. Have a go hero—constructing "Hello World" with the wizard
      8. Prebuilts making trouble?
      9. Cross-platform building
      10. Starting CMake
      11. Time for action—running CMake in GUI mode
        1. What just happened?
      12. Setting up options
      13. Generating packages using Visual Studio
      14. Time for action—building with a Visual Studio solution
        1. What just happened?
        2. Pop quiz—the difference between ALL_BUILD and 'build all'
      15. Generating packages using gcc
      16. Time for action—building with a UNIX makefile
        1. What just happened?
        2. Have a go hero—checking mis-compiled parts
      17. Configuring environment variables
      18. Summary
    12. 3. Creating Your First OSG Program
      1. Constructing your own projects
      2. Time for action—building applications with CMake
        1. What just happened?
        2. Pop quiz—configuring OSG path options yourselves
        3. Have a go hero—testing with different generators
      3. Using a root node
      4. Time for action—improving the "Hello World" example
        1. What just happened?
      5. Understanding memory management
      6. ref_ptr<> and Referenced classes
      7. Collecting garbage: why and how
      8. Tracing the managed entities
      9. Time for action—monitoring counted objects
        1. What just happened?
        2. Have a go hero—returning from a function
        3. Pop quiz—release a smart pointer
      10. Parsing command-line arguments
      11. Time for action—reading the model filename from the command line
        1. What just happened?
      12. Tracing with the notifier
      13. Redirecting the notifier
      14. Time for action—saving the log file
        1. What just happened?
      15. Summary
    13. 4. Building Geometry Models
      1. How OpenGL draws objects
      2. Geode and Drawable classes
      3. Rendering basic shapes
      4. Time for action—quickly creating simple objects
        1. What just happened?
      5. Storing array data
      6. Vertices and vertex attributes
      7. Specifying drawing types
      8. Time for action—drawing a colored quad
        1. What just happened?
        2. Pop quiz—results of different primitive types
      9. Indexing primitives
      10. Time for action—drawing an octahedron
        1. What just happened?
        2. Pop quiz—optimizing indexed geometries
        3. Have a go hero—challenges with cubes and pyramids
      11. Using polygonal techniques
      12. Time for action—tessellating a polygon
        1. What just happened?
      13. Rereading geometry attributes
      14. Customizing a primitive functor
      15. Time for action—collecting triangle faces
        1. What just happened?
        2. Have a go hero—analyzing topology of a geometry
      16. Implementing your own drawables
      17. Using OpenGL drawing calls
      18. Time for action—creating the famous OpenGL teapot
        1. What just happened?
      19. Summary
    14. 5. Managing Scene Graph
      1. The Group interface
      2. Managing parent nodes
      3. Time for action—adding models to the scene graph
        1. What just happened?
        2. Pop quiz—fast dynamic casting
      4. Traversing the scene graph
      5. Transformation nodes
      6. Understanding the matrix
      7. The MatrixTransform class
      8. Time for action—performing translations of child nodes
        1. What just happened?
        2. Pop quiz—matrix multiplications
        3. Have a go hero—making use of the PositionAttitudeTransform class
      9. Switch nodes
      10. Time for action—switching between the normal and damaged Cessna
        1. What just happened?
      11. Level-of-detail nodes
      12. Time for action—constructing a LOD Cessna
        1. What just happened?
      13. Proxy and paging nodes
      14. Time for action—loading a model at runtime
        1. What just happened?
        2. Have a go hero—working with the PagedLOD class
      15. Customizing your own NodeKits
      16. Time for action—animating the switch node
        1. What just happened?
        2. Have a go hero—creating a tracker node
      17. The visitor design pattern
      18. Visiting scene graph structures
      19. Time for action—analyzing the Cessna structure
        1. What just happened?
      20. Summary
    15. 6. Creating Realistic Rendering Effects
      1. Encapsulating the OpenGL state machine
      2. Attributes and modes
      3. Time for action—setting polygon modes of different nodes
        1. What just happened?
      4. Inheriting render states
      5. Time for action—lighting the glider or not
        1. What just happened?
      6. Playing with fixed-function effects
      7. Time for action—applying simple fog to models
        1. What just happened?
        2. Have a go hero—searching for more effects
      8. Lights and light sources
      9. Time for action—creating light sources in the scene
        1. What just happened?
        2. Pop quiz—lights without sources
      10. The Image class
      11. The basis of texture mapping
      12. Time for action—loading and applying 2D textures
        1. What just happened?
        2. Have a go hero—making use of filters and wrapping modes
      13. Handling rendering order
      14. Time for action—achieving the translucent effect
        1. What just happened?
      15. Understanding graphics shaders
      16. Using uniforms
      17. Time for action—implementing a cartoon cow
        1. What just happened?
        2. Pop quiz—replacements of built-in uniforms
        3. Have a go hero—setting vertex attributes to shaders
      18. Working with the geometry shader
      19. Time for action—generating a Bezier curve
        1. What just happened?
        2. Have a go hero—having fun with shaders
      20. Summary
    16. 7. Viewing the World
      1. From world to screen
      2. The Camera class
      3. Rendering order of cameras
      4. Time for action—creating an HUD camera
        1. What just happened?
        2. Pop quiz—changing model positions in the HUD camera
      5. Using a single viewer
      6. Digging into the simulation loop
      7. Time for action—customizing the simulation loop
        1. What just happened?
        2. Have a go hero—viewing in a non-full screen window
      8. Using a composite viewer
      9. Time for action—rendering more scenes at one time
        1. What just happened?
        2. Have a go hero—different views of the same scene
        3. Pop quiz—another way to display the same scene in different views
      10. Changing global display settings
      11. Time for action—enabling global multisampling
        1. What just happened?
      12. Stereo visualization
      13. Time for action—rendering anaglyph stereo scenes
        1. What just happened?
      14. Rendering to textures
      15. Frame buffer, pixel buffer, and FBO
      16. Time for action—drawing aircrafts on a loaded terrain
        1. What just happened?
        2. Have a go hero—saving scene to an image file
      17. Summary
    17. 8. Animating Scene Objects
      1. Taking references to functions
      2. List of callbacks
      3. Time for action—switching nodes in the update traversal
        1. What just happened?
        2. Pop quiz—adding or setting callbacks
      4. Avoiding conflicting modifications
      5. Time for action—drawing a geometry dynamically
        1. What just happened?
        2. Have a go hero—dirtying geometry objects
      6. Understanding ease motions
      7. Animating the transformation nodes
      8. Time for action—making use of the animation path
        1. What just happened?
        2. Have a go hero—more controls over the animation path
      9. Changing rendering states
      10. Time for action—fading in
        1. What just happened?
        2. Pop quiz—choosing the alpha setter and the callback
        3. Have a go hero—animating in graphics shaders
      11. Playing movies on textures
      12. Time for action—rendering a flashing spotlight
        1. What just happened?
      13. Creating complex key-frame animations
      14. Channels and animation managers
      15. Time for action—managing animation channels
        1. What just happened?
      16. Loading and rendering characters
      17. Time for action—creating and driving a character system
        1. What just happened?
        2. Have a go hero—analyzing the structure of your character
      18. Summary
    18. 9. Interacting with Outside Elements
      1. Various events
      2. Handling mouse and keyboard inputs
      3. Time for action—driving the Cessna
        1. What just happened?
        2. Pop quiz—handling events within nodes
        3. Have a go hero—manipulating the cameras
      4. Adding customized events
      5. Time for action—creating a user timer
        1. What just happened?
        2. Pop quiz—global and node-related events
      6. Picking objects
      7. Intersection
      8. Time for action—clicking and selecting geometries
        1. What just happened?
        2. Have a go hero—selecting geometries in a rectangular region
      9. Windows, graphics contexts, and cameras
      10. The Traits class
      11. Time for action—configuring the traits of a rendering window
        1. What just happened?
      12. Integrating OSG into a window
      13. Time for action—attaching OSG with a window handle in Win32
        1. What just happened?
        2. Have a go hero—embedding into GUI systems
      14. Summary
    19. 10. Saving and Loading Files
      1. Understanding file I/O plugins
      2. Discovery of specified extension
      3. Supported file formats
      4. The pseudo-loader
      5. Time for action—reading files from the Internet
        1. What just happened?
        2. Pop quiz—getting rid of pseudo-loaders
      6. Configuring third-party dependencies
      7. Time for action—adding libcurl support for OSG
        1. What just happened?
        2. Have a go hero—adding FreeType support for OSG
      8. Writing your own plugins
      9. Handling the data stream
      10. Time for action—designing and parsing a new file format
        1. What just happened?
        2. Have a go hero—finishing the writing interface of the plugin
      11. Serializing OSG native scenes
      12. Creating serializers
      13. Time for action—creating serializers for user-defined classes
        1. What just happened?
        2. Pop quiz—understanding the inheritance relations
        3. Have a go hero—adding more serializers
      14. Summary
    20. 11. Developing Visual Components
      1. Creating billboards in a scene
      2. Time for action—creating banners facing you
        1. What just happened?
        2. Have a go hero—planting massive trees on the ground
      3. Creating texts
      4. Time for action—writing descriptions for the Cessna
        1. What just happened?
        2. Pop quiz—text positions and the projection matrix
        3. Have a go hero—using wide characters to support more languages
      5. Creating 3D texts
      6. Time for action—creating texts in the world space
        1. What just happened?
      7. Creating particle animations
      8. Time for action—building a fountain in the scene
        1. What just happened?
        2. Have a go hero—designing a rotary sprinkler
      9. Creating shadows on the ground
      10. Time for action—receiving and casting shadows
        1. What just happened?
        2. Have a go hero—testing other shadow techniques
      11. Implementing special effects
      12. Time for action—drawing the outline of models
        1. What just happened?
      13. Playing with more NodeKits
      14. Summary
    21. 12. Improving Rendering Efficiency
      1. OpenThreads basics
      2. Time for action—using a separate data receiver thread
        1. What just happened?
        2. Pop quiz—carefully blocking threads
      3. Understanding multithreaded rendering
      4. Time for action—switching between different threading models
        1. What just happened?
      5. Dynamic scene culling
      6. Occluders and occludees
      7. Time for action—adding occluders to a complex scene
        1. What just happened?
        2. Have a go hero—adding holes to the occluder
      8. Improving your application
      9. Time for action—sharing textures with a customized callback
        1. What just happened?
        2. Have a go hero—sharing public models
      10. Paging huge scene data
      11. Making use of the quad-tree
      12. Time for action—building a quad-tree for massive rendering
        1. What just happened?
        2. Pop quiz—number of created levels and files
        3. Have a go hero—testing a new terrain creation tool
      13. Summary
    22. A. Pop quiz—Answers
      1. Chapter 2
        1. Dependencies of osgviewer
        2. The difference between ALL_BUILD and 'build all'
      2. Chapter 3
        1. Configuring OSG path options yourselves
        2. Release a smart pointer
      3. Chapter 4
        1. Results of different primitive types
        2. Optimizing indexed geometries
      4. Chapter 5
        1. Fast dynamic casting
        2. Matrix multiplications
      5. Chapter 6
        1. Lights without sources
        2. Replacements of built-in uniforms
      6. Chapter 7
        1. Changing model positions in the HUD camera
        2. Another way to display the same scene in different views
      7. Chapter 8
        1. Adding or setting callbacks
        2. Choosing the alpha setter and the callback
      8. Chapter 9
        1. Handling events within nodes
        2. Global and node-related events
      9. Chapter 10
        1. Getting rid of pseudo-loaders
        2. Understanding the inheritance relations
      10. Chapter 11
        1. Text positions and the projection matrix
      11. Chapter 12
        1. Carefully blocking threads
        2. Number of created levels and files
    23. Index

Product information

  • Title: OpenSceneGraph 3.0
  • Author(s): Rui Wang, Xuelei Qian
  • Release date: December 2010
  • Publisher(s): Packt Publishing
  • ISBN: 9781849512824