[Solved] OnResize does not (correctly) call glViewport

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

[Solved] OnResize does not (correctly) call glViewport

Post by kormoran »

I'm testing Irrlicht in a resizable window, and the first thing I saw is the aspect ratio problem: every time the Irrlicht window is resized, the aspect ratio goes awry. :evil:

In the forums I read of some solutions to this problem: they all call setViewport() to fix it, and it calls glViewport... but it's called even in IVideoDriver::OnResize(): the only difference is some calculations with rendering targets missing in the latter. :|

So what's happening there? is OnResize in need of a fix or is there a reason to make users call setViewPort on their own?

(EDIT: yes, I'm using EDT_OPENGL...)
Last edited by kormoran on Fri Feb 05, 2016 12:54 am, edited 1 time in total.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: (bug?) OnResize does not (correctly) call glViewport

Post by hendu »

Aspect ratio is controlled by the camera, the viewport controls which part of the window is drawn on. There's no call to camera->setAspectRatio that I can see, so after resizing you can call it yourself as a workaround.

I suspect there's no automatic call since you can have dozens of cameras without irr's knowledge, and some of them might have "wrong" aspects on purpose.
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: (bug?) OnResize does not (correctly) call glViewport

Post by kormoran »

hendu wrote:I suspect there's no automatic call since you can have dozens of cameras without irr's knowledge, and some of them might have "wrong" aspects on purpose.
I see. So, do I need to hook the original onResize event from windows on my own and call setAspectRatio? There is no way of calling my code from IVideoDriver::OnResize :-(
Unless there is another Irrlicht event raised after the window resize...
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: (bug?) OnResize does not (correctly) call glViewport

Post by hendu »

You could poll it every frame with getViewPort. Returning a reference and comparing the rect to the old rect will take minimal cpu.
kormoran
Posts: 47
Joined: Mon Dec 28, 2015 4:50 pm
Location: Tolentino

Re: (bug?) OnResize does not (correctly) call glViewport

Post by kormoran »

hendu wrote:You could poll it every frame with getViewPort
Not exactly elegant, but it works. Here's the modified main loop:

Code: Select all

    core::rect<s32> actualvp;
    core::rect<s32> old_vp;
 
while((!Terminate)&&(IrrDevice->run()))
    {
        if(old_vp != (actualvp = IrrDriver->getViewPort()))
        {
            old_vp = actualvp;
            Stager.setARatio((float)actualvp.getWidth()/(float)actualvp.getHeight());
        };
        IrrDriver->beginScene(true, true, SColor(0,200,200,200));
        IrrSmgr->drawAll();
        IrrEnv->drawAll();
        IrrDriver->endScene();
    };
 
(Stager is my implementation of irr::scene::ISceneManager class; setARatio() is a wrapper for ICameraSceneNode.setAspectRatio())
Post Reply