I'd like to draw heavy usage graphics in the fastest way. If I use standard C# graphics callbacks (es.graphics.drawline) am I doing it right? Or am I to use different libraries?
Graphics.DrawLine is a GDI+ call. If you're using Windows Forms and doing your drawing with the System.Drawing classes, you're using GDI+, which is not hardware-accelerated. To get hardware acceleration, you need to use WPF in place of WinForms or draw with Direct3D/Direct2D. The latter two (Direct3D/Direct2D) are COM-based, so you'll need a .NET wrapper. Microsoft wrapped Direct3D for .NET with Managed DirectX followed by XNA. Both (I believe) are now deprecated. There are also third-party wrappers for the DirectX libraries that are more up-to-date.
Edit: I just learned from #HansPassant's comment that GDI+ is 2D accelerated. I thought that only applied to GDI (as opposed to GDI+) because GDI+ handles things like antialiasing that (as I understood it) 2D hardware didn't do. But apparently I was wrong.
Related
Is it possible to render VC++ OpenGL output to a panel in Winforms window created with C# ? I'm aware of Tao framework and OpenTK but I don't want to rely on third party support. There is an article here but this is merely only pixel reproduction and I think this method does not guarantee user interaction with OpenGL scene.
Yes, this is absolutely possible. You have to create the OpenGL context on the HWND that is given by panel.Handle (it's an IntPtr, but can easily be cast to HWND). Be aware, that this is only working in Windows Forms, since in WPF controls do not necessarily have their own HWND. Here is another stackoverflow question, that covers a similar topic.
There are several ways how to access native C++ code from a C# application, so it might be that, depending on your needs, you will have to write a wrapper in C++/CLI around your native C++ library simmilar to (here or here).
I would like to write a simple ray tracer using WPF. It is a learning project and thus I favour configurability over performance (otherwise I'd go for C++).
I still want relatively fast pixel drawing. A previous question on StackOverflow contains code to achieve this in WPF, by obtaining a GDI bitmap. From the relatively little I know about Windows programming,
GDI is slow
DirectX is fast
WPF uses DirectX underneath (not sure which parts of WPF though)
Is it possible to obtain pixel-level access using DirectX (not GDI) through the WPF Canvas (or similar)?
I will also consider suggestions for incorporating DirectX API calls within a WPF window (alongside other WPF controls) if that is possible.
Thanks in advance.
Interesting, but with raytracing, writing the pixels to the screen will (should) not be the slow part. You can use WriteableBitmap for the purpose, though. It's certainly quick enough for what you want.
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx
(For info, I use it in this emu/IDE - http://0x10c-devkit.com/ - and it can refresh a low res display with great performance. There's the source to that on the github repository, the LEM1802 plugin.)
Ah, this bit: https://github.com/kierenj/0x10c-DevKit/blob/master/PluginAPI/NyaElektriska.LEM1802/GPU.cs - see UpdateDisplay.
Another solution is WriteableBitmapEx. It extends the builtin WriteableBitmap.
There is an open Source Project Called Direct Canvas wich is A hardware accelerated, 2D drawing API that supports vector graphics, multimedia files, extensible pixel shaders, blending modes and more!
http://directcanvas.codeplex.com/
Demo http://www.youtube.com/user/jdollah69#p/u
I have done some looking and I can't figure out a good way to write a 2D tile/sprite based game in C# for Win8. According to the MSDN documentation:
You can use managed code languages like C# and Visual Basic to develop 2D (and lightweight 3D) games.
The problem is that I can't figure out how to do this. The reason I would like to use C# is because I already have a lot of code written for Windows Phone that I would like to reuse.
Can anyone point me to how I would write a fairly efficient 2D tile/sprite MetroUI game for Win8? The only thing I can find uses C++ and DirectX.
[EDIT]
To clarify I do not care too much what I use (WinRT, DirectX...) so long as I can submit to the app store, and write my code in C#.
If you are familiar with the DirectX API, you can use SharpDX available via http://sharpdx.org. It is basically exposing DirectX APIs into C#. From my understanding, if you are going to upload apps to the store, the SharpDX should be fine and pass compliance, but I would look into it further before going too deep.
Also, as of this time, not all of the features are available (like Direct2d not fully certified for Win8 Metro).
If your game uses simple graphics, you can use Drawing Library for Modern UI, it exposes a GDI+ like interface to be used in XAML/C#/VB.NET Windows 8 Modern UI applications, it works by drawing to a XAML Canvas.
If you're looking for something quick and easy check out the "Physics Helper XAML" project;
http://physicshelperxaml.codeplex.com/
It's based on the farseer engine, and comes with sample apps. There are a few games already released using it.
http://www.andybeaulieu.com/Home/tabid/67/EntryID/223/Default.aspx
Have a look at:
[XAML images sample] (http://code.msdn.microsoft.com/windowsapps/0f5d56ae-5e57-48e1-9cd9-993115b027b9/sourcecode?fileId=102748&pathId=677969581)
The page and samples give some code for NineGrid and WriteableBitmap Image manipulation.
You can now use Win2D (open source, released by Microsoft for metro/WinRT apps) which provides hardware-accelerated 2D graphics rendering.
I have a C# application which renders 2D graphics into bitmaps using System.Drawing.Graphics.
I now want to port this application to work on normal .net on windows, mono on linux and in Silverlight/Moonlight.
But at least Silverlight is lacking System.Drawing. Since I don't want to maintain several copies of my rendering code I need one cross platform graphics library.
I see a few alternatives to achieve that:
Use a library available on all platforms
Use a port of System.Drawing to silverlight
Write a wrapper around the graphics libraries of the different platforms myself
I'm trying to avoid 3) due to the required work.
So does anybody know a free library for 1) or 2)? Library should have a reasonable license, i.e. free and not GPL (LGPL is fine).
There is no common library that does the sort of things that System.Drawing does.
This would be a massive undertaking for very little payback.
Of these options this is the only one that is viable.
I'm not sure what sort of graphics you are doing but have you considered XNA? I don't know about its Mono credentials but via Silversprite you might be able to build stuff that compiles for both .NET and Silverlight.
I have a C# application that recolors an image using ColorMatrix. I understand that ColorMatrix doesn't make use of the GPU. What would be the best avenue to explore if I wanted to use the GPU to recolor the image? Pointers to where look in any suggested libraries would be appreciated, examples even more so!
What you're searching for are call Pixel Shaders, they are tiny routines that are executed in parallel on each pixel of a given texture/image by the GPU. Since you're using C#, you can use WPF that allows pixel shaders to be applied on any element. Here's a lib on Codeplex that includes many shaders like making a monochrome or a negative image.
If you don't plan on using WPF which might be 'overkill' if you only intend to do image processing, starts using technologies like Direct3D, OpenGL or the recent Direct2D to apply with ease pixel shaders on a rendering target.