Jump to content
  • Advertisement

AlanMcCormick

Member
  • Content Count

    19
  • Joined

  • Last visited

Community Reputation

100 Neutral

About AlanMcCormick

  • Rank
    Member
  1. AlanMcCormick

    [SlimDX] clipping Z axis

    Turns out I needed to clear the ZBuffer in SlimDX but not SharpDX... d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(255, 0.2f, 0.2f, 0.2f), 1.0f, 0);
  2. I have a basic example where I draw 9 points, and attempt to rotate them on the Y axis. Using SlimDX my points disappear completely. Using SharpDX it behaves like I would expect. Is there a way around this? If you have both installed, all you have to do is comment out the #define SLIMDX line to use SharpDX. They are both implemented for comparison I attached the project as a zip file, but here's the code // comment this out and try SharpDX instead // SharpDX works #define SLIMDX using System; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; #if SLIMDX using SlimDX; using SlimDX.Direct3D9; #else using SharpDX; using SharpDX.Direct3D9; #endif namespace SlimDXTests { public partial class TestDialog : Form { // D3D Direct3D d3d; Device d3dDevice; VertexBuffer vertexBuffer; // for SharpDX since the aren't defined const int D3DWORLD = 256; const int D3DVIEW = 2; const int D3DPROJECTION = 3; struct CustomVertex { public float x, y, z; public float pointSize; public uint color; } public TestDialog() { InitializeComponent(); InitD3D9(); InitGeometry(); } private void InitD3D9() { d3d = new Direct3D(); d3dDevice = new Device( d3d, 0, DeviceType.Hardware, panel1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters() { Windowed = true, SwapEffect = SwapEffect.Discard, BackBufferFormat = Format.Unknown, PresentationInterval = PresentInterval.Immediate, BackBufferWidth = panel1.Width, BackBufferHeight = panel1.Height, //FullScreenRefreshRateInHertz = 0, //Multisample = MultisampleType.NonMaskable, //MultisampleQuality = 1 // todo query max and set to max-1 }); d3dDevice.SetRenderState(RenderState.Lighting, 0); // Turn off D3D Lighting d3dDevice.Viewport = new Viewport() { X = 0, Y = 0, Width = panel1.Width, Height = panel1.Height, MinZ = 0, MaxZ = 1 }; SetupTransform(0); } private void SetupTransform(long millis) { Matrix world; Matrix view; Matrix projection; //----------------------------- Matrix rotationY = Matrix.RotationY((float)(millis * 2 * Math.PI / 1000f)); Matrix scale = Matrix.Scaling(0.8f, 0.8f, 0.8f); world = scale * rotationY; Vector3 eyeVector = new Vector3(0.0f, 2.0f, -3.0f); Vector3 lookVector = new Vector3(0.0f, 0.0f, 0.0f); Vector3 upVector = new Vector3(0.0f, 1.0f, 0.0f); Matrix.LookAtLH(ref eyeVector, ref lookVector, ref upVector, out view); Matrix.PerspectiveFovLH((float)(Math.PI / 4), (float)panel1.Width / (float)panel1.Height, 1f, 100f, out projection); #if SLIMDX d3dDevice.SetTransform(TransformState.World, world); d3dDevice.SetTransform((TransformState)TransformState.View, view); d3dDevice.SetTransform((TransformState)TransformState.Projection, projection); #else d3dDevice.SetTransform((TransformState)D3DWORLD, ref world); d3dDevice.SetTransform((TransformState)D3DVIEW, ref view); d3dDevice.SetTransform((TransformState)D3DPROJECTION, ref projection); #endif } private void InitGeometry() { CustomVertex[] vertices = new CustomVertex[] { new CustomVertex(){x = 0.0f, y = 0.0f, z = 0.0f, pointSize = 5f, color = 0xff0094FF}, new CustomVertex(){x = -1.0f, y = 0.0f, z = 0.0f, pointSize = 5f, color = 0xffFF6A00}, new CustomVertex(){x = 1.0f, y = 0.0f, z = 0.0f, pointSize = 5f, color = 0xff007F0E}, new CustomVertex(){x = 0.0f, y = -1.0f, z = 0.0f, pointSize = 5f, color = 0xffD477FF}, new CustomVertex(){x = 0.0f, y = 1.0f, z = 0.0f, pointSize = 5f, color = 0xffFF00DC}, new CustomVertex(){x = -1.0f, y = 1.0f, z = 0.0f, pointSize = 5f, color = 0xffFFE15E}, new CustomVertex(){x = 1.0f, y = 1.0f, z = 0.0f, pointSize = 5f, color = 0xffFFFFFF}, new CustomVertex(){x = -1.0f, y = -1.0f, z = 0.0f, pointSize = 5f, color = 0xff7D00B7}, new CustomVertex(){x = 1.0f, y = -1.0f, z = 0.0f, pointSize = 5f, color = 0xffFFB27F} }; // create vertex buffer vertexBuffer = new VertexBuffer( d3dDevice, 3 * Marshal.SizeOf(typeof(CustomVertex)), Usage.None, VertexFormat.Diffuse | VertexFormat.Position | VertexFormat.PointSize, Pool.Default); DataStream stream = vertexBuffer.Lock(0, Marshal.SizeOf(typeof(CustomVertex)) * vertices.Length, LockFlags.None); for (int i = 0; i < vertices.Length; i++) stream.Write(vertices); vertexBuffer.Unlock(); } protected override void OnClosed(EventArgs e) { d3d.Dispose(); d3dDevice.Dispose(); vertexBuffer.Dispose(); base.OnClosed(e); } private void btnDX9_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); int frames = 0; sw.Start(); while (sw.ElapsedMilliseconds < 3000) { d3dDevice.Clear(ClearFlags.Target, new Color4(255, 0.2f, 0.2f, 0.2f), 1.0f, 0); SetupTransform(sw.ElapsedMilliseconds); d3dDevice.BeginScene(); d3dDevice.SetStreamSource(0, vertexBuffer, 0, Marshal.SizeOf(typeof(CustomVertex))); d3dDevice.VertexFormat = VertexFormat.Diffuse | VertexFormat.Position | VertexFormat.PointSize; d3dDevice.DrawPrimitives(PrimitiveType.PointList, 0, 9); d3dDevice.EndScene(); d3dDevice.Present(); frames++; } sw.Stop(); } } }
  3. AlanMcCormick

    [SlimDX] Can't view Z-dimension

    Ok this is as simple as I can make it.. I have 5 points being drawn.... rotating them on Y and Z axis. All I can see are 3 points being rotated around the Z-axis. (spinng counter clockwise) using System; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace GraphDrawingTests { public partial class GraphDrawingDialog : Form { // D3D SlimDX.Direct3D9.Direct3D d3d; SlimDX.Direct3D9.Device d3dDevice; SlimDX.Direct3D9.VertexBuffer vertexBuffer; struct CustomVertex { public float x, y, z; public float pointSize; public uint color; } public GraphDrawingDialog() { InitializeComponent(); InitD3D9(); InitGeometry(); } private void InitD3D9() { d3d = new SlimDX.Direct3D9.Direct3D(); d3dDevice = new SlimDX.Direct3D9.Device( d3d, 0, SlimDX.Direct3D9.DeviceType.Hardware, panel1.Handle, SlimDX.Direct3D9.CreateFlags.HardwareVertexProcessing, new SlimDX.Direct3D9.PresentParameters() { Windowed = true, SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard, BackBufferFormat = SlimDX.Direct3D9.Format.Unknown, FullScreenRefreshRateInHertz = 0, PresentationInterval = SlimDX.Direct3D9.PresentInterval.Immediate, Multisample = SlimDX.Direct3D9.MultisampleType.NonMaskable, MultisampleQuality = 1, // todo query max and set to max-1 BackBufferWidth = panel1.Width, BackBufferHeight = panel1.Height }); d3dDevice.SetRenderState(SlimDX.Direct3D9.RenderState.CullMode, 1); // Show front/back triangles d3dDevice.SetRenderState(SlimDX.Direct3D9.RenderState.Lighting, false); // Turn off D3D Lighting d3dDevice.Viewport = new SlimDX.Direct3D9.Viewport(0, 0, panel1.Width, panel1.Height, 0, 1); SetupTransform(0); } private void SetupTransform(long millis) { SlimDX.Matrix rotationZ, rotationY, rotation, scale, final; //----------------------------- rotationZ = SlimDX.Matrix.Identity; SlimDX.Matrix.RotationY((float)(millis * 2 * Math.PI / 1000f), out rotationY); SlimDX.Matrix.RotationZ((float)(millis * Math.PI / 1000f), out rotationZ); SlimDX.Matrix.Multiply(ref rotationY, ref rotationZ, out rotation); SlimDX.Matrix.Scaling(0.8f, -0.8f, 0.8f, out scale); SlimDX.Matrix.Multiply(ref scale, ref rotation, out final); d3dDevice.SetTransform(SlimDX.Direct3D9.TransformState.World, final); SlimDX.Vector3 eyePt = new SlimDX.Vector3(0.0f, 1.0f, -2.615f); SlimDX.Vector3 vLookatPt = new SlimDX.Vector3(0.0f, 0.0f, 0.0f); SlimDX.Vector3 vUpVec = new SlimDX.Vector3(0.0f, 1.0f, 0.0f); SlimDX.Matrix matView; SlimDX.Matrix.LookAtLH(ref eyePt, ref vLookatPt, ref vUpVec, out matView); //d3dDevice.SetTransform(SlimDX.Direct3D9.TransformState.View, matView); SlimDX.Matrix matProj; SlimDX.Matrix.PerspectiveFovLH((float)(Math.PI / 4), (float)panel1.Width / (float)panel1.Height, 1f, 100f, out matProj); //d3dDevice.SetTransform(SlimDX.Direct3D9.TransformState.Projection, matProj); } private void InitGeometry() { CustomVertex[] vertices = new CustomVertex[] { new CustomVertex(){x = 0.0f, y = 0.0f, z = 0.0f, pointSize = 5f, color = 0xff0094FF}, new CustomVertex(){x = -1.0f, y = 0.0f, z = 0.0f, pointSize = 5f, color = 0xffFF6A00}, new CustomVertex(){x = 1.0f, y = 0.0f, z = 0.0f, pointSize = 5f, color = 0xff007F0E}, new CustomVertex(){x = 0.0f, y = -1.0f, z = 0.0f, pointSize = 5f, color = 0xffD477FF}, new CustomVertex(){x = 0.0f, y = 1.0f, z = 0.0f, pointSize = 5f, color = 0xffFF006E}, }; // create vertex buffer vertexBuffer = new SlimDX.Direct3D9.VertexBuffer( d3dDevice, 3 * Marshal.SizeOf(typeof(CustomVertex)), SlimDX.Direct3D9.Usage.None, SlimDX.Direct3D9.VertexFormat.Diffuse | SlimDX.Direct3D9.VertexFormat.Position | SlimDX.Direct3D9.VertexFormat.PointSize, SlimDX.Direct3D9.Pool.Default); SlimDX.DataStream stream = vertexBuffer.Lock(0, Marshal.SizeOf(typeof(CustomVertex)) * vertices.Length, SlimDX.Direct3D9.LockFlags.None); for (int i = 0; i < vertices.Length; i++) { stream.Write(vertices.x); stream.Write(vertices.y); stream.Write(vertices.z); stream.Write(vertices.pointSize); stream.Write(vertices.color); } vertexBuffer.Unlock(); } protected override void OnClosed(EventArgs e) { d3d.Dispose(); d3dDevice.Dispose(); vertexBuffer.Dispose(); base.OnClosed(e); } private void btnDX9_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); int frames = 0; sw.Start(); while (sw.ElapsedMilliseconds < 4000) { d3dDevice.Clear(SlimDX.Direct3D9.ClearFlags.Target, new SlimDX.Color4(255, 0.2f, 0.2f, 0.2f), 1.0f, 0); SetupTransform(sw.ElapsedMilliseconds); d3dDevice.BeginScene(); d3dDevice.SetStreamSource(0, vertexBuffer, 0, Marshal.SizeOf(typeof(CustomVertex))); d3dDevice.VertexFormat = SlimDX.Direct3D9.VertexFormat.Diffuse | SlimDX.Direct3D9.VertexFormat.Position | SlimDX.Direct3D9.VertexFormat.PointSize; d3dDevice.DrawPrimitives(SlimDX.Direct3D9.PrimitiveType.PointList, 0, 5); d3dDevice.EndScene(); d3dDevice.Present(); frames++; } sw.Stop(); //MessageBox.Show("D3D9 Frames: " + frames); } } }
  4. edit: I copied this code and replaced it with SharpDX and it works, however I'm not sure SharpDX implements DX9 completely.. it seems to be missing a lot (no transforms?) but vertices with z-values display I've been experimenting with DirectX9 using SlimDX. I've been able to render graphs and 2d lines, points, triangles... However, whenever I add a z-value for my vertices or try a rotation around the Y-axis, or attempt to set up the View and Projection transforms, my graphics disappear completely. I'm copying example code verbatim from c++ using directx9, and I see no differences. Any time that I attempt to view anything not straight on, with z = 0.0, I see nothing.... What's wrong? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using SlimDX; using SlimDX.Direct2D; using SlimDX.Direct3D10; using SlimDX.DirectWrite; using SlimDX.DXGI; using System.Runtime.InteropServices; namespace GraphDrawingTests { public partial class GraphDrawingDialog : Form { // D3D SlimDX.Direct3D9.Device d3dDevice; public GraphDrawingDialog() { InitializeComponent(); InitD3D9(); InitGeometry(); } private void button4_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); int frames = 0; sw.Start(); // while(sw.ElapsedMilliseconds < 1000) //{ d3dDevice.Clear(SlimDX.Direct3D9.ClearFlags.Target, new SlimDX.Color4(0, 0, 0, 0), 1.0f, 0); d3dDevice.BeginScene(); d3dDevice.SetStreamSource(0, vertexBuffer, 0, Marshal.SizeOf(typeof(CustomVertex))); d3dDevice.VertexFormat = SlimDX.Direct3D9.VertexFormat.Diffuse | SlimDX.Direct3D9.VertexFormat.Position; d3dDevice.DrawPrimitives(SlimDX.Direct3D9.PrimitiveType.TriangleStrip, 0, 1); d3dDevice.EndScene(); d3dDevice.Present(); frames++; // } sw.Stop(); //MessageBox.Show("D3D9 Frames: " + frames); } private void InitD3D9() { d3dDevice = new SlimDX.Direct3D9.Device( new SlimDX.Direct3D9.Direct3D(), 0, SlimDX.Direct3D9.DeviceType.Hardware, panel1.Handle, SlimDX.Direct3D9.CreateFlags.HardwareVertexProcessing, new SlimDX.Direct3D9.PresentParameters() { Windowed = true, SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard, BackBufferFormat = SlimDX.Direct3D9.Format.Unknown, // FullScreenRefreshRateInHertz = 0, // PresentationInterval = SlimDX.Direct3D9.PresentInterval.Immediate, // Multisample = SlimDX.Direct3D9.MultisampleType.NonMaskable, // MultisampleQuality = 1, // todo query max and set to max-1 // BackBufferWidth = panel1.Width, // BackBufferHeight = panel1.Height }); d3dDevice.SetRenderState(SlimDX.Direct3D9.RenderState.CullMode, 1); // Show front/back triangles d3dDevice.SetRenderState(SlimDX.Direct3D9.RenderState.Lighting, false); // Turn off D3D Lighting SetupTransform(); } private void SetupTransform() { SlimDX.Matrix rotation; // If any of these transforms are used, nothing is displayed, transforms that do not affect z-axis display fine, projections and view never display anything uint iTime = 100; float fAngle = (float)(iTime * (2.0f * Math.PI) / 1000.0f); SlimDX.Matrix.RotationY(fAngle, out rotation); //d3dDevice.SetTransform(SlimDX.Direct3D9.TransformState.World, rotation); SlimDX.Vector3 eyePt = new SlimDX.Vector3(0.0f, -1.0f, -2.615f); SlimDX.Vector3 vLookatPt = new SlimDX.Vector3(0.0f, -1.0f, 0.0f); SlimDX.Vector3 vUpVec = new SlimDX.Vector3(0.0f, 1.0f, 0.0f); SlimDX.Matrix matView; SlimDX.Matrix.LookAtLH(ref eyePt, ref vLookatPt, ref vUpVec, out matView); //d3dDevice.SetTransform(SlimDX.Direct3D9.TransformState.View, matView); SlimDX.Matrix matProj; SlimDX.Matrix.PerspectiveFovLH((float)(Math.PI / 4), (float)panel1.Width / (float)panel1.Height, 1f, 100f, out matProj); //d3dDevice.SetTransform(SlimDX.Direct3D9.TransformState.Projection, matProj); } struct CustomVertex { public float x, y, z; public uint color; } // const int NUM_VERTICES = 3; SlimDX.Direct3D9.VertexBuffer vertexBuffer; private void InitGeometry() { // if any of these have a non-zero z-value, nothing is shown CustomVertex[] vertices = new CustomVertex[] { new CustomVertex(){x = -1.0f, y = -1.0f, z = 0.0f, color = 0xffff0000}, new CustomVertex(){x = 1.0f, y = -1.0f, z = 0.0f, color = 0xff0000ff}, new CustomVertex(){x = 0.0f, y = 1.0f, z = 0.0f, color = 0xffffffff} }; // create vertex buffer vertexBuffer = new SlimDX.Direct3D9.VertexBuffer( d3dDevice, 3 * Marshal.SizeOf(typeof(CustomVertex)), SlimDX.Direct3D9.Usage.None, SlimDX.Direct3D9.VertexFormat.Diffuse | SlimDX.Direct3D9.VertexFormat.Position, SlimDX.Direct3D9.Pool.Default); SlimDX.DataStream stream = vertexBuffer.Lock(0, Marshal.SizeOf(typeof(CustomVertex)) * vertices.Length, SlimDX.Direct3D9.LockFlags.None); for (int i = 0; i < vertices.Length; i++) { // the triangle displays properly with all zero z-values.. I've done stream.Write(vertices) as well stream.Write(vertices.x); stream.Write(vertices.y); stream.Write(vertices.z); stream.Write(vertices.color); } vertexBuffer.Unlock(); } } }
  5. AlanMcCormick

    Fastest way to draw connected lines?

    Actually nevermind D2D's anti-aliasing is rather poor. Look these lines look wavy http://imageshack.us...es/694/d2d.png/ So I get 1% the performance, and in result I get lines that look bad... wow
  6. AlanMcCormick

    Fastest way to draw connected lines?

    Great information... I will look into this, thanks. All this being said.. I may just implement it in D3D9 because we probably want to support XP. As far as i know D2D isn't supported in XP. Before I wasn't against using D2D but now that D3D9 is better at it, I'm not sure that D2D is even needed. As long as I can put the D3D into my application... However, I still want to experiment with this idea. I will say the AA did look good with D2D... I really appreciate the time you guys have taken to help me investigate this issue.
  7. AlanMcCormick

    Fastest way to draw connected lines?

    My co-worker was writing some code to use direct3d9 to render lines. he is getting several thousand frames per second anti-aliased using d3d to render lines.. It is unfortunate that D2D is so bad at it.
  8. AlanMcCormick

    Fastest way to draw connected lines?

    I have 3 monitors and 2 graphics cards. The GTX 560 runs 2 of the screens, while some old piece of junk runs the one screen to the side. My code runs about 1400 fps on each monitor with antialiasing off (I figured out how to disable it). This would seem to indicate it is not hardware accelerated since my modern graphics card supported screen does no better than the other screen. Also, I would expect anti-aliasing to hurt the gfx card much less edit: well hmm.. if I call present (1, ..) and vsync, it does 60 fps and uses almost 0% of the CPU...
  9. AlanMcCormick

    Fastest way to draw connected lines?

    How to disable smoothing (antialiasing)? Also.. were you just looping and calling DrawLine before? Edit: Actually.. how do I know even then it isn't running on the CPU and not the GPU
  10. AlanMcCormick

    Fastest way to draw connected lines?

    Erik can I see your C code?
  11. AlanMcCormick

    Fastest way to draw connected lines?

    I had read somewhere that creating the brushes is very minimal.. but wasn't sure about the path geometry. I modified it and still get 24 or 25 FPS. private void button1_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); SharpDX.Direct2D1.PathGeometry geometry = new SharpDX.Direct2D1.PathGeometry(d2dFactory_SharpDX); SharpDX.Direct2D1.GeometrySink sink = geometry.Open(); sink.BeginFigure(new PointF(0, 0), new SharpDX.Direct2D1.FigureBegin()); sink.AddLines(pts[0]); sink.EndFigure(new SharpDX.Direct2D1.FigureEnd()); sink.Close(); SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush( renderTarget_SharpDX, new SharpDX.Color4(255, 255, 255, 255)); int frames = 0; while (sw.ElapsedMilliseconds < 1000) { renderTarget_SharpDX.BeginDraw(); renderTarget_SharpDX.Clear(new SharpDX.Color4(255, 0, 0, 0)); renderTarget_SharpDX.DrawGeometry(geometry, brush); renderTarget_SharpDX.EndDraw(); frames++; swapChain_SharpDX.Present(0, SharpDX.DXGI.PresentFlags.None); } brush.Dispose(); geometry.Dispose(); MessageBox.Show("D2D Frames: " + frames); }
  12. AlanMcCormick

    Fastest way to draw connected lines?

    Thanks Erik. Here's my code. I got it to work and display... I get 46 frames in 2 seconds (23 FPS on a GTX 560 with an i7) My panel is 818x400 and therefore I'm drawing 818 lines one per each X-value with a random y-value between 0-400. I still am not getting a frame rate that I would consider good. I watched my CPU usage on the process and it was using 13% (on a 4 core (8 with hyperthreading) processor) 100 / 8 = 12.5.... I wonder is it still rendering this on the CPU? Is it possible that some sort of transfer from-to video memory and back is responsible? Is my code wrong? The code seems pretty straight forward, but I've never tried this before... public partial class GraphDrawingDialog : Form { // general PointF[][] pts; // SharpDX SharpDX.DXGI.Factory dxgiFactory; SharpDX.DXGI.SwapChain swapChain_SharpDX; SharpDX.Direct2D1.Factory d2dFactory; SharpDX.Direct2D1.RenderTarget renderTarget; SharpDX.Direct3D10.Device1 deviceSharpDX; SharpDX.Direct3D10.Texture2D backBuffer; SharpDX.Direct3D10.RenderTargetView backBufferView; public GraphDrawingDialog() { InitializeComponent(); Random r = new Random(); pts = new PointF[10][]; for (int i = 0; i < pts.Length; i++) { pts = new PointF[panel1.Width]; for (int k = 0; k < pts.Length; k++) { pts[k] = new PointF(k, r.Next(0, panel1.Height)); } } SharpDXInit(); } private void SharpDXInit() { SharpDX.DXGI.SwapChainDescription desc = new SharpDX.DXGI.SwapChainDescription() { BufferCount = 1, ModeDescription = new SharpDX.DXGI.ModeDescription( panel1.Width, panel1.Height, new SharpDX.DXGI.Rational(60, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = panel1.Handle, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), SwapEffect = SharpDX.DXGI.SwapEffect.Discard, Usage = SharpDX.DXGI.Usage.RenderTargetOutput }; SharpDX.Direct3D10.Device1.CreateWithSwapChain( SharpDX.Direct3D10.DriverType.Hardware, SharpDX.Direct3D10.DeviceCreationFlags.Debug | SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport, desc, SharpDX.Direct3D10.FeatureLevel.Level_10_0, out deviceSharpDX, out swapChain_SharpDX); dxgiFactory = swapChain_SharpDX.GetParent<SharpDX.DXGI.Factory>(); //dxgiFactory.MakeWindowAssociation(panel1.Handle, WindowAssociationFlags.IgnoreAll); backBuffer = SharpDX.Direct3D10.Texture2D.FromSwapChain<SharpDX.Direct3D10.Texture2D>(swapChain_SharpDX, 0); backBufferView = new SharpDX.Direct3D10.RenderTargetView(deviceSharpDX, backBuffer); SharpDX.DXGI.Surface surface = backBuffer.AsSurface(); d2dFactory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded); renderTarget = new SharpDX.Direct2D1.RenderTarget( d2dFactory, surface, new SharpDX.Direct2D1.RenderTargetProperties() { PixelFormat = new SharpDX.Direct2D1.PixelFormat( SharpDX.DXGI.Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied), } ); /*renderTarget = new WindowRenderTarget( factory, new RenderTargetProperties(), new HwndRenderTargetProperties() { Hwnd = panel1.Handle, PixelSize = new System.Drawing.Size(panel1.Width, panel1.Height) });*/ } protected override void OnClosed(EventArgs e) { renderTarget.Dispose(); d2dFactory.Dispose(); dxgiFactory.Dispose(); base.OnClosed(e); } private void button1_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); int frames = 0; while (sw.ElapsedMilliseconds < 10000) { SharpDX.Direct2D1.PathGeometry geometry = new SharpDX.Direct2D1.PathGeometry(d2dFactory); SharpDX.Direct2D1.GeometrySink sink = geometry.Open(); sink.BeginFigure(new PointF(0, 0), new SharpDX.Direct2D1.FigureBegin()); sink.AddLines(pts[frames % 10]); sink.EndFigure(new SharpDX.Direct2D1.FigureEnd()); sink.Close(); renderTarget.BeginDraw(); renderTarget.Clear(new SharpDX.Color4(255, 0, 0, 0)); SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush( renderTarget, new SharpDX.Color4(255, 255, 255, 255)); renderTarget.DrawGeometry(geometry, brush); brush.Dispose(); renderTarget.EndDraw(); geometry.Dispose(); frames++; swapChain_SharpDX.Present(1, SharpDX.DXGI.PresentFlags.None); } MessageBox.Show("D2D Frames: " + frames); } private void button2_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); int frames = 0; while (sw.ElapsedMilliseconds < 2000) { Graphics gfx = panel1.CreateGraphics(); gfx.Clear(Color.Black); Pen p = new Pen(Color.White); gfx.DrawLines(p, pts[frames % 10]); p.Dispose(); gfx.Dispose(); frames++; } MessageBox.Show("GDI Frames: " + frames); } }
  13. AlanMcCormick

    Fastest way to draw connected lines?

    I'm having trouble figuring out how to do this... can you help me? I tried creating a RenderTarget and passing in a surface.. but I'm not sure if I created it correctly.. do I need two factories? one for DXGI and one for D2D? Also, my code didn't crash, but also didn't display anywhere.
  14. AlanMcCormick

    Fastest way to draw connected lines?

    I'll give that a try. One thing about the lines was they were from random data.. If you had a smoother curve or something of lines.. it would be less up and down and probably faster. It isn't a perceived problem. I may be getting this data from multiple devices in real time and graphing it to compare the relative values. If I can only draw 1 line 25 times a second, then if I add a bunch of lines to the same graph, with other information and grid lines etc. etc. it could become sluggish especially while panning the graph. I would also expect it to run faster than GDI.
  15. AlanMcCormick

    basic neural network

    I 'm not sure about your code either, but have you tried reducing your learning rate to something much smaller? 0.1, 0.05 etc. If your learning rate is too high it may not converge
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!