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.
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...)
[Solved] OnResize does not (correctly) call glViewport
[Solved] OnResize does not (correctly) call glViewport
Last edited by kormoran on Fri Feb 05, 2016 12:54 am, edited 1 time in total.
Re: (bug?) OnResize does not (correctly) call glViewport
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.
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.
Re: (bug?) OnResize does not (correctly) call glViewport
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::OnResizehendu 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.
Unless there is another Irrlicht event raised after the window resize...
Re: (bug?) OnResize does not (correctly) call glViewport
You could poll it every frame with getViewPort. Returning a reference and comparing the rect to the old rect will take minimal cpu.
Re: (bug?) OnResize does not (correctly) call glViewport
Not exactly elegant, but it works. Here's the modified main loop:hendu wrote:You could poll it every frame with getViewPort
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();
};