140 lines
4.1 KiB
C#
140 lines
4.1 KiB
C#
using System.Drawing;
|
|
using System.Numerics;
|
|
|
|
using Silk.NET.GLFW;
|
|
using Silk.NET.OpenGL;
|
|
|
|
namespace DaggerFramework.Rendering
|
|
{
|
|
public class GlRenderer : Renderer
|
|
{
|
|
public override Vector2 WindowSize => throw new NotImplementedException();
|
|
public override bool ShouldRun => throw new NotImplementedException();
|
|
|
|
public override void Initialize(RendererSettings settings)
|
|
{
|
|
|
|
}
|
|
|
|
public override void CreateAndInitialize(WindowSettings windowSettings, RendererSettings renderSettings)
|
|
{
|
|
CreateWindow(windowSettings);
|
|
Initialize(renderSettings);
|
|
}
|
|
|
|
public override void BeginFrame()
|
|
{
|
|
_glfw.PollEvents();
|
|
_gl.Viewport(new Size((int)_windowSize.X, (int)_windowSize.Y));
|
|
}
|
|
|
|
public override void EndFrame()
|
|
{
|
|
// throw new NotImplementedException();
|
|
EndFrameUnsafe();
|
|
}
|
|
|
|
public override void ClearBackground(Color color)
|
|
{
|
|
_gl.ClearColor(color);
|
|
_gl.Clear((uint)ClearBufferMask.ColorBufferBit);
|
|
}
|
|
|
|
public override void CreateWindow(string title, Vector2 size) => CreateWindowUnsafe(title, size);
|
|
public override void Shutdown()
|
|
{
|
|
CloseWindowUnsafe();
|
|
_glfw.Terminate();
|
|
}
|
|
|
|
public override void DrawCircle(float radius, Color color)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void DrawDebugText(Vector2 position, string text, int fontSize, Color color)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void DrawRectangle(Vector2 size, Color color)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void DrawTexture(int id, Color tint)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override double GetFrameTime()
|
|
{
|
|
return 0.0;
|
|
}
|
|
|
|
public override int LoadTexture(Texture2d texture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void SetTargetFps(int fps)
|
|
{
|
|
return;
|
|
}
|
|
|
|
public override void SetTransform(Vector2 position, float rotation = 0)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void SetTransform(Matrix4x4 transform)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override void SetWindowTitle(string title)
|
|
{
|
|
SetWindowTitleUnsafe(title);
|
|
}
|
|
|
|
public override void SetWindowVSync(bool value)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override bool WindowShouldClose() => WindowShouldCloseUnsafe();
|
|
|
|
private unsafe void CreateWindowUnsafe(string title, Vector2 size)
|
|
{
|
|
_glfw = GlfwProvider.GLFW.Value;
|
|
_glfw.Init();
|
|
|
|
_glfw.WindowHint(WindowHintInt.ContextVersionMajor, 4);
|
|
_glfw.WindowHint(WindowHintInt.ContextVersionMinor, 6);
|
|
_windowHandle = _glfw.CreateWindow((int)size.X, (int)size.Y, title, null, null);
|
|
|
|
_glfw.MakeContextCurrent(_windowHandle);
|
|
_gl = GL.GetApi(_glfw.GetProcAddress);
|
|
_glfw.SwapInterval(1);
|
|
|
|
_windowSize = size;
|
|
}
|
|
private unsafe void CloseWindowUnsafe() => _glfw.DestroyWindow(_windowHandle);
|
|
private unsafe bool WindowShouldCloseUnsafe() => _glfw.WindowShouldClose(_windowHandle);
|
|
private unsafe void SetWindowTitleUnsafe(string title) => _glfw.SetWindowTitle(_windowHandle, title);
|
|
private unsafe void EndFrameUnsafe()
|
|
{
|
|
_glfw.SwapBuffers(_windowHandle);
|
|
}
|
|
|
|
public override void DrawSdfText(Vector2 position, string text, int fontSize, Color color)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private GL _gl;
|
|
private Glfw _glfw;
|
|
private unsafe WindowHandle* _windowHandle;
|
|
private Vector2 _windowSize;
|
|
}
|
|
} |