Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows
Rendering to multiple windows Rendering to multiple windows
Rendering to multiple windows
Go Back  Xtreme Visual Basic Talk > > > > Rendering to multiple windows


Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2005, 10:09 AM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Question Rendering to multiple windows


Here's a tough one I've been trying to work on , Rendering to more than one window and each giving each window its own static view(camera)
the easiest way to do this is to make multiple calls to the device.present method and give each call a different window handle

public sub Render(byval WinHandle2 as intptr,byval WinHandle3 as intptr)

device.clear

device.beginscene

'geometry and scene stuff here

device.endscene

device. present

device.present(WinHandle2)

device.present(WinHandle3)

end sub

now this renders the same device.transform.view to all windows. The problem with this is when you translate / rotate the devices view the view is moved in all windows.I want to have a seperate view for each window , so I can Translate the view in one window and not effect the others.Hopefully some one can help me out with this please post if you know the answer
Reply With Quote
  #2  
Old 03-02-2005, 02:06 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

I have been looking at something similar too. I have found that SwapChains are what are needed but I've failed to find a good example to use.
__________________
Cheers
Reply With Quote
  #3  
Old 03-03-2005, 06:58 PM
The-Colonel The-Colonel is offline
Newcomer
 
Join Date: Feb 2005
Posts: 7
Default

Could you just create two non-exclusive devices, one for each window, and render your view for the second window to a texture (using the RenderToSurface object in D3DX).

Then all you need to do is draw that texture to the second window.
Reply With Quote
  #4  
Old 03-03-2005, 07:56 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Cool Multiple Device lag

I see where you are headed with the multiple device suggestion , but there is one huge flaw in this. "it takes way to much processing" using multiple devices can seriously slow down your app especially with visual basic. which supposedly has a slower speed than other languages c++, J# etc.also using multiple devices which I have tried makes rendering scenes vey hard. which I actually can't even get it to render with two devices I keep getting buffer overflow or something of that nature.

using the the swap chain has the same effect as using device.present call multiple times and the view are shared by one device so translating a view in one window effects the other.I am assuming with the high tech stuff in the new directx surely they didn't leave out a way to make multiple cameras.

by the way does any one know when the release of visual basic .net 2005 is.Not the express edition the standard edition??

Here are some other failed attempts at this I tried , take a look so you don't waste your time falling into the same errors I have

device.present(Window1)

device.transform.view = matrix.multiply(device.transform.view,matrix.translation(view2matrix))

device.present(window2)

'' what I tried here is to present the scene to the first window then apply a matrix to the view then present it again to the second window.When you do this the scene will render one time then show up as a blank screen. not sure why but it does. if I could get this one to work I could use different matrix's to present different views of the same world maybe some one can get that trixk to work.
Reply With Quote
  #5  
Old 03-07-2005, 02:40 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Once again I suggest that you look for SwapChains. I've only got a C++ example but it is the easiest way of doing this.
__________________
Cheers
Reply With Quote
  #6  
Old 03-08-2005, 06:39 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default I tried that

I tried that already

