help / color / mirror / Atom feed
From: Troy Jacobs <>
Subject: Struggling to use fonts in SDLAda
Date: Mon, 12 Sep 2022 15:43:56 -0700 (PDT)	[thread overview]
Message-ID: <> (raw)

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;


    if SDL.Initialise = True and then SDL.TTFs.Initialise = True then

    Ada.Text_IO.Put_Line("Ada directory:");


    Ada.Text_IO.Put_Line("SDL2 directory:");



    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);


    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)





    end loop;





    end if;

    end Coolgame1;


    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:


    SDL2 directory:


    raised SDL.TTFS.TTF_ERROR : Couldn't load font file


    0x7ff69aff0089 ??? at ???


    0x7ff69afeffbb ??? at ???


    0x7ff69afebf10 ??? at ???


    0x7ff69affffe9 ??? at ???


    0x7ff69af9143d ??? at ???


    0x7ff69af91144 ??? at ???





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.

             reply	other threads:[~2022-09-12 22:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 22:43 Troy Jacobs [this message]
2022-09-13  9:52 ` Struggling to use fonts in SDLAda Troy Jacobs
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox