WIP: fonts.
This commit is contained in:
@@ -11,14 +11,15 @@
|
||||
<PackageReference Include="DaggerFramework.Fmod" Version="0.2.2.8" />
|
||||
<PackageReference Include="ImGui.NET" Version="1.89.4" />
|
||||
<PackageReference Include="Raylib-cs" Version="4.2.0.1" />
|
||||
<PackageReference Include="SharpFont" Version="4.0.1" />
|
||||
<PackageReference Include="Silk.NET" Version="2.17.0" />
|
||||
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
|
||||
<PackageReference Include="StbImageSharp" Version="2.27.13" />
|
||||
<PackageReference Include="StbVorbisSharp" Version="1.22.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="BuildFmod" BeforeTargets="BeforeBuild">
|
||||
<MSBuild Projects="../DaggerFramework.Fmod/DaggerFramework.Fmod.csproj"
|
||||
Targets="Restore;Build" />
|
||||
<MSBuild Projects="../DaggerFramework.Fmod/DaggerFramework.Fmod.csproj" Targets="Restore;Build" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -28,7 +28,7 @@ namespace DaggerFramework.Audio
|
||||
channels = 2;
|
||||
}
|
||||
|
||||
var channel = PlaySoundFromBuffer(sound.Path, sound.BufferSize, channels, sound.SampleRate, sound.Buffer, GetChannelGroup(bus));
|
||||
var channel = PlaySoundFromBuffer(sound.Path, (int)sound.BufferSize, channels, sound.SampleRate, sound.Buffer, GetChannelGroup(bus));
|
||||
channel.setVolume(volume);
|
||||
channel.setPitch(pitch);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -4,13 +4,16 @@ public class FontLoader : IResourceLoader
|
||||
{
|
||||
public IEnumerable<string> SupportedExtensions => new string[]
|
||||
{
|
||||
".ttf"
|
||||
"ttf"
|
||||
};
|
||||
|
||||
public Type ResourceType => typeof(Font);
|
||||
|
||||
public Resource Load(string path)
|
||||
{
|
||||
return default;
|
||||
byte[] fileBuffer = File.ReadAllBytes(path);
|
||||
var result = new Font(path, fileBuffer);
|
||||
result.BufferSize = fileBuffer.Length;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace DaggerFramework
|
||||
public string? Path { get => _path; set => _path = value; }
|
||||
public byte[]? Buffer { get => _buffer; set => _buffer = value; }
|
||||
|
||||
public long BufferSize { get; set; }
|
||||
|
||||
public Resource(string path, byte[] buffer)
|
||||
{
|
||||
_path = path;
|
||||
|
||||
@@ -102,7 +102,8 @@ namespace DaggerFramework.Resources
|
||||
private readonly Dictionary<Type, IResourceLoader> _resourceLoaderAssociations = new()
|
||||
{
|
||||
{typeof(Sound), new SoundLoader()},
|
||||
{typeof(Texture2d), new Texture2dLoader()}
|
||||
{typeof(Texture2d), new Texture2dLoader()},
|
||||
{typeof(Font), new FontLoader()}
|
||||
};
|
||||
|
||||
private Dictionary<string, Resource> _loadedResources = new();
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace DaggerFramework
|
||||
{
|
||||
public SoundFormat Format { get; set; }
|
||||
public int SampleRate { get; set; }
|
||||
public int BufferSize { get; set; }
|
||||
|
||||
public Sound(string path, byte[] buffer) : base(path, buffer)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user