OgreSDK的环境配置这里不谈,大家可以在网上找到很多文章
这里只列出构建一个Ogre最最简单的系统所需要的代码
/* ===================================================== */
//
// ◢█████◣ ◢██████◣
// ◢◤ ◥◣ ◢◤ ◥◣
// ◤ ◥◣ ◢◤ █
// ▎ ◢█◣ ◥◣◢◤ ◢█◣ █
// ◣ ◢◤ ◥◣ ◢◣ ◥◣ ◢
// ◥██◤ ◢◤ ◥◣ ◥█◤
// █ ● ● █
// █ 〃 ▄ 〃 █
// ◥◣ ╚╩╝ ◢◤
// ◥█▅▃▃ ▃▃▅█◤
// ◢◤ ◥◣
// █ █
// ◢◤▕ ▎◥◣
// ▕▃◣◢▅▅▅◣◢▃▎
//
// Author : Wangxu
// Create Date :
// Description :
//
/* ===================================================== */
#pragma warning(disable: 4251)
#pragma warning(disable: 4193)
#pragma warning(disable: 4275)
#include <Ogre/Ogre.h>
// 链接基本的类和函数
#pragma comment(lib,"OgreMain_d.lib")
using namespace Ogre;
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
// 构造一个Root类,使用min_plugins.cfg作为插件的配置文件
Root* root = new Root("min_plugins.cfg");
// 弹出设置对话框
if(!root->showConfigDialog())
{
return -1;
}
// 初始化,创建显示窗口
RenderWindow* window = root->initialise(true);
// 得到场景管理器
SceneManager* sceneMgr = root->createSceneManager(ST_GENERIC);
// 得到摄像机
Camera* cam = sceneMgr->createCamera("MainCamera");
// 得到与该摄像机和窗口关联的视口
Viewport* viewport = window->addViewport(cam);
// 设置摄像机的基本属性
cam->setAspectRatio((Ogre::Real)viewport->getActualWidth() / (Ogre::Real)viewport->getActualHeight());
cam->setNearClipDistance(5);
cam->setPosition(0,0,600);
// 显示窗口,开始渲染,进入无限循环
root->startRendering();
return 0;
}
配置文件:min_plugins.cfg
# Defines plugins to load
# Define plugin folder
PluginFolder=.
# Define plugins
Plugin=RenderSystem_Direct3D9_d