Code:
 Public Swap As SwapChain

    Public Sub InitializeDirect3d(ByVal WindowHandle As IntPtr)

        Dim PP As New PresentParameters
        Dim Display As DisplayMode
        'set display to default 
        Display = Manager.Adapters(Manager.Adapters.Default.Adapter).CurrentDisplayMode
        'set display parameters
        With PP
            .Windowed = True
            .SwapEffect = SwapEffect.Copy
            .EnableAutoDepthStencil = True
            .AutoDepthStencilFormat = DepthFormat.D24X8
            .BackBufferFormat = Display.Format
        End With

        Try
            Dim Dx As DirectXException
            Device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, WindowHandle, CreateFlags.SoftwareVertexProcessing, PP)

            Swap = New SwapChain(Device, PP)
            'turn on lighting and culling
            Device.RenderState.Lighting = True
            Device.RenderState.ZBufferEnable = True
            Device.RenderState.CullMode = Cull.None
            'set the camera up
            Device.Transform.World = Matrix.Identity
            Device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, 1.0F, 1, -1000)
            Device.Transform.View = Matrix.LookAtLH(New Vector3(0, 500, -2000), New Vector3(0, 0, 0), New Vector3(0.0F, 1.0F, 0.0F))
        Catch dx As DirectXException
            MessageBox.Show("Error Initializing Direct3d " & dx.ToString)
        End Try
        'release resources
        PP = Nothing
        Display = Nothing
    End Sub

    Public Sub Render(ByVal Window2 As IntPtr)

        Device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Black, 1.0F, 0)

        Device.BeginScene()

        '  Device.RenderState.Lighting = True

        SetupLights()

        Device.Transform.World = LightMatrix

        MeshArray(0).DrawSubset(0)

        Device.Transform.World = MeshMatrix

        MeshArray(1).DrawSubset(0)

        Device.SetTexture(0, Textures(0))
        Device.SetStreamSource(0, VertBuffer, 0)
        Device.VertexFormat = CustomVertex.PositionNormalTextured.Format
        Device.DrawPrimitives(PrimitiveType.PointList, 0, NumberOfParticles)

        Device.SetTexture(0, Textures(0))
        Device.SetStreamSource(0, GlassBuffer, 0)
        Device.VertexFormat = CustomVertex.PositionNormalTextured.Format
        Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)

        Dim n As Integer
        For n = 0 To MeshMaterials.Length - 1
            ' Set the material and texture for this subset
            Device.Material = MeshMaterials(n)
            Device.SetTexture(0, MeshTextures(n))
            ' Draw the mesh subset
            AraMesh.DrawSubset(n)
        Next n

        Device.EndScene()

        Device.Present()

        Swap.Device.Present(Window2)

    End Sub
see here I make new device set up the swap giving it the devices setting and present parameters then in the render function I use the swap.device.present function and device.present functio to present the scene which presents two pictures to seperate windows but if apply a matrix to either the device or the swap.device both of them are affected = in each screen maybe you see something I am doing wrong help me out here
Reply With Quote
  #7  
Old 03-09-2005, 02:48 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

To me it looks as though you are displaying the same image to both screens. You've applied the matrix and presenting the same to both windows. Try changing the view on the second window before you present it.
__________________
Cheers
Reply With Quote
  #8  
Old 03-28-2005, 05:01 PM
Tuplet Tuplet is offline
Newcomer
 
Join Date: Mar 2005
Posts: 3
Default I am having trouble with SwapChain example

Hi I am having trouble with the supplied SwapChain example. I have two UserControls. One for the device's Present() and one for the swap chain. The rendering works for the first UserControl which the device is Presented to but the second UserControl's display is all screwy and scrambled. Is there something special I have to do?

Thanks
Reply With Quote
  #9  
Old 03-29-2005, 01:06 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

You could try doing a clear of the device again before the second present call.
__________________
Cheers
Reply With Quote
  #10  
Old 03-29-2005, 03:56 AM
Tuplet Tuplet is offline
Newcomer
 
Join Date: Mar 2005
Posts: 3
Default

Quote:
Originally Posted by ardman
You could try doing a clear of the device again before the second present call.
Great I'll try that. Thanks
Reply With Quote
  #11  
Old 03-29-2005, 05:51 AM
Tuplet Tuplet is offline
Newcomer
 
Join Date: Mar 2005
Posts: 3
Default

I got it working I forgot a line of code in the sample. I wasn't using mySwapChain.Device.Present(someWindow) but trying to use mySwapChain.Present(someWindow). I dont know why that doesnt work but it doesnt.
Reply With Quote
  #12  
Old 03-30-2005, 06:46 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default urghhh

O.k maybe there is something wrong with the way I am initilializing my main device and swap chain device perhaps the solution here is to find some one who knows how do this and have them post the entire process from initialization to rendering

any volunteers ??
Reply With Quote
  #13  
Old 03-31-2005, 01:00 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

