WIP: fonts.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -71,6 +71,9 @@ namespace DaggerFramework.Rendering
|
||||
/// <param name="texture">Texture to load.</param>
|
||||
/// <returns>A texture handler on the GPU.</returns>
|
||||
public abstract int LoadTexture(Texture2d texture);
|
||||
|
||||
public abstract int LoadFont(Font font);
|
||||
|
||||
/// <summary>
|
||||
/// Sets transforms for the next draw operation.
|
||||
/// </summary>
|
||||
@@ -109,6 +112,9 @@ namespace DaggerFramework.Rendering
|
||||
/// <param name="fontSize">Size of the font.</param>
|
||||
/// <param name="color">Color of the text.</param>
|
||||
public abstract void DrawSdfText(string text, int fontSize, Color color);
|
||||
|
||||
public abstract void DrawText(int fontId, string text, int fontSize, Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the texture.
|
||||
/// </summary>
|
||||
|
||||
@@ -156,6 +156,16 @@ namespace DaggerFramework.Rendering
|
||||
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;
|
||||
Reference in New Issue
Block a user