Using Inventor with OpenGL
2001.08.21
Chapter objectives
• Create Inventor callback nodes that include calls to the OpenGL Library
• Explain how Inventor uses and affects OpenGL state variables
• Write a program that combines use of Inventor and OpenGL and uses the SoGLRenderAction
• Use color index mode
Introduction
• This chapter– Describes how to combine calls to the inventor and
OpenGL libraries in the same window
• Combine Inventor with OpenGL in several ways– Using SoCallback– Applying a Render Action Inside a GLX Window
OpenGL state variables and Inventor
• Combine inventor and OpenGL– If Inventor uses the current value of an OpenGL sta
te value and never change it
• To save and restore OpenGL state– Use the OpenGL pushAttribute() and popAttributes
() commands
OpenGL state variables and Inventor
OpenGL state variables and Inventor
OpenGL state variables and Inventor
Color-Index Mode
• Open an X window– Supports OpenGL rendering in either RGB mode or
color-index mode– use color-index mode
• Be sure to load the color map
• Example– If you are using BASE_COLOR lighting.use the SoColorIndex n
ode to specify the index into the color map
Using an SoCallback Node
• A typical use of an SoCallback node is to make calls to OpenGL
If(action->isOfType(SoGLRenderAction::getClassTypeId()){ …execute rendering code…
Caching
• Caching saves the result of an operation so that it doesn’t need to be repeated
Void maycallback(void *myData, SoAction *action){ If(action->isOfType(SoGLRenderAction:getClassTypeId())){ SoCacheElement::invalidate(action->getState()); // make sure this isn’t cached // …make OpenGL calls that depend on a global variable…//}} // SoCacheElement::invalidate() to prevent Inventor from automatically
creating a cache
Using a Callback Node
• Inventor : red cube and a blue sphere• GL calls to draw a checked “floor”
//draw the lines that make up // callback routine to render floor the floor,using OpenGL using OpenGL
void drawFloor() void myCallbackRoutine(..){ { . . . … drawFloor(); } . . .} main(…){ . . . SoCallback *mycallback = new SoCallback; myCallback->setCallback(myCallbackRoutine);
Applying a Render Action Inside a GLX Window
• Example– Creates a GLX window,makes Inventor and OpenGL
calls, and then applies a GL render action// draw the lines that make up the floor,using OpenGL
void drawFloor() main(…){ { … … drawFloor();} … }
Top Related