WIP: fonts.

This commit is contained in:
2023-06-20 00:18:35 +02:00
parent 72b6896d3e
commit 193462b747
11 changed files with 79 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using Raylib_cs;
@@ -98,6 +99,35 @@ namespace DaggerFramework.Rendering
return _texturePool.Count - 1;
}
public unsafe override int LoadFont(Font font)
{
// TODO: screw it, let's just load the font directly from the path. I give up.
// Raylib_cs.Font fontRay;
// string ext = "ttf";
// byte[] extBytes = new byte[Encoding.Default.GetByteCount(ext) + 1];
// Encoding.Default.GetBytes(ext, extBytes);
// int fontChars = 0;
// unsafe
// {
// fixed (byte* extP = extBytes)
// {
// fixed (byte* bufferP = font.Buffer)
// {
// fontRay = Raylib.LoadFontFromMemory((sbyte*)extP, bufferP, (int)font.BufferSize, font.Size, null, 95);
// }
// }
// }
var fontRay = Raylib.LoadFont(font.Path);
Raylib.SetTextureFilter(fontRay.texture, TextureFilter.TEXTURE_FILTER_BILINEAR);
_fontPool.Add(fontRay);
return _fontPool.Count - 1;
}
public override void DrawTexture(int id, Color tint)
{
Raylib.DrawTextureV(_texturePool[id], _position, DaggerColorToRaylibColor(tint));
@@ -154,7 +184,14 @@ namespace DaggerFramework.Rendering
return new Raylib_cs.Color { r = (byte)Math.Round(color.R * 255f), g = (byte)Math.Round(color.G * 255f), b = (byte)Math.Round(color.B * 255f), a = (byte)Math.Round(color.A * 255f) };
}
private List<Texture2D> _texturePool = new List<Texture2D>();
public override void DrawText(int fontId, string text, int fontSize, Color color)
{
var font = _fontPool[fontId];
Raylib.DrawTextPro(font, text, _position, Vector2.Zero, _rotation, fontSize, 0.0f, DaggerColorToRaylibColor(color));
}
private List<Texture2D> _texturePool = new();
private List<Raylib_cs.Font> _fontPool = new();
private Vector2 _position;
private float _rotation;
private Vector2 _windowSize;