本文整理汇总了C++中ViewportRecPtr::setBackground方法的典型用法代码示例。如果您正苦于以下问题:C++ ViewportRecPtr::setBackground方法的具体用法?C++ ViewportRecPtr::setBackground怎么用?C++ ViewportRecPtr::setBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewportRecPtr
的用法示例。
在下文中一共展示了ViewportRecPtr::setBackground方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
{
// Set up Window
WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
TutorialWindow->initWindow();
// Create the SimpleSceneManager helper
SimpleSceneManager sceneManager;
TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));
// Tell the Manager what to manage
sceneManager.setWindow(TutorialWindow);
TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);
// Make Main Scene Node and add the Torus
NodeRecPtr scene = Node::create();
scene->setCore(Group::create());
scene->addChild(TorusGeometryNode);
// Create the Graphics
GraphicsRecPtr TutorialGraphics = Graphics2D::create();
// Initialize the LookAndFeelManager to enable default settings
LookAndFeelManager::the()->getLookAndFeel()->init();
//Create the nessicary parts for a viewport
Matrix TransformMatrix;
TransformMatrix.setTranslate(0.0f,0.0f, 0.0f);
TransformRecPtr CameraBeaconTransform = Transform::create();
CameraBeaconTransform->setMatrix(TransformMatrix);
NodeRecPtr CameraBeaconNode = Node::create();
CameraBeaconNode->setCore(CameraBeaconTransform);
// Make Torus Node (creates Torus in background of scene)
NodeRecPtr GeometryNode = makeTorus(.5, 2, 32, 32);
//Make a light Node
NodeRecPtr LightBeaconNode = makeCoredNode<Transform>();
DirectionalLightRecPtr SceneLight = DirectionalLight::create();
SceneLight->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
SceneLight->setDiffuse(Color4f(0.8f,0.8f,0.8f,1.0f));
SceneLight->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f));
SceneLight->setOn(true);
SceneLight->setBeacon(LightBeaconNode);
NodeRecPtr LightNode = makeNodeFor(SceneLight);
LightNode->addChild(GeometryNode);
// Make Main Scene Node and add the Torus
NodeRecPtr DefaultRootNode = Node::create();
DefaultRootNode->setCore(Group::create());
DefaultRootNode->addChild(LightNode);
DefaultRootNode->addChild(LightBeaconNode);
DefaultRootNode->addChild(CameraBeaconNode);
//Camera
PerspectiveCameraRecPtr DefaultCamera = PerspectiveCamera::create();
DefaultCamera->setBeacon(CameraBeaconNode);
DefaultCamera->setFov (osgDegree2Rad(60.f));
DefaultCamera->setNear (0.1f);
DefaultCamera->setFar (100.f);
//Background
GradientBackgroundRecPtr DefaultBackground = GradientBackground::create();
DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f);
DefaultBackground->addLine(Color3f(0.0f,0.0f,1.0f), 1.0f);
//Viewport
ViewportRecPtr DefaultViewport = Viewport::create();
DefaultViewport->setCamera (DefaultCamera);
DefaultViewport->setRoot (DefaultRootNode);
DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f);
DefaultViewport->setBackground (DefaultBackground);
//GL Viewport Component
LineBorderRecPtr TheGLViewportBorder = LineBorder::create();
TheGLViewportBorder->setColor(Color4f(1.0,0.0,0.0,1.0));
TheGLViewportBorder->setWidth(3.0);
GLViewportRecPtr TheGLViewport = GLViewport::create();
TheGLViewport->setPort(DefaultViewport);
TheGLViewport->setPreferredSize(Vec2f(400.0f,400.0f));
TheGLViewport->setBorders(TheGLViewportBorder);
TheGLViewport->lookAt(Pnt3f(0.0f,0.0f,10.0f), //From
Pnt3f(0.0f,0.0f,0.0f), //At
Vec3f(0.0f,1.0f,0.0f)); //Up
ButtonRecPtr ExampleButton = Button::create();
//.........这里部分代码省略.........
示例2: renderSceneToTexture
OSG_USING_NAMESPACE
void renderSceneToTexture(Scene* const TheScene,
TextureObjChunk* const ColorTexture,
Window* const TheWindow,
RenderAction* TheRenderAction)
{
//Create an FBO to render the Scene's Viewport(s) into
FrameBufferObjectRecPtr SceneFBO = FrameBufferObject::create();
TextureBufferRecPtr FBOTextureBuffer = TextureBuffer ::create();
RenderBufferRecPtr FBODepthBuffer = RenderBuffer ::create();
//Attache the Texture to the TexureBuffer
FBOTextureBuffer->setTexture(ColorTexture);
// add a depth attachment, otherwise there is no depth buffer when
// rendering to the FBO
FBODepthBuffer->setInternalFormat(GL_DEPTH_COMPONENT24);
// make the fbo render to the texture
SceneFBO->setColorAttachment(FBOTextureBuffer, 0);
SceneFBO->setDepthAttachment(FBODepthBuffer );
SceneFBO->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);
SceneFBO->setWidth (FBOTextureBuffer->getTexture()->getImage()->getWidth() );
SceneFBO->setHeight(FBOTextureBuffer->getTexture()->getImage()->getHeight());
/*
Next we set up a Stage, which renders the subtree below it to its
render target (the FBO from above).
*/
SimpleStageRefPtr SceneStage = SimpleStage::create();
NodeRefPtr SceneStageNode = makeNodeFor(SceneStage);
ViewportRecPtr SceneViewport(TheScene->getPrimaryViewport());
SceneStage->setRenderTarget(SceneFBO);
SceneStage->setLeft(SceneViewport->getLeft());
SceneStage->setRight(SceneViewport->getRight());
SceneStage->setTop(SceneViewport->getTop());
SceneStage->setBottom(SceneViewport->getBottom());
SceneStage->setCamera(SceneViewport->getCamera());
SceneStage->setBackground(SceneViewport->getBackground());
for(UInt32 i(0) ; i<SceneViewport->getMFForegrounds()->size() ; ++i)
{
SceneStage->pushToForegrounds(SceneViewport->getForegrounds(i));
}
SceneStageNode->addChild(SceneViewport->getRoot());
NodeRecPtr ThumbRootNode = makeCoredNode<Group>();
ThumbRootNode->addChild(SceneStageNode);
CameraRecPtr ThumbCamera = MatrixCamera::create();
ThumbCamera->setBeacon(ThumbRootNode);
BackgroundRecPtr ThumbBackground = PassiveBackground::create();
//Create a dummy Viewport for attaching to the window
ViewportRecPtr ThumbViewport = Viewport::create();
ThumbViewport->setBackground(ThumbBackground);
ThumbViewport->setRoot(ThumbRootNode);
ThumbViewport->setCamera(ThumbCamera);
//Get all of the original TravMasks of the Viewports on the window
//Set all of the TravMasks of the Viewports on the window to 0
std::vector<UInt32> OrigTravMasks;
OrigTravMasks.reserve(TheWindow->getMFPort()->size());
for(UInt32 i(0) ; i<TheWindow->getMFPort()->size() ; ++i)
{
OrigTravMasks.push_back(TheWindow->getPort(i)->getTravMask());
TheWindow->getPort(i)->setTravMask(0);
}
//Attach the Viewport to the Window
TheWindow->addPort(ThumbViewport);
//Draw the window
TheWindow->render(TheRenderAction);
//Detach the Viewport from the Window
TheWindow->subPortByObj(ThumbViewport);
//Reset all of the original TravMasks of the Viewports on the window
for(UInt32 i(0) ; i<TheWindow->getMFPort()->size() ; ++i)
{
TheWindow->getPort(i)->setTravMask(OrigTravMasks[i]);
}
}
示例3: main
//.........这里部分代码省略.........
ButtonRecPtr UndoButton = OSG::Button::create();
UndoButton->setText("Undo");
UndoButton->setEnabled(false);
UndoButton->connectActionPerformed(boost::bind(&handleUndoButtonAction, _1, TheUndoManager));
ButtonRecPtr RedoButton = OSG::Button::create();
RedoButton->setText("Redo");
RedoButton->setEnabled(false);
RedoButton->connectActionPerformed(boost::bind(&handleRedoButtonActionPerformed, _1, TheUndoManager));
TheUndoManager->connectStateChanged(boost::bind(&handleUndoManagerStateChanged, _1, UndoButton.get(), RedoButton.get(), UndoRedoListModel.get(), TheUndoManager));
// Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel)
ScrollPanelRefPtr UndoRedoScrollPanel = ScrollPanel::create();
UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200));
UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
UndoRedoScrollPanel->setViewComponent(UndoRedoList);
//Background Editor Field
FieldContainerEditorComponentRefPtr TheEditor = FieldContainerEditorFactory::the()->createDefaultEditor(TutorialBackground, TheCommandManager);
//FieldContainerEditorComponentRefPtr TheEditor = FieldContainerEditorFactory::the()->createDefaultEditor(RedoButton, TheCommandManager);
//FieldContainerEditorComponentRefPtr TheEditor = FieldContainerEditorFactory::the()->createDefaultEditor(dynamic_cast<Geometry*>(TorusGeometryNode->getCore())->getMaterial(), TheCommandManager);
ScrollPanelRefPtr EditorScrollPanel = ScrollPanel::create();
EditorScrollPanel->setPreferredSize(Vec2f(300,400));
EditorScrollPanel->setViewComponent(TheEditor);
//Undo Panel
LabelRecPtr UndoPanelLabel = Label::create();
UndoPanelLabel->setText("Undo Panel");
UndoPanelLabel->setPreferredSize(Vec2f(100.0f, 20.0f));
LayoutRefPtr UndoPanelLayout = OSG::FlowLayout::create();
PanelRecPtr UndoPanel = Panel::create();
UndoPanel->setPreferredSize(Vec2f(300.0f,300.0f));
UndoPanel->pushToChildren(UndoPanelLabel);
UndoPanel->pushToChildren(UndoRedoScrollPanel);
UndoPanel->pushToChildren(UndoButton);
UndoPanel->pushToChildren(RedoButton);
UndoPanel->setLayout(UndoPanelLayout);
// Create The Main InternalWindow
// Create Background to be used with the Main InternalWindow
ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
MainInternalWindow->pushToChildren(EditorScrollPanel);
MainInternalWindow->pushToChildren(UndoPanel);
MainInternalWindow->setLayout(MainInternalWindowLayout);
MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f));
MainInternalWindow->setDrawTitlebar(false);
MainInternalWindow->setResizable(false);
// Create the Drawing Surface
UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
TutorialDrawingSurface->setGraphics(TutorialGraphics);
TutorialDrawingSurface->setEventProducer(TutorialWindow);
TutorialDrawingSurface->openWindow(MainInternalWindow);
// Create the UI Foreground Object
UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();
TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);
// Add the UI Foreground Object to the Scene
TutorialViewport->addForeground(TutorialUIForeground);
TutorialViewport->setBackground(TutorialBackground);
//Create the Documentation Foreground and add it to the viewport
SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);
// Show the whole Scene
sceneManager.showAll();
//sceneManager.setStatistics(true);
TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1, TheCommandManager, TutorialViewport.get(), UndoRedoList.get()));
//Open Window
Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
TutorialWindow->openWindow(WinPos,
WinSize,
"03GenericFieldContainerEditor");
//Enter main Loop
TutorialWindow->mainLoop();
}
osgExit();
return 0;
}