How to use SlimDX inside a WPF C# application - c#

i'm totally new to SlimDX and WPF, but i need to create a multiple images in my application and one of them need to be a 3d visualizator of a point render, something like this:
http://img600.imageshack.us/img600/5879/6a00d83452464869e2017ee.gif
I found i can use SlimDX to use DirectX by C# instruction in my application, writing the result in a D3DImage component.
After some tries i made visual studio 2012 to recoignize that D3DImage (for some reason i needed to restart windows to made it work) but i don't know a few things:
How i can initialize a DirectX window inside that D3DImage? I really can't find any example or source code. All the examples i can find (like the 3 litte examples on SlimDX) are out of the WPF context
Where i can find some good documentation about SlimDX? The GameDev community seems some kinda bugged and i can't post anything (maybe because i'm not paying) and i can't find anything anywhere! How i'm supposed to learn that?
Not a single one of the SlimDX examples from the SVN can compile. I always got some reference error with the SlimDX library (empty path) and even re-importing from the correct path doesn't solve it
This is driving my crazy D:

I feel your pain. I haven't be working to much with the D3D stuff in SlimDX for lack of a reason to do so, But I have been playing around with DirectSound and DirectInput, So i'll tell you what i've figured out.
First Bullet:
I'm not sure initializing a D3D Window inside of an image is going to work. If you're using Windows Forms as your base, SlimDX includes a RenderForm or some such thing that subclasses Windows.Forms, and provides a decent amount of functionality. I still haven't figured it out for WPF, even though there's supposed to be a sample for that.
Second Bullet: Documentation is difficult to come by. There's some stuff on the site, and some stuff here, but what's really been helpful is the MSDN Reference for DirectX. SlimDX Mirrors the structures pretty well, and you can find out a lot by reading it. It DOES take a bit of conversion, because the DirectX reference is C++.
Third Bullet: Same problem. Never was able to figure out why.
Hope that helps a bit.

Related

WPF - Customizing title bar - uptodate solution

I love WPF but I'm in trouble.
Everything is very customizable but I didn't found anything valid for personalizing title Bar and Application borders.
I've understand that isn't possible to customize it directly because it's Windows that manage that, but otherwise I didn't found any valid solutions...
The only results that show up from google are using WindowChrome, but I think it's a VERY outdated solution.
Otherwise I only found THIS code snippet, but it is (for me, at least) a bit complicated to understand fully. Also, I've tried it but it doesn't allow to do some actions, like move window when maximized, but a lot of application (done in WPF) that I saw daily are able to do that.
In final word I can't find anything good.
I think WPF is very used even today, and I really don't understand how they do good looking solutions, that doesn't involve using a 2009 library.
You should get started with the docs. That sample you linked to will make more sense after that.
Basically, you are asking OS that you own the entire region and will take care of ensuring everything continues to behave as expected.

How to Lay Out C# Windows Forms Correctly, and allow for Scaling?

I am one week into learning C#, and I am currently working on a large application, as my C/C++ and Python knowledge comes into play - one problem here, however: C, C++ and Python don't have a GUI for creating GUIs.
I noticed that simply placing controls on a window won't work, and instead they need to be layed out in GroupBox-es and TableLayoutPanel(s) - and TabControl(s).
My aim is to achieve scaling, so at any size the program will look similar (this is very important for this program specifically).
At the moment, resizing makes my whole program flicker, and it doesn't even work properly.
I managed to sort-of do this in a previous program, however I've lost it at this point and have no idea what I'm doing.
Here are a few screenshots of my current work:
https://justpaste.it/119kb (screenshot links pasted on this website, as StackOverflow is not letting me put more than 2 links or images)
As you can see, it doesn't scale properly.
(as bad as it may look, I'm working on it - I haven't released the first version yet, and I will definitely revamp the whole program before release, just trying things out here)
Could someone enlighten me with tips on how to scale properly or inform me of something I'm not using?

Dynamic user-interface, WPF or not?

I'm currently working at a application that helps people understand how to do there job. You can see it as a personal coach that guides them trough all the steps they need to do that no normal person could keep remembering.
In my previous application we had the ability to show the user up to 4 pictures (what proves to be more then enough). The application would load the data and see how many pictures where in every instruction and then sort out the picture in the best fitting way without messing up the scale and resolution of the pictures. This all was done with GDI+ and worked very well.
Ofc, change is something that always happens, my bosses came up with some great ideas. So they want to be able to see movies on the screen, animated gif's, 3D models that can rotate or animate. So I think we had pushed GDI+ to it's limits and it's time to look for something different.
I have heard and readed about WPF but have no experience with it. Is it even possible to do all what I ask in WPF? And what about the old picture-merging thing I wrote, can we also get it done in wpf? I tried to make some things working but I didn't went as smooth as I hoped.
I'm also concerned about the fact that the interface needs to be dynamic, the one moment it should be showing picture with some text above it, the other moment it should be showing another text with a video under it.
I would love to hear some opinions here and if you got some other suggestions I should look into pls tell me. Thnx in advance
PS: If WPF is the choice, should I convince my boss to change to .net 4.0?
Although my answer can be termed subjective, I find WPF better than GDI+ anyday. You can do everything you can in WPF which you have done/could do in GDI+ (apart from pure games/game engines). If you can afford the steep learning curve of WPF, I think it will be better investment as this technology is not going anywhere soon.
As for .Net 4.0, WPF 4.0 does introduces some important functions in 4.0 (specially easing functions for animations) but there is nothing you cannot do without if you are using 3.5. I won't recommend 3.0 though mainly because of performance in animations.
WPF is up to the task, but you could also check other options.
You could go web based, and have either an XBAP (WPF in the browser), or Silverlight/Flash app.
Silverlight/Flash doesn't require that much from the client (to install), and is easily updatable, and both can do the job.

SlimDX viewports in WPF controls

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.

Gdi Guidance required

I am currently working in C# with wpf, I don't know about graphics, I want to learn about GDI and graphics from scratch, Can anyone help me by providing some basic knowledge or material?
Can anyone tell me to write very first program using Gdi?
If you want to learn about WPF I really suggest "Windows Presentation Foundation Unleashed"
http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917
Also check out this video from the PDC - Mastering WPF Graphics and beyond:
http://microsoftpdc.com/Sessions/CL31
And if you still want to check out GDI you should read this book
http://www.amazon.com/NET-Game-Programming-DirectX-9-0/dp/1590590511/ref=sr_1_1?ie=UTF8&s=books&qid=1259061198&sr=1-1
It starts out with GDI+ basics and then moves on to DirectX.
Even though it's written for VB.NET you'll get a great deal out of it as a c# developer as well. It helped me back in the days and writing the games in the book is just downright fun :p
(Hint: There is a huge performance issue with the first example in the book, try to solve it, it'll help you understand things even better).
I would advise you to take a look at the msdn, usually they have the best resource on the web. Also some tutorial website like code-project.com might help.

Categories