DirectX on WPF Geometry - c#

I just have a question:
I need to draw some WPF geometries in a canvas, and each geometry's surface is a complicate Texture2D in Direct3D 11. I'm using SharpDX and just convert the Texture2D into a MemoryStream then Convert to a WPF ImageSource, because I'm using Compute Shader, the Format.Bgra isn't supported with UAV texture, so I can't use a D3DImage. Since there're performance issue, how can I bind a Texture2D to a WPF Geometry directly? Thanks.

For performance reasons, you should perform the whole rendering with SharpDX and not using WPF Geometries, only D3DImage to synchronize the result of rendering with WPF. If you need to convert a texture from one format to another to match WPF formats, you can simply render a full quad with a simple shader copying the texture. If you are doing this with SharpDX Toolkit, it is fairly easy to develop it as it is providing a WPF control.

Short answer is you can't, WPF 3D is still in its infancy and custom shader support is available for 2D effects only. Best advice I can offer at the moment is to render your geometry onto an XNA surface and display it in an AirspacePopup with your WPF controls on top.

Related

Display graphics on top of OpenGL game

This is not really language-specific (although I am most comfortable in C#). I am basically trying to create an application that would display basic 2D graphics over an OpenGL application (specifically FlightGear). There would be no need to have mouse-interaction (e.g. clicks) with the overlay - it would be for informational purposes only.
What is the simplest way of going about this?
If I understand your question correctly, you just have to render your scene and after that you can change your camera transformation to a parallel projection, with the size of your viewport. You can now render simple rectangles with your 2D graphics as textures on it.

SharpDX render 2D polygon to offscreen bitmap

I'm wondering what is the best way to render a polygon to WPF-compatable BitmapSource using DirectX (preferably SharpDX)?
I have to render tens of thousands of polygons like this offscreen to BitmapSource then include in a WPF applicatoin and need the fastest possible way to do it. The rendering must be performed off-screen for later showing in a WPF Image OR exporting to file.
(not actual size. Polygon size ranges from 16x16 to 24x24 pixels)
Any suggestions welcome!
WPF has its own ability to render shapes and does so using DirectX as DirectX is the underlying technology behind WPF. Here is a link to some some sample code for using SharpDX in WPF.
http://directx4wpf.codeplex.com/

Points array visualization in 3d

I need to show points array in three-dimensional coordinate system. Which component or library should I use for it(Winforms/WPF)?
Here is a tutorial for Direct3D in C#, it's for winforms: http://msdn.microsoft.com/en-us/library/ms920768.aspx. I don't think it matters whether you use winforms or wpf, the trick is to get your videocard do you drawing and that bypasses wpf.

Making fast drawing canvas like Photoshop in wpf

I have to write a faster canvas in wpf for my upcoming project. The canvas will be similar to adobe photoshop canvas. It should have layers and objects and also direct drawing methods.
I am thinking to write the canvas in vc++ or in c# and use it into wpf. Is it a good idea to write the canvas in any other language and use it with wpf? Or should I extend the existing canvas of wpf? If using other language, then vc++ will be better or c#?
Thanks
You are looking for the writeable bitmap - see http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx
This allows direct pixel level manipulation of graphical data, basically designed for what you want to do.
I suggest you use QT. :)

How to animate rotating cube in C#?

I would like to do something like this: a rotating cube on a form. I don't want to use any external library or dll, just pure .NET 3.5 (without directx). And a cube build with lines only. Could you please tell me how to do this?
I don't want to use external libraries because I don't need > 100 MB library to do this thing right? I want only to animate a rotating cube made with lines.
This is how you go about making a Cube in GDI+
C# 3D Drawing with GDI+ Euler Rotation
http://www.vcskicks.com/3d-graphics-improved.html
C# 3D-Drawing Cube with Shading
http://www.vcskicks.com/3d_gdiplus_drawing.html
Study assignment? This can be done with some simple 3D maths. You just need to understand the basics of matrix algebra, 3D transformations, and 3D->2D view transformation. The DirectX tutorial covers this, but you can google for it and you'll get plenty of other tutorials.
Added: Just to clarify - I'm not suggesting to use DirectX or anything. You can do this with standard System.Drawing tools. You just need to understand the math, and that's explained in the DirectX tutorials.
You might try using WPF and the 3D Tools source code released by the WPF team.
3DTools
Assuming you are using WPF for your GUI:
Make an animated PNG of the cube using a graphics program.
Use the APNG WPF Control to insert the image into your GUI.
This will yield a small assembly size and transparent background if needed.
You need a way to represent 3d points. There is no ready struct for that in .NET unless you use directx or WPF.
Then with a standard euler rotation matrix applied to the points you get the transformed points. If you only do rotations you can get away with 3x3 matrix, but if you want translation you better use 4x4 matrices and homogenous points.
After this you need a way to project those 3d points to the 2d canvas. Depending whether you are using perspective or orthographic projection the projection matrix will look a bit different.
Look into WPF in general, it will help you do this with a few measly lines of code. You can also host a WPF window in Forms.
http://msdn.microsoft.com/en-us/library/aa970268.aspx

Categories