Upgrade Raylib_cs to latest version, use safe version of LoadFontFromMemory in Raylib.

This commit is contained in:
2024-10-21 18:08:04 +02:00
parent 20036be50f
commit 503473c6b3
2 changed files with 21 additions and 31 deletions

View File

@@ -39,10 +39,10 @@ namespace Voile.Rendering
ConfigFlags flags = 0;
// MSAA
flags |= settings.Msaa == Msaa.Msaa4x ? ConfigFlags.FLAG_MSAA_4X_HINT : 0;
flags |= settings.Msaa == Msaa.Msaa4x ? ConfigFlags.Msaa4xHint : 0;
// VSync
flags |= settings.UseVSync ? ConfigFlags.FLAG_VSYNC_HINT : 0;
flags |= settings.UseVSync ? ConfigFlags.VSyncHint : 0;
_fullscreen = settings.Fullscreen;
@@ -59,13 +59,13 @@ namespace Voile.Rendering
public override void CreateWindow(WindowSettings windowSettings)
{
Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
Raylib.SetTraceLogLevel(TraceLogLevel.None);
_defaultWindowSettings = windowSettings;
_windowSize = windowSettings.Size;
ConfigFlags windowFlags = 0;
windowFlags |= windowSettings.Resizable ? ConfigFlags.FLAG_WINDOW_RESIZABLE : 0;
windowFlags |= windowSettings.Resizable ? ConfigFlags.ResizableWindow : 0;
_windowTitle = windowSettings.Title;
@@ -180,10 +180,10 @@ namespace Voile.Rendering
{
Raylib.DrawRectanglePro(new Rectangle()
{
x = transformPosition.X,
y = transformPosition.Y,
width = size.X,
height = size.Y
X = transformPosition.X,
Y = transformPosition.Y,
Width = size.X,
Height = size.Y
}, transformPivot, transformRotation, VoileColorToRaylibColor(color));
}
@@ -252,28 +252,17 @@ namespace Voile.Rendering
return Raylib.GetCurrentMonitor();
}
private unsafe void LoadFont(Font font)
private void LoadFont(Font font)
{
Raylib_cs.Font fontRay;
ReadOnlySpan<char> ext = ".ttf"; // TODO: don't use a hardcoded extension.
Span<byte> extBytes = new byte[Encoding.Default.GetByteCount(ext) + 1];
Encoding.Default.GetBytes(ext, extBytes);
int fontChars = 2048; // TODO: control this dynamically to not load the entire font.
string ext = ".ttf"; // TODO: don't use a hardcoded extension.
int fontChars = 250; // TODO: control this dynamically to not load the entire font.
unsafe
{
fixed (byte* extP = extBytes)
{
fixed (byte* bufferP = font.Buffer)
{
fontRay = Raylib.LoadFontFromMemory((sbyte*)extP, bufferP, (int)font.BufferSize, font.Size, null, fontChars);
}
}
}
fontRay = Raylib.LoadFontFromMemory(ext, font.Buffer, font.Size, null, fontChars);
Raylib.GenTextureMipmaps(ref fontRay.texture);
Raylib.SetTextureFilter(fontRay.texture, TextureFilter.TEXTURE_FILTER_BILINEAR);
Raylib.GenTextureMipmaps(ref fontRay.Texture);
Raylib.SetTextureFilter(fontRay.Texture, TextureFilter.Bilinear);
_fontPool.Add(fontRay);
@@ -288,14 +277,15 @@ namespace Voile.Rendering
{
fixed (void* dataPtr = texture.Buffer)
{
image.data = dataPtr;
image.Data = dataPtr;
}
}
image.width = texture.Width;
image.height = texture.Height;
image.mipmaps = texture.Mipmaps;
image.format = (PixelFormat)texture.Format;
image.Width = texture.Width;
image.Height = texture.Height;
image.Mipmaps = texture.Mipmaps;
image.Format = (PixelFormat)texture.Format;
Texture2D rayTexture;

View File

@@ -15,7 +15,7 @@
<PackageReference Include="Tommy" Version="3.1.2" />
<PackageReference Include="Voile.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="Raylib-cs" Version="6.1.1" />
<PackageReference Include="SharpFont" Version="4.0.1" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
<PackageReference Include="StbImageSharp" Version="2.27.13" />