// 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;
}