ogre1.7 cookbook_OgreMfc

新建一个单文档mfc应用OgreMfc,项目配置与win32相同,Engine.h, Engine.cpp也与win32 application相同。

OgreMfc.h中加:

public:
CEngine* m_pEngine;
void InitEngine(HWND hwnd);
void CloseEngine();

OgreMfc.cpp中的BOOL COgreMfcApp::InitInstance()的最后+:

InitEngine(m_pMainWnd->m_hWnd);

OgreMfc.cpp中的int COgreMfcApp::ExitInstance()+:

CloseEngine();

void COgreMfcApp::InitEngine(HWND hwnd)
{
	m_pEngine = new CEngine(hwnd);
}

void COgreMfcApp::CloseEngine()
{
	if (m_pEngine)
	{
		delete m_pEngine;
		m_pEngine = 0;
	}
}

  

OgreMfcView类添加OnPaint()消息响应函数;

void COgreMfcView::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    // TODO: 在此处添加消息处理程序代码
    // 不为绘图消息调用 CView::OnPaint()

    CEngine* pEngine = ((COgreMfcApp*)AfxGetApp())->m_pEngine;
    if (pEngine && pEngine->m_Root)
    {
        pEngine->m_Root->renderOneFrame();
    }
}

可选的代码:(加不加都可以,窗口未显示渲染处的场景时,可以移动一下窗口就显示了。。)

BOOL COgreMfcDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;

// TODO: 在此添加重新初始化代码
// (SDI 文档将重用该文档)
UpdateAllViews(NULL);

return TRUE;
}

 

PS:mfc程序退出时,显示有大量的内存泄露。。。解决办法:

http://www.blogjava.net/wangle/archive/2008/11/18/124813.html

i) in the General tab, switch "Use MFC in 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

另一种方法是,使用Ogre自己的MemoryManager,并且禁止调用MFC的DEBUG_NEW,这需要先

#define OGRE_DEBUG_MEMORY_MANAGER 1

然后删除cpp中的以下行

#ifdef _DEBUG 
#define new DEBUG_NEW 
#endif

这样Ogre中会使用自己的new/delete,而不是调用vccrt中的_heap_alloc_debug

我用的第一种方法,另外VS2010中,应该是mfc100d.lib.......

 

转载于:https://www.cnblogs.com/kex1n/archive/2012/08/30/2664199.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值