[fixed]OpenGL texture matrix problem

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
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

[fixed]OpenGL texture matrix problem

Post by pc0de »

I just noticed my texture matrix animation code stopped working against the latest revision of the trunk (r3519). I am able to reproduce the problem with the following test:

Code: Select all

// animated texture matrix test.
void test10()
{
    static bool m_running = true;

    class EventReceiver : public IEventReceiver
    {
        bool OnEvent(const SEvent& event)
        {
            if ((event.EventType == irr::EET_KEY_INPUT_EVENT) &&
                !event.KeyInput.PressedDown &&
                (event.KeyInput.Key == KEY_ESCAPE))
                m_running = false;
            return false;
        }
    };

    SIrrlichtCreationParameters cp;
    //cp.DriverType = EDT_DIRECT3D9;
    cp.DriverType = EDT_OPENGL;
    cp.WindowSize = dimension2du(640,480);
    cp.EventReceiver = new EventReceiver();

    IrrlichtDevice* m_device = createDeviceEx(cp);
    if(!m_device)
        return;

    m_device->getCursorControl()->setVisible(false);
    IFileSystem* m_fileSystem = m_device->getFileSystem();
    IVideoDriver* m_videoDriver = m_device->getVideoDriver();
    ISceneManager* m_sceneManager = m_device->getSceneManager();
    IGUIEnvironment* m_gui = m_device->getGUIEnvironment();

    ICameraSceneNode* m_camera = m_sceneManager->addCameraSceneNodeFPS(0, 100, 0.02f);
    m_camera->setPosition(vector3df(0,0,-10));

    // set up plane mesh to face the camera
    dimension2df tileSize(150,150);
    dimension2d<u32> tileCount(1,1);
    IAnimatedMesh* pmesh = m_sceneManager->addHillPlaneMesh("testMesh" ,tileSize, tileCount);
    IAnimatedMeshSceneNode* pnode = m_sceneManager->addAnimatedMeshSceneNode(pmesh);
    pnode->setPosition(vector3df(0, 0, 150));
    pnode->setRotation(vector3df(-90, 0, 0));

    // set the hillplane material texture & save a reference
    // to the texture matrix.
    SMaterial& material = pnode->getMaterial(0);
    ITexture* tex = m_videoDriver->getTexture("../media/water.jpg");

    material.setTexture(0,tex);
    material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
    material.setFlag(EMF_LIGHTING,false);
    matrix4& textureMatrix = material.TextureLayer[0].getTextureMatrix();

    u32 lastTime = m_device->getTimer()->getTime();
    vector2df rcenter, trans, scale(1.f, 1.f);
    f32 scrollSpeed = 0.5f;

    while(m_device->run() && m_running)
    {
        m_videoDriver->beginScene(true, true, SColor(255,100,101,140));

        // update the texture matrix (scroll left)
        u32 curTime = m_device->getTimer()->getTime();
        irr::u32 t = curTime - lastTime;
        if(t)
        {
            lastTime = curTime;
            trans.X += t * 0.001f * scrollSpeed;
            textureMatrix.buildTextureTransform(0.f, rcenter, trans, scale);
        }

        m_sceneManager->drawAll();
        m_gui->drawAll();
        m_videoDriver->endScene();
    }

    m_device->drop();
}
This code simply scrolls a texture from right to left and it works fine using the DirectX driver. It appears the problem was introduced by the r3500 update of COpenGLDriver.cpp (r3499 works fine).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, you're right. I misread the matrix creation code and removed something which shouldn't be removed. Fixed now. Thanks.
Seems also that none of our tests so far really tested if texture matrix works. I've added your test to our test suite. If you have more tests just submit them for inclusion into the test suite. This really helps to improve the commit quality and overall development.
pc0de
Posts: 300
Joined: Wed Dec 05, 2007 4:41 pm

Post by pc0de »

Thanks for the quick fix - everything is working well again.

The tests I've been building are primarily a result of isolating/minimizing the code needed to reproduce problems I encounter so I currently don't have any new tests to post. I'll definitely post them when I create them in the future.

Thanks again for the update.
Post Reply