Book Image

OpenSceneGraph 3.0: Beginner's Guide

Book Image

OpenSceneGraph 3.0: Beginner's Guide

Overview of this book

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.
Table of Contents (22 chapters)
OpenSceneGraph 3.0
Credits
Foreword
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Real-time rendering is in quite demand in computer science today, and OpenSceneGraph, being one of the best 3D graphics toolkits, is being used widely in the fields of virtual reality, scientific visualization, visual simulation, modeling, games, mobile applications, and so on. Although you can use the powerful OpenSceneGraph, which is based on the low-level OpenGL API, to implement 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, and guiding them to develop virtual-reality applications using this powerful 3D graphics engine. This book covers the essence of OpenSceneGraph, 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. 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 OpenSceneGraph in your own projects and research fields, and extend its functionalities by referring to OpenSceneGraph's source code, official examples, and API documentation.

This handy book divides the core functionalities of the proved and comprehensive OpenSceneGraph 3D graphics engine into different aspects, which are introduced in separate chapters. Each chapter can be treated as an individual lesson that covers one important field of OpenSceneGraph programming, along with several examples illustrating concrete usages and solutions. The sequence of the chapters is organized from the easy topics to the more difficult concepts, to help you to gradually build your knowledge and skills in with OpenSceneGraph.

By the end of the whole book, you will have gained a ready-to-use OpenSceneGraph development environment for yourself, and will have the ability to develop OpenSceneGraph -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.

What this book covers

Chapter 1, The Journey into OpenSceneGraph introduces the history, structure and features of OpenSceneGraph (OSG), and introduces the general concept of scene graph.

Chapter 2, Compilation and Installation of OpenSceneGraph guides readers through compiling, installing and configuring an OSG development environment, either by using the prebuilt binaries or building an environment wholly from the source code.

Chapter 3, Creating Your First OSG Program shows how to code an OSG-based application, highlighting the utilization of smart pointers, notifying system, object instances and data variances.

Chapter 4, Building Geometry Models explains how to create a geometry entity simply with vertices and the drawing primitives defined within OSG.

Chapter 5, Managing Scene Graph is all about the implementation of a typical scene graph using OSG, and shows the usages of the various types of scene graph nodes with special focus on some commonly-used node types.

Chapter 6, Creating Realistic Rendering Effects introduces some basic knowledge about OSG implementation of rendering states, texture mapping, shaders, and the render-to-texture technique.

Chapter 7, Viewing the World shows the means by which developers can encapsulate the cameras, manipulators, and stereo supports, and have them work together.

Chapter 8, Animating Scene Objects shows OSG's capability of creating animated graphic presentations by using the built-in animation library, and showcases the implementations of path animations, vertex-level animations, state and texture animations, and character animations that a 3D application can use.

Chapter 9, Interacting with Outside Elements focuses on the implementation of human computer interaction using OSG, including input device handling and GUI toolkit integration.

Chapter 10, Saving and Loading Files explains in detail the working mechanism of reading and writing scene data, and gives tips for creating user-customized I/O plugins.

Chapter 11, Developing Visual Components covers a wide range of advanced scene graph components, including billboards, texts, height mapped terrains, shadows, and volume rendering.

Chapter 12, Improving Rendering Efficiency introduces the techniques necessary for building a fast real time rendering system. It helps users to load, organize, and render massive datasets in a very efficient manner.

What you need for this book

To use this book, you will need a graphics card with robust OpenGL support, with the latest OpenGL device driver from your graphics hardware vendor installed.

You will also need a working compiler that can transform C++source code into executable files. Some recommended ones include: .gcc, .mingw32, and Visual Studio. For Windows users, there is a free Visual Studio Express Edition for use (http://www.microsoft.com/express/Windows/). However, you should read the documentation in order to consider its limitations carefully.

Who this book is for

This book is intended for software developers who are new to OpenSceneGraph and are considering using it in their applications. It is assumed that you have basic knowledge of C++ before using this book, especially the standard template library (STL) constructs, of which OSG makes extensive use. Some familiarity with design patterns as implemented in C++ is also useful, but is not required.

You need to be familiar with OpenGL—the standard cross-platform low-level 3D graphics API. We'll meet some math in the book, including geometry and linear algebra. Familiarity with these topics will be great, but you don't need to be a math whiz to use this book.

Conventions

In this book, you will find several headings appearing frequently.

To give clear instructions of how to complete a procedure or task, we use:

Time for action—heading

  1. Action 1

  2. Action 2

  3. Action 3

Instructions often need some extra explanation so that they make sense, so they are followed with:

What just happened?

This heading explains the working of tasks or instructions that you have just completed.

You will also find some other learning aids in the book, including:

Pop quiz—heading

These are questions intended to help you test your own understanding.

Have a go hero—heading

These set practical challenges and give you ideas for experimenting with what you have learned.

You will also find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "CMake will generate an OpenSceneGraph.sln file at the root of the build directory".

A block of code is set as follows:

#include <osg/PolygonMode>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

Any command-line input or output is written as follows:

# osgviewer --image picture_name.bmp

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Start the installer and you will see the Choosing Language dialog, the Welcome page, and the License Agreement page".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.