Is there any way to draw and display graphics on the screen with .NET Core? I would like to create a graphics application that runs on multiple platforms.
4 Answers
You can actually use OpenGL to draw graphics with .NET Core, but it seems a bit cumbersome, if you are just committed to using C# and not .NET Core maybe Unity is a better option for you.
If you are trying to make a "desktop application" with GUI elements you can also look into Electron combined with TypeScript (which is somewhat similar to C#), this is how they made Visual Studio Code for example
EDIT: I just found another very interesting article (by the same guy I've mentioned in the comments) called Building a 3D Game Engine with .NET Core, I'm pretty sure you can get some inspiration out of that how to use OpenTK, Veldrid and ImGui.NET for drawing on screen.
- 4,994
 - 6
 - 34
 - 58
 
- 
                    OK, I understand that there is nothing that is truly cross-platform to draw on the screen using .NET Core, so we would have to rely on a platform-specific set of "Platform Invokes", right? – SuperJMN Jan 09 '17 at 13:06
 - 
                    2I'm not really a pro when it comes to graphic manipulation, but at the end of the articel I included in my answer the author talks about this guys https://github.com/mellinoe and from a quick look he has 4 very interesting projects on there that all do .NET core graphics manipulation in a more abstracted way (ImGui.NET, vk, veldrid, ge) and he also contributed to something called Avalonia which you can also check out, but I haven't really figured out if this runs on .NET core **EDIT:** also have a look into OpenTK https://www.nuget.org/packages/OpenTK.NETCore/ – Staeff Jan 09 '17 at 13:22
 - 
                    
 - 
                    1@SuperJMN I've just made an edit because I've found another interesting article, so maybe also look into that – Staeff Jan 25 '17 at 10:28
 - 
                    1Regardless of what final rendering you choose try to write your code logically with a clear tier boundary, this will help you if you need to change and do not cost much time. Your custom method DrawSphere(...) for example will give logical instructions to draw a sphere. Only code below this method will be drawing specific for the library you choose, while code above will be fully logical. – Stefanos Zilellis Jun 24 '19 at 09:26
 
You can use System.Drawing.Common NuGet package supports .net core however be aware some methods are not supported cross-platform.
You can use https://www.nuget.org/packages/OpenTK.NetStandard/
Instruction: how to create your first window for OpenGL graphics
- dotnet new console
 - dotnet add package OpenTK.NetStandard
 - dotnet run
 
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace dotnet_opentk
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var window = new Window())
            {
                window.Run();
            }
        }
    }
    class Window : GameWindow
    {
        protected override void OnLoad(System.EventArgs e)
        {
            GL.ClearColor(0.1f, 0.2f, 0.3f, 1f);
            Console.WriteLine(GL.GetString(StringName.Version));
        }
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);
            SwapBuffers();
        }
    }
}
- 868
 - 10
 - 17
 
Another library that supports basic 2D graphics, and listening for window events like input, is SFML which has C# bindings in the form of SFML.Net
Simply start a new NET Core Console application and add the SFML.Net NuGet package to the project.
Then replace the program's body with the following code:
using SFML.Graphics;
using SFML.Window;
using System;
class Program
{
    static void Main(string[] args)
    {
        RenderWindow window = new RenderWindow(new VideoMode(640, 480), "This is a new window");
        CircleShape cs = new CircleShape(100.0f);
        cs.FillColor = Color.Green;
        window.SetActive();
        window.Closed += new EventHandler(OnClose);
        while (window.IsOpen)
        {
            window.Clear();
            window.DispatchEvents();
            window.Draw(cs);
            window.Display();
        }
    }
    static void OnClose(object sender, EventArgs e)
    {
        RenderWindow window = (RenderWindow)sender;
        window.Close();
    }
}
This gives you a window with a green circle. When you close the graphics window the application will shut down.
Hopefully this will help get you started!
- 622
 - 1
 - 9
 - 19