Ok. Here we go. After you've initialised DirectX you need to do the following:
Code:
        settaggio = New PresentParameters
        settaggio.BackBufferCount = 1
        settaggio.AutoDepthStencilFormat = DepthFormat.D16
        settaggio.EnableAutoDepthStencil = True
        settaggio.DeviceWindowHandle = PictureBox1.Handle
        settaggio.SwapEffect = SwapEffect.Discard
        settaggio.Windowed = True
        sw1 = New Direct3D.SwapChain(device, settaggio)

        settaggio = New PresentParameters
        settaggio.BackBufferCount = 1
        settaggio.AutoDepthStencilFormat = DepthFormat.D16 
        settaggio.EnableAutoDepthStencil = True
        settaggio.DeviceWindowHandle = PictureBox2.Handle
        settaggio.SwapEffect = SwapEffect.Discard
        settaggio.Windowed = True
        sw2 = New Direct3D.SwapChain(device, settaggio)

        settaggio = New PresentParameters
        settaggio.BackBufferCount = 1
        settaggio.AutoDepthStencilFormat = DepthFormat.D16
        settaggio.EnableAutoDepthStencil = True
        settaggio.DeviceWindowHandle = PictureBox3.Handle
        settaggio.SwapEffect = SwapEffect.Discard
        settaggio.Windowed = True
        sw3 = New Direct3D.SwapChain(device, settaggio)

        s1 = sw1.GetBackBuffer(0, BackBufferType.Mono)
        s2 = sw2.GetBackBuffer(0, BackBufferType.Mono)
        s3 = sw3.GetBackBuffer(0, BackBufferType.Mono)

        backB = device.GetBackBuffer(0, 0, BackBufferType.Mono)
This will create 3 swap chains. When you are doing your rendering:

Code:
            device.SetRenderTarget(0, backB)
            device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Yellow, 1, 0)
            device.BeginScene()
            ' Rendering stuff here...
            device.EndScene()
            device.Present()

            device.SetRenderTarget(0, s1)
            device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
            device.BeginScene()
            ' Rendering stuff here
            device.EndScene()
            sw1.Present()

etc...
Done!
__________________
Cheers
Reply With Quote
  #14  
Old 04-02-2005, 01:11 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default None

O.k thanks now I can use multiple chains to render the same scene , but I think you missed my original question which is how can I get two different views of the same scene with independent views?

say If I translate the view1 I don't wont it to affect view 2

public sub TranslateView1()

swap1.device.transform.view = matrix.multiply(swap1.device.transform.view,matrix.translation(new vector3(0,0,10))

end sub

public sub TranslateView2()

swap2.device.transform.view = matrix.multiply(swap2.device.transform.view,matrix.translation(new vector3(0,0,10))

end sub

if you do this then no matter which swap view is translated it affects every view port and translates them all

so what I want to do is move the camera in one view and have it not affect the camera in the other view ???? I know this requires a swapchain but I am not sure how to work the views now Perhaps some one can clear this up for me ?
Reply With Quote
  #15  
Old 04-04-2005, 02:19 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Default

My apologies for missing that bit out. All you need to do is to change the World matrix before you render e.g.

Code:
Dim matView as Matrix

    device.SetRenderTarget(0, s1)
    device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Blue, 1, 0)
    device.BeginScene()
    matView = device.Matrix.LookAtLH(new vector3(x,y,z),new vector3(x,y,z),new vector3(x,y,z))
    device.SetTransform(Direct3D.TransformType.View, matView)
    device.EndScene()
    sw1.Present()
__________________
Cheers
Reply With Quote
  #16  
Old 04-06-2005, 07:49 PM
Chris Ara Chris Ara is offline
Centurion
 
Join Date: Feb 2005
Posts: 176
Default Thanks

Super Sweet
There is so much more to rendering to multiple views than the crappy documentation that comes with directx shows .
You seem like a very knowledgable guy on directx and visual basic can you suggest any good books may be that you think could help ?
hooray once again the mystery is solved
Reply With Quote
  #17  
Old 04-07-2005, 02:20 AM
ardman ardman is offline
Contributor
 
Join Date: Jan 2002
Posts: 126
Talking

Quote:
Originally Posted by Chris Ara
Super Sweet
There is so much more to rendering to multiple views than the crappy documentation that comes with directx shows .
You seem like a very knowledgable guy on directx and visual basic can you suggest any good books may be that you think could help ?
hooray once again the mystery is solved
One recommendation I do have and thats 3D Game Engine programming. It is written in C++ but it's not too tricky to convert into VB. Anything else that you think I can help with then drop us an email at neil_knight@hotmail.com.

Watch out for my new DLL coming soon.
__________________
Cheers
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows Rendering to multiple windows
Rendering to multiple windows
Rendering to multiple windows
 
Rendering to multiple windows
Rendering to multiple windows
 
-->