OpenGL near-plane seems incorrect

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

OpenGL near-plane seems incorrect

Post by CuteAlien »

I just found out that our near-value in OpenGL behaves somewhat strange. It does not clip at the correct distance. For example it's possible to see things sometimes even if it's larger than the far-plane. Also the near-plane seems to change depending on the far-plane distance. In DirectX everything is as expected.

To test use the following code and play with the setNearValue and setFarValue settings:

Code: Select all

 
#include <irrlicht.h>
 
using namespace irr;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
 
int main(int argc, char *argv[])
{
    IrrlichtDevice * Device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640,480) );
    //IrrlichtDevice * Device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<u32>(640,480) );   // that one is fine
    if (!Device)
        return false;
    
    scene::ISceneManager* smgr = Device->getSceneManager();
    gui::IGUIEnvironment* guiEnv = Device->getGUIEnvironment();
    video::IVideoDriver* videoDriver =  Device->getVideoDriver();   
 
    // looking straight at the cube
    irr::scene::ICameraSceneNode* cam = smgr->addCameraSceneNode (0, core::vector3df(0, 0, 0),
                                core::vector3df(0, 0, 100),
                                -1);
    cam->setNearValue(35.f);
    cam->setFarValue(62.f); // far value is correct
 
    // center 30 units away, cube from 20-40 units distance
    irr::scene::ISceneNode * cube = smgr->addCubeSceneNode (20.0f, 0, -1, 
                            core::vector3df(0, 0, 30),
                            core::vector3df(0, 0, 0),
                            core::vector3df(1.0f, 1.0f, 1.0f));
    cube->setMaterialFlag(irr::video::EMF_LIGHTING, false);
    cube->setMaterialFlag(irr::video::EMF_WIREFRAME, true);
    cube->setMaterialFlag(irr::video::EMF_BACK_FACE_CULLING, false);
 
    // center 30 units away, cube has only size 1
    cube = smgr->addCubeSceneNode (1.0f, 0, -1, 
                            core::vector3df(0, 0, 30),
                            core::vector3df(0, 0, 0),
                            core::vector3df(1.0f, 1.0f, 1.0f));
    cube->setMaterialFlag(irr::video::EMF_LIGHTING, false);
    cube->setMaterialFlag(irr::video::EMF_WIREFRAME, true);
    cube->setMaterialFlag(irr::video::EMF_BACK_FACE_CULLING, false);
 
    while ( Device->run() )
    {
        if ( Device->isWindowActive() )
        {
            videoDriver->beginScene(true, true);
 
            smgr->drawAll();
            guiEnv->drawAll();
 
            videoDriver->endScene();
        }
        Device->sleep( 1 );
    }
 
    Device->closeDevice();
    Device->drop();
    
    return 0;
}
 
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply