Overlay Scene Graph

/*------------------------------------------------------------ * This example shows how to use the overlay planes with the * viewer components. By default color 0 is used for the * overlay planes background color (clear color), so we use * color 1 for the object. This example also shows how to * load the overlay color map with the wanted color. *----------------------------------------------------------*/ #include <Inventor/SoDB.h> #include <Inventor/SoInput.h> #include <Inventor/nodes/SoNode.h> #include <Inventor/nodes/SoCone.h> #include <Inventor/Win/SoWin.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> #ifdef sun #include <Inventor/nodes/SoColorIndex.h> #include <Inventor/actions/SoSearchAction.h> #endif #ifdef sun #ifdef __cplusplus extern "C" { #endif extern int glXIsOverlayTGS(void); #ifdef __cplusplus } #endif # pragma weak glXIsOverlayTGS #endif static char *overlayScene = "/ #Inventor V2.0 ascii/n/ / Separator { / OrthographicCamera { / position 0 0 5 / nearDistance 1.0 / farDistance 10.0 / height 10 / } / LightModel { model BASE_COLOR } / ColorIndex { index 1 } / Coordinate3 { point [ -1 -1 0, -1 1 0, 1 1 0, 1 -1 0] } / FaceSet {} / } "; #ifdef WIN32 # include "print.h" #endif int main(int, char **argv) { // Initialize Inventor and Win HWND myWindow = SoWin::init(argv[0]); // read the scene graph in SoInput in; SoNode *scene; in.setBuffer((void *)overlayScene, (size_t) strlen(overlayScene)); if (! SoDB::read(&in, scene) || scene == NULL) { printf("Couldn't read scene/n"); exit(1); } // Allocate the viewer, set the overlay scene and // load the overlay color map with the wanted color. // SbColor color(.5, 1, .5); SbColor color(1.0f, 1.0f, 0.0f); SoWinExaminerViewer *myViewer = new SoWinExaminerViewer(myWindow); #ifdef sun if (!glXIsOverlayTGS) { long value; int num; // Get overlay colormap size int colorMapSize = myViewer->getOverlayColorMapSize(); // Code which gets a handle to the SoColorIndex node SoSearchAction searchAction; searchAction.setType(SoColorIndex::getClassTypeId()); searchAction.setInterest(SoSearchAction::FIRST); scene->ref(); searchAction.apply(scene); SoPath *path = searchAction.getPath(); if (path) { int zi; for (zi=0;zi<path->getLength();zi++) { SoNode *child; SoType type1; child = path->getNode(zi); type1 = child->getTypeId(); if (type1 == SoColorIndex::getClassTypeId()) { num = ((SoColorIndex *)child)->index.getNum(); value = ((SoColorIndex *)child)->index[0]; // Modify the index to the high end of the colormap ((SoColorIndex *)child)->index.set1Value(0, colorMapSize-1-value); } } } // Set the overlay colormap with the color we want myViewer->setOverlayColorMap(colorMapSize-1-value, 1, &color); } else { myViewer->setOverlayColorMap(1, 1, &color); } // #else // myViewer->setOverlayColorMap(1, 1, &color); #endif // myViewer->setSceneGraph(new SoCone); myViewer->setOverlaySceneGraph(scene); myViewer->setOverlayColorMap(1, 1, &color); myViewer->setTitle("Overlay Plane"); // Show the viewer and loop forever myViewer->show(); SoWin::show(myWindow); // Display main window SoWin::mainLoop(); return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值