最近我了解、学习了Irrlicht(鬼火),在这儿跟大家分享一下这个游戏引擎,关于本引擎的详细内容自己网上学习。(由于本人也是菜鸟一枚,也是第一次发博客,所以本文章有错的地方,希望大家多多包涵!)
好了,现在进入正题。
1.环境搭建
首先我们将“irrlicht-1.7.1.zip”这个压缩包减压,先放到一边。
然后在VS2012上创建一个C++空项目,然后添加一个源文件(文件名自己命名)。
然后选中此项目,右键=》属性=》配置属性=》VC++目录,选择右边的包含目录,出现下拉列表框,选择编辑,添加“irrlicht-1.7.1”中的include文件。同理,选择右边的库目录,出现下拉列表框,选择编辑,添加lib文件。最后应用,确定。(这种方法配置的环境应该是暂时的,以前配置DX环境的时候,这样配的结果就是每建一个项目就要配置一次环境,很麻烦!)
第二种方法就是:跟第一种方法一样的创建一个项目。这次我们在上方的菜单栏中选择视图=》属性管理器[外链图片转存中...(img-yPekD53i-1651737347485)]
2.经典例子:Hello,World!
#include <irrlicht.h>
#include <windows.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
if (!device)
return 1;
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<s32>(10,10,260,22), true);
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
这个程序就靠自己去理解,嘿嘿
3.遇到的麻烦
当我输入上述代码时,出现了一个警告框:本计算机丢失irrlicht.dll。但是,在irrlicht的SDK中的bin文件夹中有这个文件。所以,我的解决办法是将其放入自己建的项目的文件夹中去就可以了。(我也不知道为什么会出现这个问题,或许是自己建项目的时候哪儿出问题了吧!)