Original Post
Hello!
I am currently learning how to use SlimDX along with D3DImage in WPF, and was making a small editor like app with 4 different viewports using multiple swapchains.
I ran into a problem though, which meant weird errors with cutting off parts of my rendered scene ( a fancy triangle ), when I resize the window.
As you can see in the code listing of a minimalistic app I made to focus on the problem, I'm resizing the backbuffer, and even reset the device with the new present parameters, but still can't get it to work properly.
any Ideas?
I also include a screenshot that shows the weirdness.

[Edited by - Daimon on September 17, 2010 5:14:12 AM]
I am currently learning how to use SlimDX along with D3DImage in WPF, and was making a small editor like app with 4 different viewports using multiple swapchains.
I ran into a problem though, which meant weird errors with cutting off parts of my rendered scene ( a fancy triangle ), when I resize the window.
As you can see in the code listing of a minimalistic app I made to focus on the problem, I'm resizing the backbuffer, and even reset the device with the new present parameters, but still can't get it to work properly.
using System;using System.Windows;using SlimDX.Direct3D9;using System.Windows.Interop;using SlimDX;using System.Windows.Media;using System.Runtime.InteropServices;namespace minimalistic{ class CustomVertex { [StructLayout(LayoutKind.Sequential)] public struct TransformedColored { public Vector4 Position; public int Color; public static readonly VertexFormat Format = VertexFormat.Diffuse | VertexFormat.PositionRhw; } [StructLayout(LayoutKind.Sequential)] public struct PositionColored { public PositionColored(float x, float y, float z, int color) { Position = new Vector3(x, y, z); Color = color; } public Vector3 Position; public int Color; public static readonly VertexFormat Format = VertexFormat.Diffuse | VertexFormat.Position; } } public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); InitializeD3D(); this.Loaded += new RoutedEventHandler(Window_Loaded); } Device device; Direct3D Direct3D; SwapChain swapchain; CustomVertex.PositionColored[] vertices; PresentParameters pp; public void InitializeD3D() { HwndSource hwnd = new HwndSource(0, 0, 0, 0, 0, "test", IntPtr.Zero); Direct3D = new SlimDX.Direct3D9.Direct3D(); pp = new PresentParameters(); pp.SwapEffect = SwapEffect.Discard; pp.DeviceWindowHandle = hwnd.Handle; pp.Windowed = true; pp.BackBufferWidth = 400; pp.BackBufferHeight = 400; pp.BackBufferFormat = Format.X8R8G8B8; device = new Device( Direct3D, 0, DeviceType.Hardware, hwnd.Handle, CreateFlags.HardwareVertexProcessing, pp ); swapchain = new SwapChain(device, pp); } private void Window_Loaded(object sender, RoutedEventArgs e) { CompositionTarget.Rendering += new EventHandler(OnRendering); d3dimage.Lock(); d3dimage.SetBackBuffer( D3DResourceType.IDirect3DSurface9, swapchain.GetBackBuffer(0).ComPointer ); d3dimage.Unlock(); vertices = new CustomVertex.PositionColored[3]; vertices[0].Position = new Vector3(-1f, -1f, 0f); vertices[0].Color = System.Drawing.Color.Red.ToArgb(); vertices[1].Position = new Vector3(1f, -1f, 0f); vertices[1].Color = System.Drawing.Color.Green.ToArgb(); vertices[2].Position = new Vector3(0f, 1, 0f); vertices[2].Color = System.Drawing.Color.Yellow.ToArgb(); device.SetRenderState(RenderState.Lighting, false); device.SetRenderState(RenderState.CullMode, Cull.None); device.VertexFormat = CustomVertex.PositionColored.Format; device.SetTransform(TransformState.Projection, SlimDX.Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)output.ActualWidth / (float)output.ActualHeight, 1f, 50f)); device.SetTransform(TransformState.View, SlimDX.Matrix.LookAtLH(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0))); } protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { pp.BackBufferWidth = (int)output.ActualWidth; pp.BackBufferHeight = (int)output.ActualHeight; if (swapchain != null) { swapchain.Dispose(); swapchain = new SwapChain(device, pp); } d3dimage.Lock(); d3dimage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, swapchain.GetBackBuffer(0).ComPointer); d3dimage.Unlock(); device.SetTransform(TransformState.Projection, SlimDX.Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)output.ActualWidth / (float)output.ActualHeight, 1f, 50f)); device.SetTransform(TransformState.View, SlimDX.Matrix.LookAtLH(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0))); device.Viewport = new Viewport(0, 0, (int)output.Width, (int)output.Height); device.SetRenderTarget(0, swapchain.GetBackBuffer(0)); } public void Render() { device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Pink, 1.0f, 0); device.BeginScene(); device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices); device.EndScene(); } private void OnRendering(object sender, EventArgs e) { d3dimage.Lock(); Render(); d3dimage.AddDirtyRect(new Int32Rect(0, 0, (int)d3dimage.Width, (int)d3dimage.Height)); d3dimage.Unlock(); } }}any Ideas?
I also include a screenshot that shows the weirdness.

[Edited by - Daimon on September 17, 2010 5:14:12 AM]