Update TestGame, load fonts from memory.
This commit is contained in:
@@ -143,35 +143,6 @@ 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));
|
||||
@@ -233,10 +204,15 @@ 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) };
|
||||
}
|
||||
|
||||
public override void DrawText(int fontId, string text, int fontSize, Color color)
|
||||
public override void DrawText(Font font, string text, Color color)
|
||||
{
|
||||
var font = _fontPool[fontId];
|
||||
Raylib.DrawTextPro(font, text, _position, Vector2.Zero, _rotation, fontSize, 0.0f, DaggerColorToRaylibColor(color));
|
||||
if (font.FontHandle == -1)
|
||||
{
|
||||
LoadFont(font);
|
||||
}
|
||||
|
||||
var rayFont = _fontPool[font.FontHandle];
|
||||
Raylib.DrawTextPro(rayFont, text, _position, Vector2.Zero, _rotation, font.Size, 0.0f, DaggerColorToRaylibColor(color));
|
||||
}
|
||||
|
||||
protected override int GetMonitorWidth(int monitorId)
|
||||
@@ -254,6 +230,33 @@ namespace DaggerFramework.Rendering
|
||||
return Raylib.GetCurrentMonitor();
|
||||
}
|
||||
|
||||
private unsafe void LoadFont(Font font)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Raylib.SetTextureFilter(fontRay.texture, TextureFilter.TEXTURE_FILTER_TRILINEAR);
|
||||
|
||||
_fontPool.Add(fontRay);
|
||||
|
||||
font.FontHandle = _fontPool.Count - 1;
|
||||
}
|
||||
|
||||
|
||||
private List<Texture2D> _texturePool = new();
|
||||
private List<Raylib_cs.Font> _fontPool = new();
|
||||
|
||||
@@ -86,8 +86,6 @@ namespace DaggerFramework.Rendering
|
||||
/// <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>
|
||||
@@ -128,7 +126,7 @@ namespace DaggerFramework.Rendering
|
||||
/// <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);
|
||||
public abstract void DrawText(Font font, string text, Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the texture.
|
||||
|
||||
@@ -161,16 +161,6 @@ 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();
|
||||
}
|
||||
|
||||
public override void BeginCamera2d(Vector2 offset, Vector2 target, float rotation, float zoom)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -201,6 +191,12 @@ namespace DaggerFramework.Rendering
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user