using inventor with opengl 2001.08.21. chapter objectives create inventor callback nodes that...

12
Using Inventor with OpenGL 2001.08.21

Upload: aron-howard

Post on 05-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

Using Inventor with OpenGL

2001.08.21

Page 2: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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

Page 3: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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

Page 4: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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

Page 5: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

OpenGL state variables and Inventor

Page 6: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

OpenGL state variables and Inventor

Page 7: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

OpenGL state variables and Inventor

Page 8: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how 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

Page 9: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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…

Page 10: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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

Page 11: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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);

Page 12: Using Inventor with OpenGL 2001.08.21. Chapter objectives Create Inventor callback nodes that include calls to the OpenGL Library Explain how Inventor

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();} … }