SoOffscreenRender纹理显示

/*----------------------------------------------------------- * Using the offscreen renderer to generate a texture map. * Generate simple scene and grab the image to use as * a texture map. *----------------------------------------------------------*/ #include <Inventor/SoDB.h> #include <Inventor/SoInput.h> #include <Inventor/SoOffscreenRenderer.h> #include <Inventor/SbViewportRegion.h> #include <Inventor/nodes/SoCube.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoPerspectiveCamera.h> #include <Inventor/nodes/SoRotationXYZ.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoTexture2.h> #include <Inventor/Win/SoWin.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> SbBool generateTextureMap(SoNode *root, SoTexture2 *texture, short textureWidth, short textureHeight) { SbViewportRegion myViewport(textureWidth, textureHeight); // Render the scene SoOffscreenRenderer *myRenderer = new SoOffscreenRenderer(myViewport); myRenderer->setBackgroundColor(SbColor(0.3f, 0.3f, 0.3f)); if (!myRenderer->render(root)) { delete myRenderer; return FALSE; } // Generate the texture texture->image.setValue(SbVec2s(textureWidth, textureHeight), SoOffscreenRenderer::RGB, myRenderer->getBuffer()); delete myRenderer; return TRUE; } #include <Inventor/nodes/SoComplexity.h> int main(int, char **argv) { // Initialize Inventor and Win HWND appWindow = SoWin::init(argv[0]); if (appWindow == NULL) exit(1); // Make a scene from reading in a file SoSeparator *texRoot = new SoSeparator; SoComplexity *nodeComplexity = new SoComplexity; nodeComplexity->ref(); nodeComplexity->textureQuality = 0.0f; texRoot->addChild(nodeComplexity); SoInput in; SoNode *result; texRoot->ref(); in.openFile("../data/jumpyMan.iv"); SoDB::read(&in, result); SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoRotationXYZ *rot = new SoRotationXYZ; rot->axis = SoRotationXYZ::X; rot->angle = (float)M_PI_2; myCamera->position.setValue(SbVec3f(-0.2f, -0.2f, 2.0f)); myCamera->scaleHeight(0.4f); texRoot->addChild(myCamera); texRoot->addChild(new SoDirectionalLight); texRoot->addChild(rot); texRoot->addChild(result); // Generate the texture map SoTexture2 *texture = new SoTexture2; texture->ref(); if (generateTextureMap(texRoot, texture, 64, 64)) printf ("Successfully generated texture map/n"); else printf ("Could not generate texture map/n"); texRoot->unref(); // Make a scene with a cube and apply the texture to it SoSeparator *root = new SoSeparator; root->ref(); root->addChild(texture); root->addChild(new SoCube); // Initialize an Examiner Viewer SoWinExaminerViewer *viewer = new SoWinExaminerViewer(appWindow); viewer->setSceneGraph(root); viewer->setTitle("Offscreen Rendered Texture"); // In Inventor 2.1, if the machine does not have hardware texture // mapping, we must override the default drawStyle to display textures. viewer->setDrawStyle(SoWinViewer::STILL, SoWinViewer::VIEW_AS_IS); viewer->show(); SoWin::show(appWindow); SoWin::mainLoop(); return 0; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值