为什么三角形会被剪裁在这个网格中?

发布于 2024-10-04 04:17:54 字数 2093 浏览 3 评论 0原文

我有以下代码:

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

...运行时会产生以下内容:

alt text

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

其他:

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

I have the following code:

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

...which when run produces the following:

alt text

...which is fine except that the grass is supposed to be a grid of 16x16 squares and it looks like some of the triangles are being clipped for some reason. It also appears that this has something to do with the triangles being only partially displayed on the screen as only the triangles that are completely within the window's viewport are being displayed. How can I fix this?

Additional:

OS: Ubuntu 10.04 64-bit
Irrlicht version: 1.7 beta

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2024-10-11 04:17:54

结果发现问题是我使用的是软件渲染器而不是 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);

Turns out that the problem was that I was using the software renderer instead of the OpenGL renderer.

So line 13:

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

Becomes:

IrrlichtDevice *device =
    createDevice(EDT_OPENGL, dimension2d<unsigned int>(640, 480), 16,
        false, false, false, 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文