setViewPort() doesn't work

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
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

setViewPort() doesn't work

Post by blackMasoon »

Hello I am trying to set ViewPort for my app to have an universal static resolution. I did sth like this:

Code: Select all

pManager->getDriver()->setViewPort(core::rect<s32>(
													   (deskres.Width-1024)/2,
													   (deskres.Height-768)/2,
													    deskres.Width-((deskres.Width-1024)/2),
														deskres.Height-((deskres.Height-768)/2)
													   )
									   );
But it works only in my menu state... When i switch to new state it just looks like there was no viewPort set.... All states derive update() method from a gamePlayState class so I can't understand why does it work for one state and doesn't for another... there are no device/driver settings overriden... what may be the reason?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: setViewPort() doesn't work

Post by greenya »

blackMasoon wrote:what may be the reason?
anything.

Your post looks to me like "i have function called doJob() and when i call it, nothing happens. what may be the reason?" :)


My way is to take an example and try to repeat the problem in the code with minimum lines. So i took 02.Quake3Map and tested IVideoDriver::setViewPort(); i'm not sure how it supposed to work but i have 2 ways of usage this method:
1) outside device->run() cycle (this way seems to me correct if all we need is to set viewport and expect it to stay same until we change it).
2) inside device->run() cycle, so we call it each frame we render.
Next images show the difference of code samples i used (selected code -- the code i added into original Irrlicht' example):
Image

So here is the result:

Software and BurningsVideo renderers: works the same; both ways works correct;
OpenGL and Direct3D8/9 renderers: works only when using second way (when we setViewPort() every render cycle); /* maybe "device->run()" implementation resets viewport value for this renderes, but i didin't looked into it. */

Working result in OpenGL and Direct3D9:
Image

As you may notice from the image, we see the difference: OpenGL's beginScene() implementation clears all the frame buffer with specified color /* video::SColor(255,200,200,200) */ , not only viewport as Direct3D does. The same behavior (like with OpenGL) also seen in Software and BurningsVideo renderers. /* i don't know what is correct, but i believe it must be the same in all renderers; and if asking me -- D3D do it correct, when touching only specified viewport. */

/* I'm not sure is next investigation a bug, maybe the documentation on setViewPort() should just describe when it is expected and correct to call this method. */
For example we can write next:
...
int lastFPS = -1;

while(device->run())
{
if (device->isWindowActive())
{
driver->setViewPort(core::recti(100, 100, 300, 300));
driver->beginScene(true, true, video::SColor(255,200,200,200));
driver->setViewPort(core::recti(100, 100, 500, 300));
smgr->drawAll();
driver->endScene();
...
and Direct3D9 - the only render from all 4 that shows correct result (all other renders renders into 100,100,500,300 with full update):
Image
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

Well i supose You didn't understand me.. In each example you shown viewport worked (I mean that box that defines where is it on screen). What I ment was that even if I called setViewPort(core::recti(100,100,300,300)) I receive a screen like with setViewPort(core::recti(0,0,maxResX,maxResY)) where maxResX & maxResY are the values of screen resolution defined on the begining of program.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Since greenya found a good point here, I'll move this to the bug forum. OT's problem seems no real problem so far, unless we get full code and justification why there's a problem at all.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

I just noticed on the last screen i made (with red comments) that D3D not so perfect as i described: notice that left image stretched, which means that it uses "100-500" viewport for drawing, but for clearing buffers -- only "100-300".
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

But I don't change the renderer between states... That is why I can't understand that for one state it sets the ViewPort and for another with the same settings it doesn't...
Post Reply