【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: 引擎安裝目錄\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文件到項目目錄下,妥妥的。複製過去就好了。

原文地址:http://www.cnblogs.com/tail/p/3190808.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章