Chris Ara 03-01-2005, 09:09 AM 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 :cool:
ardman 03-02-2005, 01:06 AM 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.
The-Colonel 03-03-2005, 05:58 PM 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.
Chris Ara 03-03-2005, 06:56 PM 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.
ardman 03-07-2005, 01:40 AM 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.
Chris Ara 03-08-2005, 05:39 PM :p I tried that already
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
ardman 03-09-2005, 01:48 AM 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.
Tuplet 03-28-2005, 04:01 PM 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 :)
ardman 03-29-2005, 12:06 AM You could try doing a clear of the device again before the second present call.
Tuplet 03-29-2005, 02:56 AM You could try doing a clear of the device again before the second present call.
Great I'll try that. Thanks
Tuplet 03-29-2005, 04:51 AM 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.
Chris Ara 03-30-2005, 05:46 PM 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 ??
ardman 03-31-2005, 12:00 AM Ok. Here we go. After you've initialised DirectX you need to do the following:
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:
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!
Chris Ara 04-02-2005, 12:11 PM 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 ?
ardman 04-04-2005, 01:19 AM My apologies for missing that bit out. All you need to do is to change the World matrix before you render e.g.
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()
Chris Ara 04-06-2005, 06:49 PM :D 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 ?
:D :D :D hooray once again the mystery is solved
ardman 04-07-2005, 01:20 AM :D 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 ?
:D :D :D 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. :)
|