From Michael Hartman, "I have gone in and created a CMakeList.txt file for osgviewerMFC application.
Below is the changes made to the included files. The examples CMakeList.txt file was not included but the code change needed for osgviewerMFC inclusion is listed below.
CMakeList.txt:
This is a little different than other example cmakelist.txt files in that I could not use the setup_example macro. I had to go in and extract out the important parts of the macro and inline them in the CMakeList.txt file so that I could add the WIN32 declaration into the ADD_EXECUTABLE() statement. In the future the setup_example macro might be modified to support osgviewerMFC but this is special case so you might not want to muddy the water for one example.
MFC_OSG.h:
This file had some small changes:
From: #include <osgViewer/GraphicsWindowWin32>
To: #include <osgViewer/api/win32/GraphicsWindowWin32>
Also added two new function declarations
Void PreFrameUpdate(void);
Void PostFrameUpdate(void);
MFC_OSG.cpp:
This file changed only in that I am explicitly showing the viewer run loop and added the two new functions in the MFC_OSG.h file.
"
This commit is contained in:
@@ -122,5 +122,11 @@ IF (FLTK_FOUND)
|
||||
ADD_SUBDIRECTORY(osgsimpleviewerFLTK)
|
||||
ENDIF(FLTK_FOUND)
|
||||
|
||||
IF (WIN32)
|
||||
ADD_SUBDIRECTORY(osgviewerMFC)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
|
||||
#ADD_SUBDIRECTORY(osgcegui)
|
||||
#to add subject to find socket#ADD_SUBDIRECTORY(osgcluster)
|
||||
|
||||
33
examples/osgviewerMFC/CMakeLists.txt
Normal file
33
examples/osgviewerMFC/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
SET(TARGET_SRC MFC_OSG_MDI.cpp MFC_OSG_MDI.rc MFC_OSG_MDIDoc.cpp MFC_OSG_MDIView.cpp stdafx.cpp MFC_OSG.cpp MainFrm.cpp ChildFrm.cpp)
|
||||
SET(TARGET_H MFC_OSG_MDI.h MFC_OSG_MDIDoc.h MFC_OSG_MDIView.h stdafx.h MFC_OSG.h MainFrm.h ChildFrm.h Resource.h)
|
||||
|
||||
ADD_DEFINITIONS(-D_AFXDLL)
|
||||
SET(CMAKE_MFC_FLAG 2)
|
||||
|
||||
#### end var setup ###
|
||||
#SETUP_EXAMPLE(osgviewerMFC)
|
||||
|
||||
#
|
||||
#Extracted from SETUP_EXAMPLES
|
||||
#
|
||||
SET(TARGET_NAME osgviewerMFC)
|
||||
|
||||
#
|
||||
#Extracted from SETUP_EXE
|
||||
#
|
||||
IF(NOT TARGET_TARGETNAME)
|
||||
SET(TARGET_TARGETNAME "${TARGET_DEFAULT_PREFIX}${TARGET_NAME}")
|
||||
ENDIF(NOT TARGET_TARGETNAME)
|
||||
IF(NOT TARGET_LABEL)
|
||||
SET(TARGET_LABEL "${TARGET_DEFAULT_LABEL_PREFIX} ${TARGET_NAME}")
|
||||
ENDIF(NOT TARGET_LABEL)
|
||||
|
||||
# This is the important line because it adds WIN32 which tells CMake that this is an MFC/Windows appliation
|
||||
# and not a console application
|
||||
ADD_EXECUTABLE(${TARGET_TARGETNAME} WIN32 ${TARGET_SRC} ${TARGET_H})
|
||||
|
||||
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}")
|
||||
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME})
|
||||
|
||||
SETUP_LINK_LIBRARIES()
|
||||
@@ -149,16 +149,37 @@ void cOSG::InitCameraConfig(void)
|
||||
mViewer->realize();
|
||||
}
|
||||
|
||||
void cOSG::PreFrameUpdate()
|
||||
{
|
||||
// Due any preframe updates in this routine
|
||||
}
|
||||
|
||||
void cOSG::PostFrameUpdate()
|
||||
{
|
||||
// Due any postframe updates in this routine
|
||||
}
|
||||
|
||||
void cOSG::Render(void* ptr)
|
||||
{
|
||||
cOSG* osg = (cOSG*)ptr;
|
||||
|
||||
osgViewer::Viewer* viewer = osg->getViewer();
|
||||
|
||||
viewer->run();
|
||||
// You have two options for the main viewer loop
|
||||
// viewer->run() or
|
||||
// while(!viewer->done()) { viewer->frame(); }
|
||||
|
||||
//viewer->run();
|
||||
while(!viewer->done())
|
||||
{
|
||||
osg->PreFrameUpdate();
|
||||
viewer->frame();
|
||||
osg->PostFrameUpdate();
|
||||
//Sleep(10); // Use this command if you need to allow other processes to have cpu time
|
||||
}
|
||||
|
||||
// For some reason this has to be here to avoid issue:
|
||||
// if you have multiple OSG windows up
|
||||
// and you exit one then all stop rendering
|
||||
AfxMessageBox("Exit Rendering Thread");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/StatsHandler>
|
||||
#include <osgViewer/GraphicsWindowWin32>
|
||||
#include <osgViewer/api/win32/GraphicsWindowWin32>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/KeySwitchMatrixManipulator>
|
||||
#include <osgDB/DatabasePager>
|
||||
@@ -23,6 +23,8 @@ public:
|
||||
void InitCameraConfig(void);
|
||||
void SetupWindow(void);
|
||||
void SetupCamera(void);
|
||||
void PreFrameUpdate(void);
|
||||
void PostFrameUpdate(void);
|
||||
static void Render(void* ptr);
|
||||
|
||||
osgViewer::Viewer* getViewer() { return mViewer.get(); }
|
||||
@@ -35,4 +37,4 @@ private:
|
||||
osg::ref_ptr<osg::Node> mModel;
|
||||
osg::ref_ptr<osgGA::TrackballManipulator> trackball;
|
||||
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user