root/OpenSceneGraph/trunk/examples/osgviewerFOX/FOX_OSG_MDIView.cpp @ 12292

Revision 12292, 2.4 kB (checked in by robert, 3 years ago)

Ran svn propset -R svn:eol-style native . on the OpenSceneGraph

  • Property svn:eol-style set to native
Line 
1#include "FOX_OSG_MDIView.h"
2
3#include <osgViewer/ViewerEventHandlers>
4
5#include <osgGA/TrackballManipulator>
6
7#include <osgDB/ReadFile>
8
9
10// Map
11FXDEFMAP(FOX_OSG_MDIView) FOX_OSG_MDIView_Map[] = {
12    //________Message_Type_________        ___ID___                        ________Message_Handler________
13    FXMAPFUNC(SEL_CHORE,                FOX_OSG_MDIView::ID_CHORE,        FOX_OSG_MDIView::OnIdle)
14};
15
16FXIMPLEMENT(FOX_OSG_MDIView, FXMDIChild, FOX_OSG_MDIView_Map, ARRAYNUMBER(FOX_OSG_MDIView_Map))
17
18FOX_OSG_MDIView::FOX_OSG_MDIView(FXMDIClient *p, const FXString &name,
19        FXIcon *ic, FXPopup *pup, FXuint opt,
20        FXint x, FXint y, FXint w, FXint h)
21        :   FXMDIChild(p, name, ic, pup, opt, x, y, w, h)
22{
23    // A visual to drag OpenGL in double-buffered mode; note the glvisual is
24    // shared between all windows which need the same depths and numbers of buffers
25    // Thus, while the first visual may take some time to initialize, each subsequent
26    // window can be created very quickly; we need to determine grpaphics hardware
27    // characteristics only once.
28    FXGLVisual* glVisual=new FXGLVisual(getApp(),VISUAL_DOUBLEBUFFER|VISUAL_STEREO);
29
30    m_gwFox = new GraphicsWindowFOX(this, glVisual, NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y, x, y, w, h );
31
32    osgViewer::Viewer *viewer = new osgViewer::Viewer;
33    viewer->getCamera()->setGraphicsContext(m_gwFox);
34    viewer->getCamera()->setViewport(0,0,w,h);
35    viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
36
37    // FOX example does not catch the close of the graphics window, so
38    // don't allow the default escape sets to done to be active.
39    viewer->setKeyEventSetsDone(0);
40
41    // load the scene.
42    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osg");
43    if (!loadedModel)
44    {
45        return ;
46    }
47
48    // add the stats handler
49    viewer->addEventHandler(new osgViewer::StatsHandler);
50
51    viewer->setSceneData(loadedModel.get());
52
53    viewer->setCameraManipulator(new osgGA::TrackballManipulator);
54
55    SetViewer(viewer);
56
57    getApp()->addChore(this,ID_CHORE);
58
59}
60
61
62FOX_OSG_MDIView::~FOX_OSG_MDIView()
63{
64    getApp()->removeChore(this,ID_CHORE);
65}
66
67long FOX_OSG_MDIView::OnIdle(FXObject *sender, FXSelector sel, void* ptr)
68{
69    m_osgViewer->frame();
70    getApp()->addChore(this, ID_CHORE);
71    return 1;
72}
73
74void FOX_OSG_MDIView::SetViewer(osgViewer::Viewer* viewer)
75{
76    m_osgViewer = viewer;
77}
Note: See TracBrowser for help on using the browser.