Code for listing a OGRE--MFC online
In the single-text block architecture of MFC, The onpait message function in the cview adds a settimer to refresh the UI.
On this basis, I used cview to build a plug-in with an MFC multi-threaded UI, and added a dock window with cj60lib.
Cview inserts an ogreappliction. But this listener is used. OIS must be bound to the cmainwnd of the Main Window handle, and the window to be rendered must be bound to the window to be painted, that is, cview.
If no image is available, see the following figure:
More open source things need to be added to the project
I wanted to create a 3D editor.
The docking window is followed by a script to control the writing logic. In other scenarios, all the other special tools are put in the window, and an ogre window can be obtained quickly when the MFC shell window is opened.
However, I have no time to figure it out. I have no technical skills. At least a lot of specific things have not been shelved.
The code here is based on a lot of things in the project. There is definitely a problem. compile it with your mind. Just look at the diagram and the content in the cview.
Http://www.cppblog.com/Files/jimsmorong/ogre_mfc_edit.rar
Ogre MFC
Code:
Http://www.pudn.com/downloads82/sourcecode/windows/bitmap/detail318146.html
Recently I am working on this to display ogre rendering in the MFC framework. The development environment is vs2005.
In fact, it is not difficult to embed it. It is mainly to pass the handle of the MFC main window to the rendersystem of the Ogre rendering system and clean the rendering window at the end of the program.
1) because the Default Configuration window of ogre is not used to initialize the rendersystem, this step must be done by yourself. First, set the configuration file path, and then Round-Robin the available rendersystem. Direct3D9 Render system is used by default.
// Set the plug-in and resource path as before. After setting, you can call the available rendersystem.
Setupresources ();
// Specify the Direct3D9 Render system rendering subsystem.
Rendersystemlist * RL = root: getsingleton (). getavailablerenderers ();
Rendersystemlist: iterator it = RL-> begin ();
D3d9rendersystem * mrsys = NULL;
While (it! = RL-> end ())
{
If (-1! = (* It)-> getname (). Find ("3d9 "))
{
Mrsys = (d3d9rendersystem *) (* it );
Break;
}
It ++;
}
// Manually set the options in the Configuration box.
Mrsys-> initconfigoptions ();
Mrsys-> setconfigoption ("anti aliasing", "NONE ");
Mrsys-> setconfigoption ("floating-point mode", "fastest ");
Mrsys-> setconfigoption ("full screen", "no ");
Mrsys-> setconfigoption ("rendering device", "NVIDIA geforce2 MX/MX 400 ");
Mrsys-> setconfigoption ("vsync", "no ");
Mrsys-> setconfigoption ("video mode", "640x480 @ 32-bit color ");
// Start
Mroot-> setrendersystem (mrsys );
2) the rest of the initialization process is basically the same as exampleapplication, but now the ogre does not need to automatically create a form. You should upload the handle of the MFC View to the previous initialization process.
// Initialization. If it is set to false, the ogre automatic window creation is not required.
Mroot-> initialise (false );
// Manually create a rendering window. Here we pass in the handle of the MFC View
Namevaluepairlist miscparams;
Miscparams ["external?whandle"] = stringconverter: tostring (size_t) mwnd );
Mwindow = mroot-> createrenderwindow ("View", 640,480, false, & miscparams );
After the initialization process is completed, the running program will have a dark MFC window.
3) Because wndproc of the view is used now, we must handle the update and trigger the framestart event by ourselves.
// Trigger the framestart and frameend events
Void Update (void)
{
Mroot-> _ fireframestarted ();
Mwindow-> Update ();
Mroot-> _ fireframeended ();
}
// Call update in the ondraw time of the View
Void cmfcrenderview: ondraw (CDC */* PDC */)
{
Cmfcrenderdoc * pdoc = getdocument ();
Assert_valid (pdoc );
If (! Pdoc)
Return;
// Todo: add the drawing code for the local data here
Update ();
}
This is not enough. The wm_paint event is not controlled by us. It will not be triggered when the form is quiet. Therefore, we can set a timer to simulate frame-free updates,
// Triggered once every 20 ms
Settimer (100, 20, 0 );
Void cmfcrenderview: ontimer (uint nidevent)
{
// Todo: add the message processing program code and/or call the default value here
Update ();
_ Super: ontimer (nidevent );
}
Notes:
1 ...... initialization can be performed at the first execution of ondraw (CDC * PDC), instead of precreatewindow (createstruct & CS), cogremfcview (), or oncreate () this cview subclass is initialized because the hwnd corresponding to the view is not initialized yet...
2 .... ogre is embedded in the MFC, which will lead to overload conflicts of new and other operators. You must choose ogre or MFC for memory management.
(1) Use the memorymanager of ogre and disable calling debug_new of MFC. You must first find the following lines in CPP:
# Ifdef _ debug
# Define new debug_new
# Endif
Replace it with # define ogre_debug_memory_manager 1
In this way, ogre uses its new/delete instead of calling _ heap_alloc_debug in vccrt.
(2) The use of MFC. can refer to the http://www.blogjava.net/wangle/
The specific settings are as follows:
I) In the General tab, switch "UseMFCIn a shared DLL "to" use standard Windows libraries"
II) in the C/C ++/Preprocessor tab, add _ afxdll To The Preprocessor Definitions
Iii) In the linker/input tab, add mfc80d. Lib anywhere before ogremain_d.lib
3 ..... in actual programming, your view class will need to overload functions such as ontimer, ondraw, and onpaint of the cwnd class. In vs2005, there is no class wizzard like vc6.0, this requires you to manually add message ing during the overload process.
For example, if you reload the ontimer class, this function is available in your view class.
Afx_msg void ontimer (uint_ptr nidevent );
In this case, you need to find
Begin_message_map (cogremfcview, cview)
// Standard Print command
On_wm_timer ()
On_command (id_file_print, & cview: onfileprint)
On_command (id_file_print_direct, & cview: onfileprint)
On_command (id_file_print_preview, & cview: onfileprintpreview)
End_message_map ()
And add on_wm_timer (). Then, your timer function will respond and be called.
4 ...... you must delete the root object in your winapp. If you delete the root object in ondestroy () of the View class, or delete it in the destructor, this will cause an error after you close the program. the reason may be that the root deletion time is incorrect!