WIP: fonts.
This commit is contained in:
174
DaggerFramework/Source/Rendering/StandardRenderer.cs
Normal file
174
DaggerFramework/Source/Rendering/StandardRenderer.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
|
||||
using Silk.NET.GLFW;
|
||||
using Silk.NET.OpenGL;
|
||||
|
||||
namespace DaggerFramework.Rendering
|
||||
{
|
||||
/// <summary>
|
||||
/// A standard, OpenGL-based renderer.
|
||||
/// </summary>
|
||||
public class StandardRenderer : Renderer
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Vector2 WindowSize => throw new NotImplementedException();
|
||||
/// <inheritdoc />
|
||||
public override bool ShouldRun => throw new NotImplementedException();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(RendererSettings settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void EndFrame()
|
||||
{
|
||||
// throw new NotImplementedException();
|
||||
EndFrameUnsafe();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ClearBackground(Color color)
|
||||
{
|
||||
_gl.ClearColor(color.ToSystemColor());
|
||||
_gl.Clear((uint)ClearBufferMask.ColorBufferBit);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void CreateWindow(string title, Vector2 size) => CreateWindowUnsafe(title, size);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Shutdown()
|
||||
{
|
||||
CloseWindowUnsafe();
|
||||
_glfw.Terminate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawCircle(float radius, Color color)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawDebugText(string text, int fontSize, Color color)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawRectangle(Vector2 size, Color color)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawTexture(int id, Color tint)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetFrameTime()
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int LoadTexture(Texture2d texture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetTargetFps(int fps)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetTransform(Vector2 position, float rotation = 0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetTransform(Matrix4x4 transform)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetWindowTitle(string title)
|
||||
{
|
||||
SetWindowTitleUnsafe(title);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SetWindowVSync(bool value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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(string text, int fontSize, Color color)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int LoadFont(Font font)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void DrawText(int fontId, string text, int fontSize, Color color)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private GL _gl;
|
||||
private Glfw _glfw;
|
||||
private unsafe WindowHandle* _windowHandle;
|
||||
private Vector2 _windowSize;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user