OpenSceneGraph Quick Start Guide 5 OpenSceneGraph.The search should find OSG runtime binary and development environment packages,which you can select and install. To obtain the latest OSG binaries for Fedora Core 4,visit the OSG Wiki Web site [OSGWikil and select Download.Under Binaries,select the Fedora Core 4 link. 1.2.4 Microsoft Windows OSG run-time binaries for Microsoft Windows operating systems are available from the OSG Wiki Web site [OSGWiki]as an InstallShield executable.To install this package, perform the following steps. 1.From the OSG Wiki Web site [OSGWikil,select Downloads. 2.Download the OSG Win32 Binaries for OSG.This is an .exe file. 3.After the download completes,double-click the.exe file and follow the instructions for installation. The default installation modifies environment variables in the registry.To make these changes take effect,either log out and log back in,or reboot your system. OpenSceneGraph Figure 1-2 osglogo output This figure displays the results of the osglogo command
OpenSceneGraph Quick Start Guide 5 OpenSceneGraph. The search should find OSG runtime binary and development environment packages, which you can select and install. To obtain the latest OSG binaries for Fedora Core 4, visit the OSG Wiki Web site [OSGWiki] and select Download. Under Binaries, select the Fedora Core 4 link. 1.2.4 Microsoft Windows OSG run-time binaries for Microsoft Windows operating systems are available from the OSG Wiki Web site [OSGWiki] as an InstallShield executable. To install this package, perform the following steps. 1. From the OSG Wiki Web site [OSGWiki], select Downloads. 2. Download the OSG Win32 Binaries for OSG. This is an .exe file. 3. After the download completes, double-click the .exe file and follow the instructions for installation. The default installation modifies environment variables in the registry. To make these changes take effect, either log out and log back in, or reboot your system. Figure 1-2 osglogo output This figure displays the results of the osglogo command
6 An Overview of Scene Graphs and OpenSceneGraph 1.2.5 Verifying Your OSG Installation After installing OSG,you should verify your installation.Perform the following steps: 1.Open a command shell prompt on your computer. 2.Enter the following command: osgversion This executes the osgversion application,which should output the OSG version number, as follows: OpenSceneGraph Library 1.3 This simple step verifies that the system is able to find OSG executables(your PATH is set correctly),tells you what release version of OSG you're running,and minimally ensures that OSG is functional. To verify that OSG can render on your system,execute the following command: osglogo This should display am image similar to Figure 1-2. osglogo dynamically updates its scene to rotate the Earth.It also supports a trackball interface that allows you to spin the logo with the left mouse button. 1.3 Running osgviewer In the last section,you executed osgversion and osglogo.While this allowed you to verify your installtion,the program are limited in their functionality.This section shows you how to run osgviewer,OSG's flexible and powerful model viewing tool.Load a simple model of a cow and display it with the following command: osgviewer cow.osg The results are shown in Figure 1-3. The cow model is in OSG's own .osg file format.However,osgviewer supports the same file formats as OSG,many of which are enumerated in the section OSG Plugins later in this chapter. Like osglogo,osgviewer allows you to interact with the model.By default,osgviewer exposes a trackball-like interface.To rotate the cow model,drag with your left mouse button.When you release the mouse button,the model will continue to rotate.You can zoom in or out using the right mouse button.Hit the space bar to return to the initial view
6 An Overview of Scene Graphs and OpenSceneGraph 1.2.5 Verifying Your OSG Installation After installing OSG, you should verify your installation. Perform the following steps: 1. Open a command shell prompt on your computer. 2. Enter the following command: osgversion This executes the osgversion application, which should output the OSG version number, as follows: OpenSceneGraph Library 1.3 This simple step verifies that the system is able to find OSG executables (your PATH is set correctly), tells you what release version of OSG you’re running, and minimally ensures that OSG is functional. To verify that OSG can render on your system, execute the following command: osglogo This should display am image similar to Figure 1-2. osglogo dynamically updates its scene to rotate the Earth. It also supports a trackball interface that allows you to spin the logo with the left mouse button. 1.3 Running osgviewer In the last section, you executed osgversion and osglogo. While this allowed you to verify your installtion, the program are limited in their functionality. This section shows you how to run osgviewer, OSG’s flexible and powerful model viewing tool. Load a simple model of a cow and display it with the following command: osgviewer cow.osg The results are shown in Figure 1-3. The cow model is in OSG’s own .osg file format. However, osgviewer supports the same file formats as OSG, many of which are enumerated in the section OSG Plugins later in this chapter. Like osglogo, osgviewer allows you to interact with the model. By default, osgviewer exposes a trackball-like interface. To rotate the cow model, drag with your left mouse button. When you release the mouse button, the model will continue to rotate. You can zoom in or out using the right mouse button. Hit the space bar to return to the initial view
OpenSceneGraph Quick Start Guide 7 Figure 1-3 osgviewer output This figure displays the results of the command osgviewer cow.osg.The osgviewer application displays a wide range of image and model files. 1.3.1 Getting Help While in osgviewer,press theh'key to display a list of key commands and their functions. The'1'through '5'keys allow you to switch to different camera manipulation modes, which modify the way that the mouse controls the camera position;for now,stick with mode'1',trackball mode,which is the default.Many of the key commands control display modes,which the next section describes. The help text shows that Escape causes osgviewer to exit.Press Escape now;osgviewer exits and returns you to the command line prompt. Enter the following command to see the osgviewer command line options: osgviewer --help This causes osgviewer to display all command line options.The following describes a few of the commonly used options. .--clear-color-This option allows you to set the clear,or background,color.If you issue the following command,for example,osgviewer uses a white background color:
OpenSceneGraph Quick Start Guide 7 1.3.1 Getting Help While in osgviewer, press the ‘h’ key to display a list of key commands and their functions. The ‘1’ through ‘5’ keys allow you to switch to different camera manipulation modes, which modify the way that the mouse controls the camera position; for now, stick with mode ‘1’, trackball mode, which is the default. Many of the key commands control display modes, which the next section describes. The help text shows that Escape causes osgviewer to exit. Press Escape now; osgviewer exits and returns you to the command line prompt. Enter the following command to see the osgviewer command line options: osgviewer --help This causes osgviewer to display all command line options. The following describes a few of the commonly used options. • --clear-color—This option allows you to set the clear, or background, color. If you issue the following command, for example, osgviewer uses a white background color: Figure 1-3 osgviewer output This figure displays the results of the command osgviewer cow.osg. The osgviewer application displays a wide range of image and model files
8 An Overview of Scene Graphs and OpenSceneGraph osgviewer --clear-color 1.0,1.0,1.0,1.0 cow.osg --samples-This option enables hardware multisampling,more commonly known as full screen antialiasing.Its single numeric parameter is the number of samples per pixel.To enable multisampling with 16 subpixels,for example,use the following command: osgviewer --samples 16 cow.osg --image-This option causes osgviewer to load a single image and display it as a texture on q quadrilateral primitive,as shown in the following command. osgviewer --image osg256.png In addition to command line arguments and key commands,you can also control osgviewer with several environment variables.To see the full help text for osgviewer,issue the following command at a shell prompt: osgviewer --help-all The following sections provide more details about using the osgviewer application. 1.3.2 Display Modes Many of the osgviewer key commands specify display modes to control the appearance of the loaded model.Some of the commonly used commands are listed below. Polygon mode-Hit the w'key repeatedly to cycle between wireframe,point, and filled polygon rendering mode. Texture mapping-Hit thetkey to toggle between textured and non-textured. Lighting-Disable and enable lighting with the I'key. Backface culling-The b'key toggles backface culling.This doesn't change the appearance of the cow.osg model,but it could affect other models'appearance and rendering performance. Fullscreen mode-Use the 'f key to toggle between fullscreen and windowed rendering. Take some time and experiment with combinations of these osgviewer commands.For example,to clearly see the polygonal structure of a model,go to wireframe mode,and disable texture mapping and lighting. 1.3.3 Environment Variables Although OSG and the osgviewer application support many environment variables,there are two that you should become very familiar with.You will use them often when working with OSG
8 An Overview of Scene Graphs and OpenSceneGraph osgviewer --clear-color 1.0,1.0,1.0,1.0 cow.osg • --samples—This option enables hardware multisampling, more commonly known as full screen antialiasing. Its single numeric parameter is the number of samples per pixel. To enable multisampling with 16 subpixels, for example, use the following command: osgviewer --samples 16 cow.osg • --image—This option causes osgviewer to load a single image and display it as a texture on q quadrilateral primitive, as shown in the following command. osgviewer --image osg256.png In addition to command line arguments and key commands, you can also control osgviewer with several environment variables. To see the full help text for osgviewer, issue the following command at a shell prompt: osgviewer --help-all The following sections provide more details about using the osgviewer application. 1.3.2 Display Modes Many of the osgviewer key commands specify display modes to control the appearance of the loaded model. Some of the commonly used commands are listed below. • Polygon mode—Hit the ‘w’ key repeatedly to cycle between wireframe, point, and filled polygon rendering mode. • Texture mapping—Hit the ‘t’ key to toggle between textured and non-textured. • Lighting—Disable and enable lighting with the ‘l’ key. • Backface culling—The ‘b’ key toggles backface culling. This doesn’t change the appearance of the cow.osg model, but it could affect other models’ appearance and rendering performance. • Fullscreen mode—Use the ‘f’ key to toggle between fullscreen and windowed rendering. Take some time and experiment with combinations of these osgviewer commands. For example, to clearly see the polygonal structure of a model, go to wireframe mode, and disable texture mapping and lighting. 1.3.3 Environment Variables Although OSG and the osgviewer application support many environment variables, there are two that you should become very familiar with. You will use them often when working with OSG
OpenSceneGraph Quick Start Guide 9 File Search Path The OSG_FILE_PATH environment variable specifies the search path used by OSG when loading image and model files.If you run osgviewer cow.osg and cow.osg isn't in the current directory,OSG finds and loads cow.osg because its directory path is specified in OSG_FILE PATH Your runtime installation sets the OSG_FILE PATH variable.You can add more directories to this variable.On Windows,separate each directory with a semicolon,and use a color on other platforms.If the variable is empty or not set,OSG only searches the current directory when loading image and model files. Debug Message Display OSG is capable of displaying a large amount of debugging information to std::cout.This is useful in developing OSG applications,because it provides insight into what OSG is doing.The OSG_NOTIFY_LEVEL environment variable controls how much debugging information OSG displays.You can set it to one of seven values for varying verbosity levels:ALWAYS (least verbose),FATAL,WARN,NOTICE,INFO,DEBUG_INFO, and finally DEBUG_FP (most verbose). For typical OSG development,set OSG_NOTIFY_LEVEL to NOTICE,and adjust the value up or down the verbosity scale as necessary to receive more or less output. 1.3.4 Statistics Display Particularly useful for performance measurements is the 's'key,which uses the Statistics class in the osgUtil library to gather and display rendering performance information.The 's'key cycles between four display modes: 1.Frame rate-osgviewer displays the number of frames rendered per second (FPS). 2.Traversal time-osgviewer displays the amount of time spent in each of the update,cull,and draw traversals,including a graphical display,Figure 1-4 illustrates. 3. Geometry information-osgviewer displays the number of rendered osg::Drawable objects,as well as the total number of vertices and primitives processed per frame. 4.None-osgviewer disables the statistics display. Pressing the 's'key twice displays traversal time.Figure 1-4 illustrates the traversal time graphical display
OpenSceneGraph Quick Start Guide 9 File Search Path The OSG_FILE_PATH environment variable specifies the search path used by OSG when loading image and model files. If you run osgviewer cow.osg and cow.osg isn’t in the current directory, OSG finds and loads cow.osg because its directory path is specified in OSG_FILE_PATH. Your runtime installation sets the OSG_FILE_PATH variable. You can add more directories to this variable. On Windows, separate each directory with a semicolon, and use a color on other platforms. If the variable is empty or not set, OSG only searches the current directory when loading image and model files. Debug Message Display OSG is capable of displaying a large amount of debugging information to std::cout. This is useful in developing OSG applications, because it provides insight into what OSG is doing. The OSG_NOTIFY_LEVEL environment variable controls how much debugging information OSG displays. You can set it to one of seven values for varying verbosity levels: ALWAYS (least verbose), FATAL, WARN, NOTICE, INFO, DEBUG_INFO, and finally DEBUG_FP (most verbose). For typical OSG development, set OSG_NOTIFY_LEVEL to NOTICE, and adjust the value up or down the verbosity scale as necessary to receive more or less output. 1.3.4 Statistics Display Particularly useful for performance measurements is the ‘s’ key, which uses the Statistics class in the osgUtil library to gather and display rendering performance information. The ‘s’ key cycles between four display modes: 1. Frame rate—osgviewer displays the number of frames rendered per second (FPS). 2. Traversal time—osgviewer displays the amount of time spent in each of the update, cull, and draw traversals, including a graphical display, Figure 1-4 illustrates. 3. Geometry information—osgviewer displays the number of rendered osg::Drawable objects, as well as the total number of vertices and primitives processed per frame. 4. None—osgviewer disables the statistics display. Pressing the ‘s’ key twice displays traversal time. Figure 1-4 illustrates the traversal time graphical display