diff --git a/include/glerminal.h b/include/glerminal.h index 4ff3ee2..0df93c0 100644 --- a/include/glerminal.h +++ b/include/glerminal.h @@ -68,7 +68,7 @@ void glerminal_layer_scale(unsigned char layer, float scale); * @brief Load sprites from a png file * @param filename Name of the png file */ -void glerminal_load_sprites_file(const char* filename); +int glerminal_load_sprites_file(const char* filename); /** * @brief Load sprites from memory @@ -76,7 +76,7 @@ void glerminal_load_sprites_file(const char* filename); * @param height height of the atlas in sprites * @param buffer the in-memory atlas */ -void glerminal_load_sprites_buffer(unsigned char width, unsigned char height, const unsigned int* buffer); +int glerminal_load_sprites_buffer(unsigned char width, unsigned char height, const unsigned int* buffer); #ifdef __cplusplus } diff --git a/source/glerminal.cpp b/source/glerminal.cpp index 1f44bc3..370bdc9 100644 --- a/source/glerminal.cpp +++ b/source/glerminal.cpp @@ -815,29 +815,41 @@ void glerminal_layer_scale(unsigned char layer, float scale) GLERMINAL_G->layer_scale(layer, scale); } -void glerminal_load_sprites_file(const char* filename) +int glerminal_load_sprites_file(const char* filename) { - if (!GLERMINAL_G) { return; } + if (!GLERMINAL_G) { return false; } + + bool success = false; int w, h; stbi_uc* const buffer = stbi_load(filename, &w, &h, nullptr, 4); // verify atlas size is a multiple of CELL_SIZE in each dimension - if (w % glerminal::CELL_SIZE == 0 && h % glerminal::CELL_SIZE == 0) + if (buffer && w % glerminal::CELL_SIZE == 0 && h % glerminal::CELL_SIZE == 0) { GLERMINAL_G->load_atlas(w / glerminal::CELL_SIZE, h / glerminal::CELL_SIZE, reinterpret_cast(buffer)); + + success = true; } stbi_image_free(buffer); + + return success; } -void glerminal_load_sprites_buffer(unsigned char width, unsigned char height, const unsigned int* buffer) +int glerminal_load_sprites_buffer(unsigned char width, unsigned char height, const unsigned int* buffer) { - if (!GLERMINAL_G) { return; } + if (!GLERMINAL_G) { return false; } // verify atlas size is a multiple of CELL_SIZE in each dimension if (width % glerminal::CELL_SIZE == 0 && height % glerminal::CELL_SIZE == 0) { GLERMINAL_G->load_atlas(width / glerminal::CELL_SIZE, height / glerminal::CELL_SIZE, buffer); + + return true; + } + else + { + return false; } } \ No newline at end of file diff --git a/tests/basic.cpp b/tests/basic.cpp index d5269c6..9322eee 100644 --- a/tests/basic.cpp +++ b/tests/basic.cpp @@ -2,11 +2,16 @@ #include +#include + namespace { void init() { - glerminal_load_sprites_file("resources/image.png"); + if (!glerminal_load_sprites_file("resources/image.png")) + { + std::cout << "Failed to load texture" << std::endl; + } for (int i = 0; i < GRID_HEIGHT; i++) {