help / color / mirror / Atom feed
* Struggling to use fonts in SDLAda
@ 2022-09-12 22:43 Troy Jacobs
  2022-09-13  9:52 ` Troy Jacobs
  0 siblings, 1 reply; 2+ messages in thread
From: Troy Jacobs @ 2022-09-12 22:43 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Struggling to use fonts in SDLAda
  2022-09-12 22:43 Struggling to use fonts in SDLAda Troy Jacobs
@ 2022-09-13  9:52 ` Troy Jacobs
  0 siblings, 0 replies; 2+ messages in thread
From: Troy Jacobs @ 2022-09-13  9:52 UTC (permalink / raw)

Note: This post was originally posted on r/Ada, but I copied it here when the post I made was removed automatically.  I didn't realized that they block your post before letting it go up (I assume so someone can review it first.)  You may wish to join the  discussion there instead.  Apologies for this.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-13  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12 22:43 Struggling to use fonts in SDLAda Troy Jacobs
2022-09-13  9:52 ` Troy Jacobs

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