132 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			132 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Dashboard.Drawing;
 | 
						|
using System.Drawing;
 | 
						|
using Dashboard.Drawing.OpenGL;
 | 
						|
using OpenTK.Graphics;
 | 
						|
using OpenTK.Platform;
 | 
						|
using OpenTK.Graphics.OpenGL;
 | 
						|
using OpenTK.Mathematics;
 | 
						|
using TK = OpenTK.Platform.Toolkit;
 | 
						|
using Vector3 = System.Numerics.Vector3;
 | 
						|
 | 
						|
TK.Init(new ToolkitOptions()
 | 
						|
{
 | 
						|
    ApplicationName = "Dashboard Test Application",
 | 
						|
    Windows = new ToolkitOptions.WindowsOptions()
 | 
						|
    {
 | 
						|
        EnableVisualStyles = true,
 | 
						|
        IsDPIAware = true,
 | 
						|
    }
 | 
						|
});
 | 
						|
 | 
						|
WindowHandle wnd = TK.Window.Create(new OpenGLGraphicsApiHints()
 | 
						|
{
 | 
						|
    Version = new Version(3, 2),
 | 
						|
    ForwardCompatibleFlag = true,
 | 
						|
    DebugFlag = true,
 | 
						|
    Profile = OpenGLProfile.Core,
 | 
						|
    sRGBFramebuffer = true,
 | 
						|
 | 
						|
    SwapMethod = ContextSwapMethod.Undefined,
 | 
						|
 | 
						|
    RedColorBits = 8,
 | 
						|
    GreenColorBits = 8,
 | 
						|
    BlueColorBits = 8,
 | 
						|
    AlphaColorBits = 8,
 | 
						|
 | 
						|
    SupportTransparentFramebufferX11 = true,
 | 
						|
});
 | 
						|
TK.Window.SetTitle(wnd, "Dashboard Test Application");
 | 
						|
TK.Window.SetMinClientSize(wnd, 300, 200);
 | 
						|
TK.Window.SetClientSize(wnd, new Vector2i(320, 240));
 | 
						|
TK.Window.SetBorderStyle(wnd, WindowBorderStyle.ResizableBorder);
 | 
						|
 | 
						|
OpenGLContextHandle context = TK.OpenGL.CreateFromWindow(wnd);
 | 
						|
 | 
						|
TK.OpenGL.SetCurrentContext(context);
 | 
						|
TK.OpenGL.SetSwapInterval(1);
 | 
						|
 | 
						|
GLLoader.LoadBindings(new Pal2BindingsContext(TK.OpenGL, context));
 | 
						|
 | 
						|
DrawQueue queue = new DrawQueue();
 | 
						|
SolidBrush fg = new SolidBrush(Color.Black);
 | 
						|
SolidBrush bg = new SolidBrush(Color.White);
 | 
						|
bool shouldExit = false;
 | 
						|
 | 
						|
GLEngine engine = new GLEngine();
 | 
						|
engine.Initialize();
 | 
						|
 | 
						|
GlContext dbGlContext = new GlContext(wnd, context);
 | 
						|
ContextExecutor executor = engine.GetExecutor(dbGlContext);
 | 
						|
 | 
						|
EventQueue.EventRaised += (handle, type, eventArgs) =>
 | 
						|
{
 | 
						|
    if (handle != wnd)
 | 
						|
        return;
 | 
						|
 | 
						|
    switch (type)
 | 
						|
    {
 | 
						|
        case PlatformEventType.Close:
 | 
						|
            shouldExit = true;
 | 
						|
            break;
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
TK.Window.SetMode(wnd, WindowMode.Normal);
 | 
						|
 | 
						|
while (!shouldExit)
 | 
						|
{
 | 
						|
    TK.Window.ProcessEvents(true);
 | 
						|
 | 
						|
    TK.Window.GetFramebufferSize(wnd, out Vector2i framebufferSize);
 | 
						|
 | 
						|
    queue.Clear();
 | 
						|
    queue.Point(Vector3.Zero, 2f, fg);
 | 
						|
    queue.Line(Vector3.Zero, Vector3.One * 2, 2f, bg);
 | 
						|
    queue.Rect(Vector3.UnitX, 2 * Vector3.UnitX + Vector3.UnitY, fg, bg, 2f);
 | 
						|
 | 
						|
    GL.Viewport(0, 0, framebufferSize.X, framebufferSize.Y);
 | 
						|
    GL.ClearColor(0.3f, 0.3f, 0.3f, 1.0f);
 | 
						|
    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 | 
						|
 | 
						|
    executor.Draw(queue);
 | 
						|
    executor.EndFrame();
 | 
						|
 | 
						|
    TK.OpenGL.SwapBuffers(context);
 | 
						|
}
 | 
						|
 | 
						|
class GlContext : IGLContext
 | 
						|
{
 | 
						|
    public WindowHandle Window { get; }
 | 
						|
    public OpenGLContextHandle Context { get; }
 | 
						|
    public int ContextGroup { get; } = -1;
 | 
						|
 | 
						|
    public Size FramebufferSize
 | 
						|
    {
 | 
						|
        get
 | 
						|
        {
 | 
						|
            TK.Window.GetFramebufferSize(Window, out Vector2i framebufferSize);
 | 
						|
            return new Size(framebufferSize.X, framebufferSize.Y);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public event Action? Disposed;
 | 
						|
 | 
						|
    public GlContext(WindowHandle window, OpenGLContextHandle context)
 | 
						|
    {
 | 
						|
        Window = window;
 | 
						|
        Context = context;
 | 
						|
 | 
						|
        OpenGLContextHandle? shared = TK.OpenGL.GetSharedContext(context);
 | 
						|
        if (shared != null)
 | 
						|
        {
 | 
						|
            ContextGroup = _contexts.IndexOf(shared);
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
            _contexts.Add(context);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    private static readonly List<OpenGLContextHandle> _contexts = new List<OpenGLContextHandle>();
 | 
						|
}
 |