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


一、下載引擎

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

官方網站需要翻牆才能進入,如果不想翻牆,可以通過其他下載地址:
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: 引擎安裝目錄\lib\Win32-visualstudio 注:在lib中選擇符合你的系統類型的文件夾

配置完成后,點擊確認,IDE的設置就完成了。

(3)一件必須要做的事
在引擎安裝目錄\bin\VisualStudio中,找到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文件到項目目錄下,妥妥的。復制過去就好了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM