5

我有以下代码:

#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main(int argc, char** argv)
{
    IrrlichtDevice *device =
        createDevice(EDT_SOFTWARE, dimension2d<unsigned int>(640, 480), 16,
            false, false, false, 0);

    device->setWindowCaption(L"Train Simulator Demo");

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    IAnimatedMesh* mesh1 = smgr->getMesh("media/simple_engine.b3d");
    IAnimatedMesh* mesh2 = smgr->getMesh("media/simple_track.b3d");

    IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode( mesh1 );
    IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode( mesh2 );

    if (node1)
        node1->setMaterialFlag(EMF_LIGHTING, false);

    if (node2)
    {
        node2->setMaterialFlag(EMF_LIGHTING, false);
        node2->setMaterialTexture( 0, driver->getTexture("media/grass.jpg") );
    }

    ICameraSceneNode * pCamera = smgr->addCameraSceneNode(0, vector3df(5,0,5), vector3df(0,0,0));

    pCamera->setNearValue(0.5f);
    pCamera->setFarValue(40.0f);

    while(device->run())
    {
        driver->beginScene(true, true, SColor(0,0,0,0));

        u32 cur_time = device->getTimer()->getTime();
        float f_time = (float)cur_time / 1000.0f;

        // Change the camera
        pCamera->setPosition(vector3df(sinf(f_time) * 8.0f ,3.0f ,cosf(f_time) * 8.0f));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }

    device->drop();

    return 0;
}

...运行时会产生以下结果:

替代文字

...这很好,只是草应该是 16x16 正方形的网格,并且看起来某些三角形由于某种原因被剪裁了。这似乎也与仅部分显示在屏幕上的三角形有关,因为仅显示完全在窗口视口内的三角形。我怎样才能解决这个问题?

额外的:

操作系统: Ubuntu 10.04 64 位
Irrlicht版本:1.7 beta

4

1 回答 1

3

原来问题在于我使用的是软件渲染器而不是 OpenGL 渲染器。

所以第 13 行:

IrrlichtDevice *device =
    createDevice(EDT_SOFTWARE, dimension2d<unsigned int>(640, 480), 16,
        false, false, false, 0);

变成:

IrrlichtDevice *device =
    createDevice(EDT_OPENGL, dimension2d<unsigned int>(640, 480), 16,
        false, false, false, 0);
于 2010-11-22T00:38:47.110 回答