I want to use SlimDX (DirectX 11) to render the contents of an Image in WPF.
The problem is that I can't find a way to link the SwapChain to a D3DImage. (The DirectX 11 example uses the SlimDX RenderForm.)
Direct3D 10 and 11 are not too different in API or how they work. A SwapChain is used to present to an hWnd, not required to render. This is the same with DX10, and even the very different DX9.
In any case, this example I made should be enough to help you take your Texture2D that you render to and pass it to WPF. Don't remember if I finished the DX11, but it's pretty much the same thing.
http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/437/Direct3D-10-11-Direct2D-in-WPF.aspx
You might want to go take a look a Jeremiah Morill's DirectCanvas implementation on Codeplex. He is also very helpful if you drop him a line.
Look at the WPF example in the DX10 examples. It should work about the same for DX11 I think. Because the D3DImage only works with DX9 stuff, you need to use a dx10/11 shared texture.
Related
we have a project at university where we have to create fractals that are controllable by the user (with kinect). We are still in an early phase where we evaluate some ideas (though we already got some working prototypes). Our idea right now is to use a blackboard-image as background and draw the fractals on top of it. To make this look more natural we'd like to use some crayon effects on the lines we draw.
Our internet-research produced two main ideas to achieve this:
Paint an image of a photoshop-like brush for every moueposition of a line.
Use shaders on drawline-functions.
The first does work for an early test, but looks awful. I guess the latter would be the best approach, but the information in the internet seems to be lacking regarding this topic. At least I didn't find anything that really helped a lot. The Questions is:
Has anyone links or general tips on how to achieve this effect, or is it not possible in C#/WPF. Might there be an even better way? And how can I apply a created shader to drawline-method/brushes?
Thanks in advance and kind regards
Michael
EDIT
Nice tip from #Bradley Uffner ! (unfortunately he deleted his answer)
There is a tutorial here on how to achieve such effect :
http://alastaira.wordpress.com/2013/11/01/hand-drawn-shaders-and-creating-tonal-art-maps/
Another thing I've found recently which might interests you :
http://blogs.msdn.com/b/hemipteran/archive/2014/03/26/generating-noise-for-applications.aspx
I've didn't read well the title of your question, Windows Forms do not support shaders at all.
Be more specific about the meaning of a crayon shader
Regarding using shaders in WPF, you cannot apply them at a line-level but on a Control level instead.
This the class representing a shader in WPF:
http://msdn.microsoft.com/en-us/library/system.windows.media.effects.effect(v=vs.110).aspx
What I suggest
use an Image and set its Source property to use a WriteableBitmap
use the excellent WriteableBitmapEx library to easily draw on it, basically it's the WriteableBitmap in WPF but with many extension methods for drawing lines, circles, rectangles etc ...
then apply your shader to the Effect property of Image
For developing your shader
Use Shazzam, it allows you to develop an HLSL shader for WPF in a cool interface, preview it instantly and it will generate the Effect class ready to paste on your project.
There might be a couple of interesting shader for you in DOSBox SVN-Daum
Here's an example of the cartoon shader :
Obviously there will be quite some work as copy-pasting the shader to Shazzam won't work right away but you'll know what are the maths behind achieving the effect.
Mark the answer as accepted if you are satisfied with it :D if not edit your question and add more details.
How do you put a Windows Form Application on top off everything on your screen?
Just setting the topmost-property isn't enough when you're running fullscreen games.
If anyone has a solution for good old Forms i'll also be happy
I've seen many posts on this forum that say it's impossible but i know it's not couse i've seen alot of apps (fraps, teamspeak overlay, xfire, etc) that does this.
If you want to use a graphics library to display something always on screen, you may want to start here on SO. There are wrapper libraries available like OpenTK for OpenGL. If you want to go the DirectX route you'll need to load in the C++ libraries and access them using P/Invoke. There's a good tutorial to start with on msdn. Wrappers for DirectX also exist in the form of SharpDX.
I am a decent winforms programmer and I have done a little programming in XNA, I am trying to learn WPF.
I have a bunch of greyscale images that I want to add color to dynamically. to do this in XNA is easy simply indicate the color you want to use in the SpriteBatch.Draw method
SpriteBatch.Draw(Image,0,0,Color.blue)
Or something like that. That would draw my greyscale image with a blue hue to it. The purpose of this is to change the look of an Item, without having to draw them all manually.
I can't seem to find a good option in WPF
Ok, well I hope your are a decent ... programmer. This kind of image processing in WPF is not for the feint hearted. You certainly can't do it with the same ease that you displayed in your question example. Your best bet is to use someone else's code to do it for you. Please see the following articles for further help:
Image Processing Lab in C#
Image Processing is Done using WPF
If you're really hardcore, you can even plug High Level Shading Language (HLSL) pixel shader files into WPF to create all sorts of crazy visual effects. See Chapter 13 of the wonderful WPF Control
Development UNLEASHED book online for a great introduction to this subject.
I have an Image object in my application which the user can drag around. The object displays an image which is partly transparent, so the window background (which is itself a bitmap) can be seen through it.
I want to add a graphics effect to this object. Assume that I already have an algorithm for this effect — that’s not the issue. The issue is how to get this algorithm into WPF.
So I tried to look at how DropShadowEffect works, but the implementation displayed in Reflector is empty. I also tried to look at what methods from the abstract classes Effect and ShaderEffect I should override and there doesn’t seem to be anything related to actually rendering an effect.
So how do I create my own effect?
The best and fastest way is to use pixel shaders (supported starting with WPF 3.5 SP1 I think) . It will require some shader language (HLSL) knowledge, though :-)
Here is a tutorial: How Do I: Create Custom Pixel Shader Effects for WPF
a library on codeplex: Windows Presentation Foundation Pixel Shader Effects Library
an article with .NET 4 information (including Sliverlight support which has it too): SilverShader – Introduction to Silverlight and WPF Pixel Shaders
A very cool tool (and resource) is Shazzam it will help you to create the effects and it contains a nice tutorial.
I am transitioning from WinForms/XNA to WPF/SlimDX because:
a) all of the benefits of WPF over
WinForms (but learning curve = ouch!)
b) I would like to have multiple
SlimDX viewports attached to Panels.
XNA has 1 "game" screen.
c, last and least) DirectX 10 support
All of my previous XNA code is in C#. I am having trouble figuring out how to port this over to SlimDX and WPF on a high level. I have searched like crazy. The closest I have found are:
1) http://www.gamedev.net/community/forums/topic.asp?topic_id=507941
Many articles point to this discussion, however it is incomplete and I can't figure out the XAML, and I get device errors after attaching all of the _slimDXDevice and Window1 events that were left out.
2) http://www.codeproject.com/KB/WPF/D3DImage.aspx
This article assumes the user is porting C++. I am porting XNA code which is very close to MDX code.
If I could get to the point where I have a WPF form with a custom SlimDX driven viewport that was just a blue box, I could go from there. In XNA I rendered many separate RenderTargets and placed them all over the screen, now I want to attach them to controls. But first, just 1 blue box! :D
Any ideas? I feel that this is either simple or that there's some "cookie cutter" code that I'm missing. Greatly appreciated!
You can look at the sample now. It's just been checked in to our repository, so you'll need to use SVN to get it (or wait until we ship the Feb 2010 release):
http://code.google.com/p/slimdx/source/detail?r=1356
D3DImage is the class you want to use. Even though the codeproject tutorial is C++, it is very applicable to SlimDX and WPF.
All you have to do with your SlimDX, is run your code normally, but DO NOT run a Present(...) on your device or swap chain. At the point where you would put a Present(...), do a D3DImage.SetBackBuffer(...) and send your SlimDX surface's ComPointer property to it. Then do D3DImage.AddDirect(...) and you now have D3D composited in WPF.
Also, make sure you create a IDirect3DDevice9Ex or else your performance will be terrible in anything but XP!
I recently was messing around with D3DImage and SlimDX and didn't find it too difficult to get it working (with DirextX9). I have some code at my home pc that I'll post later, but it's pretty similar to the code in the links provided.
I was never able to get it working with a higher version of directx though. Jeremiah has a nice blog post about using a directx9 device as a link between directx 10/11/d2d and the D3DImage, but I couldn't get it working with Slimdx. I didn't put a whole lot of effort into though as directx9 did what I needed it to do and I kind of wanted it to work on XP.