【Irrlicht鬼火引擎】 安装配置Irrlicht鬼火引擎

一、下载引擎

官方网站:http://irrlicht.sourceforge.net/‎

官方网站需要FQ才能进入,如果不想FQ,可以通过其他下载地址:
CSDN下载:http://download.csdn.net/detail/fxrz12/4932156

下载后解压,学习引擎的第一步就完成了。

二、使用引擎

想要使用Irrlicht引擎,我们需要在程序中引入头文件<irrlicht.h>,该头文件在Irrlicht引擎的include目录下。为了让编译器能够找到头文件,我们需要在IDE中设置一下路径。

下面介绍一下visual studio 2010的配置方法。

(1)打开visual studio 2010,新建一个工程

(2)在菜单中选择Project->Properties,会弹出属性面板。Configuration Properties->VC++ Directories的目录下,分别有Include Directories和Library Directories,在这两个栏中添加路径信息。

include: 引擎安装目录include
library: 引擎安装目录libWin32-visualstudio 注:在lib中选择符合你的系统类型的文件夹

配置完成后,点击确认,IDE的设置就完成了。

(3)一件必须要做的事
在引擎安装目录inVisualStudio中,找到Irrlicht.dll文件,把它复制到你的工程文件目录下,否则运行的时候会报错的。

三、简单尝试

建立一个main.cpp文件,把下边的代码复制进去,尝试是否可以运行,你的第一个使用Irrlicht的程序就完成了!

#include <irrlicht.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);

    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;
}

  

当然,如果你有模型的素材,使用如下的代码添加进入程序之中,运行效果会变得更好:

  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") );
    }

  

四、常见问题

(1)fatal error C1083: Cannot open include file: 'irrlicht.h': No such file or directory


解决:没有设置好include directory, 看看自己的路径是不是设置错啦

(2)LINK : LNK6004: HelloWorld.exe not found or not built by the last incremental link; performing full link
LINK : fatal error LNK1104: cannot open file "Irrlicht.lib"
Error executing link.exe

解决:没有设置好library directory, 看看自己的lib路径是不是设置错了


(3)This application has failed to start because Irrlicht.dll was not found. Re-installing the application may fix this problem


解决:没有复制Irrlicht.dll文件到项目目录下,妥妥的。复制过去就好了。

原文地址:https://www.cnblogs.com/tail/p/3190808.html