using System.Drawing;
using System.Numerics;
using Silk.NET.GLFW;
using Silk.NET.OpenGL;
namespace DaggerFramework.Rendering
{
///
/// A standard, OpenGL-based renderer.
///
public class StandardRenderer : Renderer
{
///
public override Vector2 WindowSize => throw new NotImplementedException();
///
public override bool ShouldRun => throw new NotImplementedException();
public override Vector2 MonitorSize => throw new NotImplementedException();
public override int TargetFps { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override bool VSync { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override string WindowTitle { get => throw new NotImplementedException(); set => 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.ToSystemColor());
_gl.Clear((uint)ClearBufferMask.ColorBufferBit);
}
///
public override void Shutdown()
{
CloseWindowUnsafe();
_glfw.Terminate();
}
///
public override void DrawCircle(float radius, Color color)
{
throw new NotImplementedException();
}
///
public override void DrawDebugText(string text, int fontSize, Color color)
{
throw new NotImplementedException();
}
///
public override void DrawRectangle(Vector2 size, Color color)
{
throw new NotImplementedException();
}
///
public override void DrawTexture(Texture2d texture, Color tint)
{
throw new NotImplementedException();
}
///
protected override double GetFrameTime()
{
return 0.0;
}
///
protected override void SetTargetFps(int fps)
{
return;
}
///
public override void SetTransform(Vector2 position, Vector2 offset, float rotation = 0)
{
throw new NotImplementedException();
}
///
public override void SetTransform(Matrix4x4 transform)
{
throw new NotImplementedException();
}
///
protected override void SetWindowTitle(string title)
{
SetWindowTitleUnsafe(title);
}
///
protected override void SetWindowVSync(bool value)
{
throw new NotImplementedException();
}
///
protected 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(string text, int fontSize, Color color)
{
throw new NotImplementedException();
}
public override void BeginCamera2d(Vector2 offset, Vector2 target, float rotation, float zoom)
{
throw new NotImplementedException();
}
public override void EndCamera2d()
{
throw new NotImplementedException();
}
public override void CreateWindow(WindowSettings windowSettings)
{
throw new NotImplementedException();
}
protected override int GetMonitorWidth(int monitorId)
{
throw new NotImplementedException();
}
protected override int GetMonitorHeight(int monitorId)
{
throw new NotImplementedException();
}
protected override int GetCurrentMonitor()
{
throw new NotImplementedException();
}
public override void DrawText(Font font, string text, Color color)
{
throw new NotImplementedException();
}
private GL _gl;
private Glfw _glfw;
private unsafe WindowHandle* _windowHandle;
private Vector2 _windowSize;
}
}