Offscreen viewport

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
Linkin Puck
Posts: 36
Joined: Sat Feb 06, 2010 11:52 am

Offscreen viewport

Post by Linkin Puck »

I need to render to a viewport that is slightly off the screen. For example, instead of the viewport's top left coordinate being at 0,0 I would like it to be at -10,-10.

The problem is that all the video drivers have a setViewPort() function that clips to fixed dimensions (defined as the top left being at 0,0 and the bottom right set from the current getCurrentRenderTargetSize()).

Because this clipping results in my output dimensions changing (ie my output width and/or height are altered), this means that the projection is changed. Obviously, this results in rendering looking incorrect because it appears squashed.

I suspect that the reason for the clip is that OpenGL/DirectX cannot handle a viewport offscreen? Is that the case?

If so, does anyone have any idea as to how I can get around this limitation?

Thanks in advance!
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

well you can render the scene to a texture and then render a screen quad slitly setoff with the texture applied that will work for sure.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Linkin Puck
Posts: 36
Joined: Sat Feb 06, 2010 11:52 am

Post by Linkin Puck »

Thanks Sudi, I already thought of that but it will be too slow.

Any ideas how to get the offscreen viewport?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

and why will this be to slow?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Linkin Puck
Posts: 36
Joined: Sat Feb 06, 2010 11:52 am

Post by Linkin Puck »

Sudi wrote:and why will this be to slow?
How could your method possibly be the same speed or faster than having an offset viewport? You have an extra render stage in there.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Rending to texture and then rendering that texture to a quad has a negligible performance increase over rendering directly to the screen buffer. That's why post-processing is done this way.

I challenge you to try this before stating that it will be too slow.
Linkin Puck
Posts: 36
Joined: Sat Feb 06, 2010 11:52 am

Post by Linkin Puck »

slavik262 wrote:I challenge you to try this before stating that it will be too slow.
Okay, I accept your challenge. :D
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Just run a simple test and share the code/results.
Linkin Puck
Posts: 36
Joined: Sat Feb 06, 2010 11:52 am

Post by Linkin Puck »

slavik262 wrote:Just run a simple test and share the code/results.
Of course, I can't compare it against the offset code, since I can't get that to work. But I'll see if the speed is acceptable.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Do two programs. Make a rotating cube. Stick a camera in front of it. In one program, render straight to screen. In the other program, render to an RTT and use a quad to render to screen.
Linkin Puck
Posts: 36
Joined: Sat Feb 06, 2010 11:52 am

Post by Linkin Puck »

While I do that, can anybody actually answer my original question?
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

As far as I'm aware, there's no way to have an offscreen viewport. Render to texture and then render that texture to a fullscreen quad, using UV coordinates to offset your image. For example, if you wanted the upper left corner to be 10% inside the image, you'd make the UV coordinate (0.1, 0.1).
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Pretty sure it would be easier to just use draw2DImage()...
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Or do that. :oops:

It still involves a RTT though.
Post Reply