with the StatsHandler. When the 's' key is pressed, the rendering
window will be halted. I tried solving the problem by commenting a
line in CMFC_OSG_MDIView::OnKeyDown() and it seems to work now.
Another improvement here is to use a thread class derived from
OpenThreads to replace the old _beginthread(). It helps a lot in
keeping a high frame rate when you open more than one MDI child
windows. And the application using OpenThreads in my opinion will be
more compatible and portable."
graphics context and link it with a slave camera. I don't know the
reason we perform like that, which will cause a problem that the
GUIEventHandler may not obtain correct window coordinates because the
main camera will use a default input range to receive events from the
slave camera's graphics context. It is also weird to see the
addSlave() used in non-cluster applications, which beginners will be
confused with.
I've make a slightly modification to the osgviewerMFC example to make
it work without setting slave cameras. I've tested with the MDI
framework and everything seems fine."
Attached the modified version of MFC_OSG_MDIView.cpp and MFC_OSG_MDIView.h."
Note from Robert Osfield, submission came with wrong header file, so have had
to guess at what it should be, fingers crossed it worn't break windows build... :-)
Changes:
MFC_OSG.cpp:
Removed pixelformatdesciptor from the class initialization.
Used setInheritedWindowPixelFormat to true so it will setup the pixelformat for the window.
Added class destructor code.
MFC_OSG.h:
Removed the ref_ptr on osgViewer::Viewer
MFC_OSG_MDIViewer.cpp:
Changed the OnDestroy function code.
Added WaitforSingleObject with thread handle for the MFC render handle.
MFC_OSG_MDIView.h:
Added class variable for MFC Render Thread Handle for use with the WaitforSingleObject.
"
Changed this back to setup_example since WIN32 flag is now supported.
MFC_OSG.h:
Added flag to indicate when the rendering thread has exited.
MFC_OSG.cpp:
Code modifications to support rendering flag thread exit.
MFC_OSG_MDIView.cpp:
Change to OnDestroy function to wait until we get render thread exit flag is true before we close the window.
Main Exit Process:
User presses escape button
Viewer captures escape button and stops threading etc.
Viewer sets Done when shutdown is complete
MFC Render Thread monitors viewer->done for true
MFC Render Thread exits while loop and sets MFC Done flag
MFC View Window monitors MFC Done flag and then closes/destroys the window
"
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.
"