Struggling to use fonts in SDLAda
From
Troy Jacobs@21:1/5 to
All on Mon Sep 12 15:43:56 2022
I'm relatively new to programming with Ada, and as I've been learning the language I decided to try making a simple 2D game with it to apply what I learn about Ada. After unsuccessfully attempting to make my own binding to SDL2, I decided to simply use
the SDLAda package because it seemed well put together.
However, I've been running into this issue while trying to render text where the program fails at runtime because it failed to load the font. I've been desperately scouring the web & my code for a solution ever since to no avail. As I am newish to Ada, I
don't know the GNAT tools well enough to pinpoint what could be causing the problem.
Below is my .gpr file, Ada source file, and the message produced when I try to run it through Alire.
.gpr file:
with "config/coolgame1_config.gpr";
project Coolgame1 is
for Source_Dirs use ("src/", "config/");
for Object_Dir use "obj/" & Coolgame1_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("coolgame1.adb");
package Compiler is
for Default_Switches ("Ada") use Coolgame1_Config.Ada_Compiler_Switches;
end Compiler;
package Linker is
for Default_Switches ("Ada") use ("-lSDL2", "-lSDL2_ttf");
end Linker;
package Binder is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;
package Install is
for Artifacts (".") use ("share");
end Install;
end Coolgame1;
Ada Source File (abridged for clarity:)
with SDL;
with SDL.Video.Renderers.Makers;
with SDL.Video.Textures.Makers;
with SDL.Video.Windows.Makers;
with SDL.Video.Pixel_Formats;
with SDL.Events.Events;
with SDL.Events.Keyboards;
with SDL.TTFs.Makers;
with SDL.Video.Palettes;
with SDL.Video.Surfaces;
with Ada.Directories;
with Ada.Text_IO;
with SDL.Rwops;
procedure Coolgame1 is
window_size : constant SDL.Positive_Sizes := SDL.Positive_Sizes'(800, 600);
window : SDL.Video.Windows.Window;
renderer : SDL.Video.Renderers.Renderer;
texture : SDL.Video.Textures.Texture;
font_path : constant String := "resources/fonts/kunika_2.0/fonts/OpenType-TT/Kunika-Regular.ttf";
font : SDL.TTFs.Fonts;
text_surface : SDL.Video.Surfaces.Surface;
begin
if SDL.Initialise = True and then SDL.TTFs.Initialise = True then
Ada.Text_IO.Put_Line("Ada directory:");
Ada.Text_IO.Put_Line(Ada.Directories.Current_Directory);
Ada.Text_IO.Put_Line("SDL2 directory:");
Ada.Text_IO.Put_Line(SDL.Rwops.Base_Path);
SDL.Video.Windows.Makers.Create(
Win => window,
Title => "HITBOXERS",
Position => SDL.Natural_Coordinates'(X => 300, Y => 300),
Size => window_size,
Flags => SDL.Video.Windows.Resizable
);
SDL.Video.Renderers.Makers.Create(renderer, window);
SDL.Video.Textures.Makers.Create(
Tex => texture,
Renderer => renderer,
Format => SDL.Video.Pixel_Formats.Pixel_Format_ARGB_8888,
Kind => SDL.Video.Textures.Streaming,
Size => window_size
);
-- get font
SDL.TTFs.Makers.Create(font, font_path, 1, 40);
-- create surface for font
text_surface := SDL.TTFs.Render_Shaded(
Self => font,
Text => "Yolo",
Colour => SDL.Video.Palettes.Colour'(Red => 98, Green => 236, Blue => 120, Alpha => 255),
Background_Colour => SDL.Video.Palettes.Colour'(Red => 236, Green => 203, Blue => 98, Alpha => 255)
);
renderer.Clear;
renderer.Copy(texture);
renderer.Present;
end loop;
end;
window.Finalize;
SDL.TTFs.Finalise;
SDL.Finalise;
end if;
end Coolgame1;
Output:
PS C:\Users\usernamehere\coolgame1> alr run
Note: Building coolgame1/coolgame1.gpr...
gprbuild: "coolgame1.exe" up to date
Build finished successfully in 2.09 seconds.
Ada directory:
C:\Users\usernamehere\coolgame1
SDL2 directory:
C:\Users\usernamehere\coolgame1\bin\
raised SDL.TTFS.TTF_ERROR : Couldn't load font file
[C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]
0x7ff69aff0089 ??? at ???
[C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]
0x7ff69afeffbb ??? at ???
[C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]
0x7ff69afebf10 ??? at ???
[C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]
0x7ff69affffe9 ??? at ???
[C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]
0x7ff69af9143d ??? at ???
[C:\Users\usernamehere\coolgame1\bin\coolgame1.exe]
0x7ff69af91144 ??? at ???
[C:\WINDOWS\System32\KERNEL32.DLL]
0x7ffcf2397032
[C:\WINDOWS\SYSTEM32\ntdll.dll]
0x7ffcf384264f
And before you ask, the problem is not the font being in the wrong directory. I've confirmed this by moving the file around and reading the source code for both SDLAda & SDL_ttf.
I'll do my best to respond as much as I possibly can to questions. Thank you to anyone who is able to help.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)