#include "texture.h" #include #include "asset_manager.h" #include "game.h" #include "display.h" #include "utils.h" #include "errors.h" texture_t *load_texture(void) { uint16_t width, height; if(file_read(&width, sizeof(width), 1, game.asset_manager.asset_file)) return_failure_ptr; if(file_read(&height, sizeof(height), 1, game.asset_manager.asset_file)) return_failure_ptr; texture_t *texture = image_alloc(width, height, IMAGE_RGB565A); if(!texture) { error_printf("Failed to create texture."); return NULL; } for(uint16_t line = 0; line < height; line++) { if(file_read(&((uint8_t *)texture->data)[line * texture->stride], sizeof(uint16_t), width, game.asset_manager.asset_file)) goto_failure; } return texture; failure: image_free(texture); return NULL; } void destroy_texture(texture_t *texture) { image_free(texture); }