I am trying to make a little game for practice in C++
. I am using the Clion
IDEA which uses CMake
for it's build system.
So I have this project set up which uses the Allegro
game library and I can get it working fine for now with me CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(my-game)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
# Set executeable
add_executable(game ${SOURCE_FILES})
#Include Allegro
include_directories(/usr/include/allegro5/)
link_directories(/usr/include/allegro5/)
#connect all the libraries you need
set(game_LIBS
liballegro.so
liballegro_dialog.so
liballegro_image.so
liballegro_font.so
liballegro_ttf.so
)
target_link_libraries(game ${game_LIBS})
Now the problem is that in my project root folder I have this folder called assets
and inside of it I would like to store my assets. For now there is a fonts
folder in there which contains a arial.ttf
file which I would like to use to display some text in my game.
Now the line I would use to get this asset and use it in my application should be something similar:
ALLEGRO_FONT *font24 = al_load_ttf_font("/assets/fonts/arial.ttf", 24, 0);
But for some reason when I launch the application and I start to use that font24
pointer, I get this error:
game: /build/buildd/allegro5-5.0.10/addons/font/text.c:77: al_draw_ustr: Assertion `font' failed.
Now if I use this line instead:
ALLEGRO_FONT *font24 = al_load_ttf_font("/home/kaspar/Documents/Coding-projects/ClionProjects/my-game/assets/fonts/arial.ttf", 24, 0);
Then the application will be able to print the text with the desired font just fine.
So what must I do so that I would be able to reference my assets in the project more easily? I imagine that pointing to a file with it's full system path is not really a healthy practice..