Page 1 of 1

Offscreen viewport

Posted: Wed Jun 23, 2010 10:54 am
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!

Posted: Wed Jun 23, 2010 11:16 am
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.

Posted: Wed Jun 23, 2010 12:00 pm
by Linkin Puck
Thanks Sudi, I already thought of that but it will be too slow.

Any ideas how to get the offscreen viewport?

Posted: Wed Jun 23, 2010 12:50 pm
by sudi
and why will this be to slow?

Posted: Wed Jun 23, 2010 5:43 pm
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.

Posted: Wed Jun 23, 2010 8:19 pm
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.

Posted: Wed Jun 23, 2010 8:40 pm
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

Posted: Wed Jun 23, 2010 8:44 pm
by slavik262
Just run a simple test and share the code/results.

Posted: Wed Jun 23, 2010 10:01 pm
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.

Posted: Thu Jun 24, 2010 12:27 am
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.

Posted: Thu Jun 24, 2010 8:12 am
by Linkin Puck
While I do that, can anybody actually answer my original question?

Posted: Thu Jun 24, 2010 11:56 am
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).

Posted: Thu Jun 24, 2010 1:07 pm
by BlindSide
Pretty sure it would be easier to just use draw2DImage()...

Posted: Thu Jun 24, 2010 1:32 pm
by slavik262
Or do that. :oops:

It still involves a RTT though.