OverviewFilesCommitsIssuesDocsReleasesPeers

ifsrenderer-linux / AvaloniaShell / Program.cs

55 lines · csharp ref:
using System;

using Avalonia;

using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

namespace IFSRenderer.AvaloniaShell;

internal static class Program
{
    /// <summary>
    /// The hidden GLFW window whose OpenGL context the engine renders into.
    /// </summary>
    /// <remarks>
    /// GLFW mandates that initialisation and window creation happen on the process
    /// main thread, so it is created here rather than on the render thread. The
    /// OpenGL *context* it carries is a different matter - a context may be made
    /// current on any single thread - so it is released here and acquired by the
    /// render thread in <see cref="RenderService"/>.
    /// </remarks>
    public static NativeWindow GlWindow { get; private set; }

    [STAThread]
    public static void Main(string[] args)
    {
        GlWindow = new NativeWindow(new NativeWindowSettings
        {
            ClientSize = new OpenTK.Mathematics.Vector2i(64, 64),
            APIVersion = new Version(4, 5),
            Profile = ContextProfile.Core,
            StartVisible = false,
            StartFocused = false,
            Title = "IFSEngine",
        });
        // Creating the window made the context current here; hand it off.
        GlWindow.Context.MakeNoneCurrent();

        try
        {
            BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
        }
        finally
        {
            GlWindow.Dispose();
        }
    }

    public static AppBuilder BuildAvaloniaApp() =>
        AppBuilder.Configure<App>()
            .UsePlatformDetect()
            .WithInterFont()
            .LogToTrace();
}