Change GameWindow startup color to something else than default white?

Viewed 21

When you instantiate a new GameWindow, its background color is white, I would like to change it to black for instance.

The problem is further visible if you have a long initialization sequence happening.

The closest I could get is to set clear color in constructor then swap but it ain't perfect.

using System.Drawing;
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;

internal static class Program
{
    private static void Main(string[] args)
    {
        var gws = new GameWindowSettings();
        var nws = new NativeWindowSettings
        {
            Size = new Vector2i(320, 240)
        };

        using (var game = new Game(gws, nws))
        {
            game.Run();
        }
    }
}

internal class Game : GameWindow
{
    public Game(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
        : base(gameWindowSettings, nativeWindowSettings)
    {
        // close but still shows a white background at startup for some time
        GL.ClearColor(Color.Red);
        GL.Clear(ClearBufferMask.ColorBufferBit);
        Context.SwapBuffers();
    }

    protected override void OnLoad()
    {
        base.OnLoad();
        GL.ClearColor(Color.Green);
    }

    protected override void OnRenderFrame(FrameEventArgs args)
    {
        base.OnRenderFrame(args);
        GL.Clear(ClearBufferMask.ColorBufferBit);
        Context.SwapBuffers();
    }

    protected override void OnResize(ResizeEventArgs e)
    {
        base.OnResize(e);
        GL.Viewport(0, 0, e.Width, e.Height);
    }
}

enter image description here

Question:

How to get GameWindow to use another color than white when it's first shown?

0 Answers
Related