irrlicht引擎入门——安装和运行第一个实例
阅读原文时间:2021年04月22日阅读:1

想找个图像引擎体验下,网上逛了半天之后选定了riilicht。据说好上手,比较适合我这种仅仅想体验一下的人。但是发现各种tutorial被墙(也许只是教育网被墙)外加各种tutorial中的链接失效,折腾若干小时才把hello world跑通,作此记录。

下载地址

现在该引擎的下载地址为http://sourceforge.net/projects/irrlicht/?source=directory

网上大多数说的那个地址已经下不到了(至少教育网不行)

教程地址

其实最容易得到的教程在源码包里doc/html中

环境配置

vs2010中,直接新建空项目,在解决方案窗口中点右键,打开属性对话框如图配置

将下载来的压缩包解压所得文件夹中的include文件夹添加到“包含目录”中,lib目录下对应文件夹添加到“库目录”中。

ps:这时候跑例子还是会找不到Irrlicht.dll。所以最简单直白的方法:解压目录\bin\Win32-VisualStudio中找到他,然后复制到system32中。

第一个例子

例子是跑不通的!!!其实就路径问题。将代码中两个路径修改下就行,偷懒直接改绝对路径。(把解压路径修改下就行)

#include<irrlicht.h>
#include<iostream>

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

源码就不解释了,各位自己翻看教程就行

给张最后的运行效果图


哈哈,这长相…………晚上做梦不怪我^^

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章