diff --git a/Make/makedirdefs b/Make/makedirdefs index a76df85a9..2fa67ff3f 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -166,6 +166,7 @@ EXAMPLE_DIRS = \ osgspheresegment\ osgsimulation\ osgsimple\ + osgsimplepager\ osgshaders\ osgshadowtexture\ osgdepthshadow\ diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index c9caa7209..e8d0aa0a2 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -1662,6 +1662,33 @@ Package=<4> ############################################################################### +Project: "Example osgsimplepager"=.\examples\osgsimplepager\osgsimplepager.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgUtil + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgFX + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgGL2 + End Project Dependency +}}} + +############################################################################### + Project: "Example osgwindows"=.\examples\osgwindows\osgwindows.dsp - Package Owner=<4> Package=<5> diff --git a/VisualStudio/examples/osgsimplepager/osgsimplepager.dsp b/VisualStudio/examples/osgsimplepager/osgsimplepager.dsp new file mode 100644 index 000000000..6bc383a10 --- /dev/null +++ b/VisualStudio/examples/osgsimplepager/osgsimplepager.dsp @@ -0,0 +1,190 @@ +# Microsoft Developer Studio Project File - Name="Example osgsimplepager" - Package Owner=<4> + +# Microsoft Developer Studio Generated Build File, Format Version 6.00 + +# ** DO NOT EDIT ** + + + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + + + +CFG=Example osgsimplepager - Win32 Release + +!MESSAGE This is not a valid makefile. To build this project using NMAKE, + +!MESSAGE use the Export Makefile command and run + +!MESSAGE + +!MESSAGE NMAKE /f "osgsimplepager.mak". + +!MESSAGE + +!MESSAGE You can specify a configuration when running NMAKE + +!MESSAGE by defining the macro CFG on the command line. For example: + +!MESSAGE + +!MESSAGE NMAKE /f "osgsimplepager.mak" CFG="Example osgsimplepager - Win32 Release" + +!MESSAGE + +!MESSAGE Possible choices for configuration are: + +!MESSAGE + +!MESSAGE "Example osgsimplepager - Win32 Release" (based on "Win32 (x86) Console Application") + +!MESSAGE "Example osgsimplepager - Win32 Debug" (based on "Win32 (x86) Console Application") + +!MESSAGE + + + +# Begin Project + +# PROP AllowPerConfigDependencies 0 + +# PROP Scc_ProjName "" + +# PROP Scc_LocalPath "" + +CPP=cl.exe + +RSC=rc.exe + + + +!IF "$(CFG)" == "Example osgsimplepager - Win32 Release" + + + +# PROP BASE Use_MFC 0 + +# PROP BASE Use_Debug_Libraries 0 + +# PROP BASE Output_Dir "Release" + +# PROP BASE Intermediate_Dir "Release" + +# PROP BASE Target_Dir "" + +# PROP Use_MFC 0 + +# PROP Use_Debug_Libraries 0 + +# PROP Output_Dir "Release" + +# PROP Intermediate_Dir "Release" + +# PROP Ignore_Export_Lib 0 + +# PROP Target_Dir "" + +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c + +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c + +# ADD BASE RSC /l 0x809 /d "NDEBUG" + +# ADD RSC /l 0x809 /d "NDEBUG" + +BSC32=bscmake.exe + +# ADD BASE BSC32 /nologo + +# ADD BSC32 /nologo + +LINK32=link.exe + +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +# ADD LINK32 opengl32.lib Producer.lib OpenThreadsWin32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgsimplepager.exe" /libpath:"../../../lib" + + + +!ELSEIF "$(CFG)" == "Example osgsimplepager - Win32 Debug" + + + +# PROP BASE Use_MFC 0 + +# PROP BASE Use_Debug_Libraries 1 + +# PROP BASE Output_Dir "Debug" + +# PROP BASE Intermediate_Dir "Debug" + +# PROP BASE Target_Dir "" + +# PROP Use_MFC 0 + +# PROP Use_Debug_Libraries 1 + +# PROP Output_Dir "Debug" + +# PROP Intermediate_Dir "Debug" + +# PROP Ignore_Export_Lib 0 + +# PROP Target_Dir "" + +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c + +# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c + +# ADD BASE RSC /l 0x809 /d "_DEBUG" + +# ADD RSC /l 0x809 /d "_DEBUG" + +BSC32=bscmake.exe + +# ADD BASE BSC32 /nologo + +# ADD BSC32 /nologo + +LINK32=link.exe + +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +# ADD LINK32 opengl32.lib Producerd.lib OpenThreadsWin32d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgsimplepagerd.exe" /pdbtype:sept /libpath:"../../../lib" + +# SUBTRACT LINK32 /incremental:no + + + +!ENDIF + + + +# Begin Target + + + +# Name "Example osgsimplepager - Win32 Release" + +# Name "Example osgsimplepager - Win32 Debug" + +# Begin Source File + + + +SOURCE=..\..\..\examples\osgsimplepager\osgsimplepager.cpp + +# End Source File + +# End Target + +# Begin Group "Resource Files" + + + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + +# End Group + +# End Project + diff --git a/examples/osgsimplepager/GNUmakefile b/examples/osgsimplepager/GNUmakefile new file mode 100644 index 000000000..33040ba9c --- /dev/null +++ b/examples/osgsimplepager/GNUmakefile @@ -0,0 +1,27 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgsimplepager.cpp\ + +LIBS += -lProducer -losgFX -losgGL2 -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) -lOpenThreads + +INSTFILES = \ + $(CXXFILES)\ + GNUmakefile.inst=GNUmakefile + +EXEC = osgsimplepager + +INC += $(X_INC) +LDFLAGS += -L/usr/X11R6/lib + + +ifeq ($(USE_OPEN_THREAD),1) + DEF += -D_USE_OPEN_THREAD + INC += $(INC_OPEN_THREAD) + LDFLAGS += $(LIB_OPEN_THREAD) + LIBS += -lOpenThread +endif + +include $(TOPDIR)/Make/makerules + diff --git a/examples/osgsimplepager/GNUmakefile.inst b/examples/osgsimplepager/GNUmakefile.inst new file mode 100644 index 000000000..eb90c9ad3 --- /dev/null +++ b/examples/osgsimplepager/GNUmakefile.inst @@ -0,0 +1,14 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgsimplepager.cpp\ + +LIBS += -lProducer -losgFX -losgGL2 -losgDB --losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgsimplepager + +INC += $(PRODUCER_INCLUDE_DIR) $(X_INC) +LDFLAGS += $(PRODUCER_LIB_DIR) + +include $(TOPDIR)/Make/makerules diff --git a/examples/osgsimplepager/osgsimplepager.cpp b/examples/osgsimplepager/osgsimplepager.cpp new file mode 100644 index 000000000..3dc6ac584 --- /dev/null +++ b/examples/osgsimplepager/osgsimplepager.cpp @@ -0,0 +1,229 @@ +// C++ source file - (C) 2003 Robert Osfield, released under the OSGPL. +// +// Simple example of use of Producer::RenderSurface + KeyboardMouseCallback + SceneView +// example that provides the user with control over view position with support for +// enabling the osgDB::DatabasePager as required by the PagedLOD and TXP databases. + +#include +#include +#include + +#include + +#include +#include + +#include + +#include + + +class MyKeyboardMouseCallback : public Producer::KeyboardMouseCallback +{ +public: + + MyKeyboardMouseCallback(osgUtil::SceneView* sceneView) : + Producer::KeyboardMouseCallback(), + _mx(0.0f),_my(0.0f),_mbutton(0), + _done(false), + _trackBall(new Producer::Trackball), + _sceneView(sceneView) + { + resetTrackball(); + } + + virtual void specialKeyPress( Producer::KeyCharacter key ) + { + if (key==Producer::KeyChar_Escape) + shutdown(); + } + + virtual void shutdown() + { + _done = true; + } + + virtual void keyPress( Producer::KeyCharacter key) + { + if (key==' ') resetTrackball(); + } + + virtual void mouseMotion( float mx, float my ) + { + _mx = mx; + _my = my; + } + + virtual void buttonPress( float mx, float my, unsigned int mbutton ) + { + _mx = mx; + _my = my; + _mbutton |= (1<<(mbutton-1)); + + _mx_buttonPress = _mx; + _my_buttonPress = _my; + } + virtual void buttonRelease( float mx, float my, unsigned int mbutton ) + { + _mx = mx; + _my = my; + _mbutton &= ~(1<<(mbutton-1)); + } + + bool done() { return _done; } + float mx() { return _mx; } + float my() { return _my; } + unsigned int mbutton() { return _mbutton; } + + void resetTrackball() + { + osg::Node* scene = _sceneView->getSceneData(); + if (scene) + { + const osg::BoundingSphere& bs = scene->getBound(); + _trackBall->reset(); + _trackBall->setOrientation( Producer::Trackball::Z_UP ); + _trackBall->setDistance(bs.radius()*2.0f); + _trackBall->translate(-bs.center().x(),-bs.center().y(),-bs.center().z()); + } + } + + osg::Matrixd getViewMatrix() + { + _trackBall->input( mx(), my(), mbutton() ); + return osg::Matrixd(_trackBall->getMatrix().ptr()); + } + +private: + + float _mx, _my; + float _mx_buttonPress, _my_buttonPress; + unsigned int _mbutton; + + bool _done; + + osg::ref_ptr _trackBall; + osg::ref_ptr _sceneView; +}; + +int main( int argc, char **argv ) +{ + if (argc<2) + { + std::cout << argv[0] <<": requires filename argument." << std::endl; + return 1; + } + + // load the scene. + osg::ref_ptr loadedModel = osgDB::readNodeFile(argv[1]); + if (!loadedModel) + { + std::cout << argv[0] <<": No data loaded." << std::endl; + return 1; + } + + // create the window to draw to. + osg::ref_ptr renderSurface = new Producer::RenderSurface; + renderSurface->setWindowName("osgsimplepager"); + renderSurface->setWindowRectangle(100,100,800,600); + renderSurface->useBorder(true); + renderSurface->realize(); + + + // create the view of the scene. + osg::ref_ptr sceneView = new osgUtil::SceneView; + sceneView->setDefaults(); + sceneView->setSceneData(loadedModel.get()); + + + // do the set up of the DatabasePager... + // create the database pager via the osgDB::Registry + osgDB::DatabasePager* databasePager = osgDB::Registry::instance()->getOrCreateDatabasePager(); + + // set wether the DatabasePager thread should be blocked while the scene graph is being used to render a frame + // setting frame block to true can help achieve constant frame rates on single CPU systems. + databasePager->setUseFrameBlock(false); + + // register any PagedLOD that need to be tracked in the scene graph + databasePager->registerPagedLODs(sceneView->getSceneData()); + + // need to register the DatabasePager with the SceneView's CullVisitor so it can pass on request + // for files to be loaded. + sceneView->getCullVisitor()->setDatabaseRequestHandler(databasePager); + + + // set up a KeyboardMouse to manage the events comming in from the RenderSurface + osg::ref_ptr kbm = new Producer::KeyboardMouse(renderSurface.get()); + + // create a KeyboardMouseCallback to handle the mouse events within this applications + osg::ref_ptr kbmcb = new MyKeyboardMouseCallback(sceneView.get()); + + + // record the timer tick at the start of rendering. + osg::Timer_t start_tick = osg::Timer::instance()->tick(); + + unsigned int frameNum = 0; + + // main loop (note, window toolkits which take control over the main loop will require a window redraw callback containing the code below.) + while( renderSurface->isRealized() && !kbmcb->done()) + { + // set up the frame stamp for current frame to record the current time and frame number so that animtion code can advance correctly + osg::FrameStamp* frameStamp = new osg::FrameStamp; + frameStamp->setReferenceTime(osg::Timer::instance()->delta_s(start_tick,osg::Timer::instance()->tick())); + frameStamp->setFrameNumber(frameNum++); + + // pass frame stamp to the SceneView so that the update, cull and draw traversals all use the same FrameStamp + sceneView->setFrameStamp(frameStamp); + + // pass any keyboard mouse events onto the local keyboard mouse callback. + kbm->update( *kbmcb ); + + // set the view + sceneView->setViewMatrix(kbmcb->getViewMatrix()); + + // update the viewport dimensions, incase the window has been resized. + sceneView->setViewport(0,0,renderSurface->getWindowWidth(),renderSurface->getWindowHeight()); + + + // tell the DatabasePager the frame number of that the scene graph is being actively used to render a frame + databasePager->signalBeginFrame(frameStamp); + + // syncronize changes required by the DatabasePager thread to the scene graph + databasePager->updateSceneGraph(frameStamp->getReferenceTime()); + + // do the update traversal the scene graph - such as updating animations + sceneView->update(); + + // do the cull traversal, collect all objects in the view frustum into a sorted set of rendering bins + sceneView->cull(); + + // draw the rendering bins. + sceneView->draw(); + + + // tell the DatabasePager that the frame is complete and that scene graph is no longer be activity traversed. + databasePager->signalEndFrame(); + + // Swap Buffers + renderSurface->swapBuffers(); + + + // clean up and compile gl objects with a specified limit + double availableTime = 0.0025; // 2.5 ms + + // compile any GL objects that are required. + databasePager->compileGLObjects(*(sceneView->getState()),availableTime); + + // flush deleted GL objects. + sceneView->flushDeletedGLObjects(availableTime); + + + + } + + // switch off the database pager by unreferning it. + osgDB::Registry::instance()->setDatabasePager(0); + + return 0; +} +