Sub viewports?

Started by
6 comments, last by silvermace 18 years, 7 months ago
How do you go about doing sub viewports, i.e. the ones used in X2 the Threat? Whereby you present another view of the scene on an embedded part of the screen (or billboard quad, I'm not sure). Either DirectX and/or OpenGL answers are welcome.
Advertisement
In OpenGL the solution is pretty simple, you just define the viewport that you want to render to with glVieport(blah, blah, blah) and then define an orthographic projection glOrtho(etc, etc, etc) then just perform your rendering. You probably want to do this at the very end of frame writing.

The cool thing is you can still use alpha blending etc, if you want to partially (or fully) show what is going on underneath with your game.

There is probably a similar solution for DirectX but I am not 100% sure.
I don't know much about D3D but I imagine it supports scissor test which would let you do this, even if with a lot more difficulty than GL because you'd have to adjust your projection matrix depending on where on screen your viewport was.

moagstar: I would've thought you could only use alpha blending if you had zero overdraw otherwise you'd end up being able to see through things in the viewport. Unless of course you rendered to an offscreen texture and drew that, which is also a perfectly good solution.
Quote:Original post by ZQJ
moagstar: I would've thought you could only use alpha blending if you had zero overdraw otherwise you'd end up being able to see through things in the viewport. Unless of course you rendered to an offscreen texture and drew that, which is also a perfectly good solution.


I'm not 100% sure I know what you mean by this, but if I understand (correct me if i'm wrong) then the whole point of using alpha on the viewport would be so that you could see through it?

Yeah - well that's why I mentioned the other way. If you render to a texture then alpha blend that texture onto the screen it'll be like a transparent photo. If on the other hand you render a scene to a little part of the screen with all polygons having an alpha factor of say 0.5, then where you have two overlapping you'll be able to see both of them and the background will only have 0.25 intensity.
How do you go about rendering to a texture?
Render-to-texture is API specific. The OpenGL method is EXT_framebuffer_object. You might need pretty new drivers to get that extension because the spec is quite recent.
one of my better previous posts has code for an easy (and slower/older) method. You might want to change the variable apiTarget from GL_TEXTURE_RECTANGLE_ARB to GL_TEXTURE_2D.

Cheers
-Danu
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website

This topic is closed to new replies.

Advertisement