Archived

This topic is now archived and is closed to further replies.

Second Viewport

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been using directx framework hierarcy to implement 3d. I want to create a second viewport which renders my scene from another camera and also is it efficient (i need to keep my FPS maximum). How can i do this, any idea???

Share this post


Link to post
Share on other sites
You can do it with the function: CreateAdditionalSwapChain

With this function you can create another surface to draw too. In youre render function, you swap to another render surface, and render youre triangles.

Before rendering to youre main window, use code like this(delphi) to set the main surface:

var
pBack,pStencil: IDIRECT3DSURFACE8;
begin

D3DDEV8.GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, pBack);
D3DDEV8.GetDepthStencilSurface(pStencil);
D3DDEV8.SetRenderTarget(pBack,pStencil);
pBack := nil;
pStencil := nil;

D3DDEV8.BeginScene;
blabla
D3DDEV8.EndScene;

Then, loop through all the extra surfaces you have created with CreateAdditionalSwapChain:

//I stored the info i got from CreateAdditionalSwapChain in a structure, wich i retrieve in this loop from ExtraViews.

You can find more info in the DX SDK, search for CreateAdditionalSwapChain




for a := 0 to ExtraViews.Count - 1 do
begin
EV := ExtraViews.ItemsLink

3D graphics, its all fake

Share this post


Link to post
Share on other sites
Previous post has been fuck-up, reposting it:

You can do it with the function: CreateAdditionalSwapChain

With this function you can create another surface to draw too. In youre render function, you swap to another render surface, and render youre triangles.

Before rendering to youre main window, use code like this(delphi) to set the main surface:


var
pBack,pStencil: IDIRECT3DSURFACE8;
begin

D3DDEV8.GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, pBack);
D3DDEV8.GetDepthStencilSurface(pStencil);
D3DDEV8.SetRenderTarget(pBack,pStencil);
pBack := nil;
pStencil := nil;

D3DDEV8.BeginScene;
blabla
D3DDEV8.EndScene;


Then, loop through all the extra surfaces you have created with CreateAdditionalSwapChain:


I stored the info i got from CreateAdditionalSwapChain in a structure, wich i retrieve in this loop from ExtraViews.
for a := 0 to ExtraViews.Count - 1 do
begin
EV := ExtraViews.ItemsLink

Share this post


Link to post
Share on other sites
I am really sorry, my posts are being misformed. I''ll try to explain what you have to do:

Make extra swap''s with the function CreateAdditionalSwapChain, store the info in an array(easy when rendering). In youre render function, set the correct backbuffer, look at the function SetRenderTarget in the SDK help. Do youre rendering, and go to the next backbuffer.

Please note that the main backbuffer have to be set seperate. You can set the additional backbuffers in a loop.

hope this helps

Share this post


Link to post
Share on other sites
Alternatively (and much simpler) is just explicitly call SetViewport() for each view.

We do this for split screen and it works fine:

BeginScene()
SetViewport( entire screen )
Clear() // clear all views

SetViewport( split 1 )
Set matrices for split1
Set states for split1
Render polys for split1

SetViewport( split 2 )
Set matrices for split2
Set states for split2
Render polys for split2

SetViewport( split 3 )
Set matrices for split3
Set states for split3
Render polys for split3

...etc...

EndScene()


You should only need an additional swap chain when the other view is in a DIFFERENT WINDOW to the main swap chain.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
thanks for replys. but the second solution seems to be less efficient (but more easy ). what if i had four views (like 3dsmax) do i have to render each mesh sperately for each view ? isn''t that decreases frame rate dangerously...

Share this post


Link to post
Share on other sites
Yes you have to render the mesh several times, once for each viewport. Unless you want the same view in all 4 viewports.

But how else would you get different views (cameras) of the object ?

Share this post


Link to post
Share on other sites
Well, however you approach this in your code, when you have 4 cameras pointing to a scene from 4 different angles, then you HAVE to render all visible triangles 4 times. Take it as a universal law. You want something done 4 times, it is more work than one time.

Sure your framerate might go down - at the same time, though, the rendered area is smaller.

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Share this post


Link to post
Share on other sites