您的位置:首页 > 其它

创建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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: