创建OGRE的第一个例子 (转)
2014-06-04 21:22
417 查看
OGRE作为一个图形渲染引擎,要学习它的话首先就得学习它如何显示了.
下面是一个在屏幕上显示出一个立方体的例子
这里需要一个cube.mesh的模型文件,可以在OGRESDK/media/models中找到.
不过我们不需要移动它,我们要把工作目录设置成OGRESDK/Bin/debug就成了.
在它里面有个resources.cfg文件,它的作用就是来设置一些资源文件的路径的,我们可以看到它里面有行FileSystem=../../media/models.
好了下面看下这个例子
example.h文件
#ifndef __example1_h_
#define __example1_h_
#include "ExampleApplication.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif
class Example1App:public ExampleApplication
{
public:
Example1App()
{
}
~Example1App()
{
}
protected:
virtual void createScene(void);
};
#endif // #ifndef __example1_h_
example.cpp文件
#include "example1.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
void Example1App::createScene(void)
{
this->mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5,0.5,0.5,1));
Ogre::Entity* pEntity=this->mSceneMgr->createEntity("entity1","cube.mesh");
Ogre::SceneNode* pSceneNode=this->mSceneMgr->getRootSceneNode()->createChildSceneNode("CubeNode");
pSceneNode->attachObject(pEntity);
}
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create application object
Example1App theApp;
try {
//app.go();
theApp.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
下面是一个在屏幕上显示出一个立方体的例子
这里需要一个cube.mesh的模型文件,可以在OGRESDK/media/models中找到.
不过我们不需要移动它,我们要把工作目录设置成OGRESDK/Bin/debug就成了.
在它里面有个resources.cfg文件,它的作用就是来设置一些资源文件的路径的,我们可以看到它里面有行FileSystem=../../media/models.
好了下面看下这个例子
example.h文件
#ifndef __example1_h_
#define __example1_h_
#include "ExampleApplication.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif
class Example1App:public ExampleApplication
{
public:
Example1App()
{
}
~Example1App()
{
}
protected:
virtual void createScene(void);
};
#endif // #ifndef __example1_h_
example.cpp文件
#include "example1.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
void Example1App::createScene(void)
{
this->mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5,0.5,0.5,1));
Ogre::Entity* pEntity=this->mSceneMgr->createEntity("entity1","cube.mesh");
Ogre::SceneNode* pSceneNode=this->mSceneMgr->getRootSceneNode()->createChildSceneNode("CubeNode");
pSceneNode->attachObject(pEntity);
}
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create application object
Example1App theApp;
try {
//app.go();
theApp.go();
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
相关文章推荐
- 创建OGRE的第一个例子
- ogre 第一个例子编译运行
- OGRE步步惊心 - 第003天: 第一个机器人例子的扩展
- 使用Eclipse创建第一个Struts例子
- windows下erlang环境搭建和创建第一个简单例子
- windows下erlang环境搭建和创建第一个简单例子
- 创建第一个sencha touch例子
- wcf创建基于tcp协议的iis寄宿服务的第一个例子
- 使用Intellij IEDA创建第一个hibernate例子
- Ogre学习笔记(二)创建第一个OGRE程序
- 创建第一个JBPM6项目并且运行自带的helloword例子(JBPM6学习之三)
- 使用Dagger2创建的第一个小例子
- 使用gcc创建第一个VTK例子
- lucene学习的第一个例子之创建索引
- BootStrap入门_创建第一个例子
- 【Ogre开发】之二:创建自己的第一个Ogre程序
- 使用Intellij IEDA创建第一个springmvc例子
- 创建第一个JBPM6项目并且运行自带的helloword例子(JBPM6学习之三)
- 我的第一个Atlas例子
- 创建我的第一个BLOG