C# Unity drawing to Texture2D - c#

I need to render shapes to a Texture2D (lines, rect, roundrect, filled and line polygons). I can't find a proper solution for this. I found one very basic library for drawing but that only can draw line and fill rect. I rather not want to write my own rendering library in 2021 or hacking SkiaSharp in unity.
It would be nice to find any c# graphics library what is just rendering to an rgb array, but I can't find any so far.
What would be the best solution for this?

Related

C# 2D Drawing custom style of lines and curves

I build an application which part is also drawing into video frames. For this I am using Graphics library from System.Drawing. Drawing is working fine and is already implemented. But I also need to be able to draw straight lines with for example this kind of curvy pattern:
.
Could somebody help me how this could be achievable?

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.

DirectX on WPF Geometry

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.

Rotate text - Managed DirectX (C#)

I am currently developing a little application with a highly-dynamic GUI which needs a lot of refreshing and drawing. To archive this, I am using managed DirectX.
I successfully painted a little string in a specific font to specific coordinates, but I have no idea on how I could rotate the drawn text...
Any ideas?
Thanks!
Okay, I found no native method to archive my goal.
So I painted the Font on a bitmap, created a texture and used sprites to draw my font texture.

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