OGRE3D入门探索01:将渲染窗口嵌入到Win32主窗口

从《OGRE3D引擎入门重拾》这篇文章开始,本系列关注OGRE3D渲染引擎及其周边应用。

本文以一个简单的示例来说明如何将Ogre的渲染窗口嵌入到另一个父窗口中,

为了增加趣味性(就是这么任性哈)我特意增加了FMOD的音乐播放支持。

首先将代码贴上来吧

/
//  CREATED by fengyhack [@<163.com><gmail.com><qq.com><live.cn>]
//  OGRE Example: Embeded window, Playing sound with FMOD.
/
#include <Windows.h>
#include <OgreRoot.h>
#include <OgreRenderSystem.h>
#include <fmod.hpp>
#include <string.h>
#pragma comment(lib,"OgreMain.lib")
#pragma comment(lib,"fmod_vc.lib")

using namespace Ogre;
using namespace std;

#define STR_RENDER_SYSTEM_DirectX9  "Direct3D9 Rendering Subsystem"
#define STR_RENDER_SYSTEM_OpenGL  "OpenGL Rendering Subsystem"

#define WINDOW_WIDTH	800	
#define WINDOW_HEIGHT	600		

LRESULT CALLBACK	WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR strCmdLine, INT nCmdShow)
{
	string rsName = STR_RENDER_SYSTEM_DirectX9;  // Using DirectX9
	string windowTitle = string("OGRE Example Window - ") + rsName;
	int width = WINDOW_WIDTH, height = WINDOW_HEIGHT;

	// Ogre Objects: Log, Root, RenderSystem, etc.
	LogManager* logMgr = new LogManager;
	Log* m_pLog = LogManager::getSingleton().createLog("LoggerFile.log", true, true, false);
	Root* m_pRoot = new Root("plugins.cfg", "config.cfg");
	RenderSystemList rsList = m_pRoot->getAvailableRenderers();
	RenderSystemList::iterator it = rsList.begin();
	RenderSystem* pRenderSubystem = NULL;
	while (it != rsList.end())
	{
		pRenderSubystem = *it;
		if (pRenderSubystem->getName() == rsName)
		{
			m_pRoot->setRenderSystem(pRenderSubystem);
			break;
		}
		++it;
	}
	pRenderSubystem = m_pRoot->getRenderSystem();
	if (pRenderSubystem == NULL)
	{
		string msg = "FAILED to set Rendering Subsystem: " + rsName;
		MessageBox(NULL, msg.c_str(), "ERROR", MB_OK);
	}
	if (!m_pRoot->restoreConfig())
	{
		m_pRoot->showConfigDialog();
	}

	//
	// Do somethig (i.e. initialization) here
	// E.G. 
	// Read properties from config.cfg
	// and then set the parameters such as width/height, etc.
	//

	// Win32 Window - Parent/External window
	LPCSTR wcexName = "MainWindow";
	WNDCLASSEX wndClass = { 0 };
	wndClass.cbSize = sizeof(WNDCLASSEX);
	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc = WndProc;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hInstance = hInst;
	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //LoadIcon(hInst, IDI_ICON1);
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
	wndClass.lpszMenuName = NULL;
	wndClass.lpszClassName = wcexName;
	RegisterClassEx(&wndClass);
	DWORD dwStyle = WS_SYSMENU | WS_SIZEBOX;
	HWND hWnd = CreateWindow(wcexName, windowTitle.c_str(), dwStyle, 
		100, 100, width, height, NULL, NULL, hInst, NULL);
	
	// Ogre Window will be embedded on the Parent/External Window(aka. Win32 Window)
	m_pRoot->initialise(false);
	NameValuePairList miscParams;
	// HWND hWnd: Ogre Window's parent window's handle
	miscParams["parentWindowHandle"] = StringConverter::toString((ULONG)hWnd); 
	m_pRoot->createRe
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值