Update logging to also print to stdout + replace printf to logging.

This commit is contained in:
2024-10-15 01:36:02 +08:00
parent 988bc52e57
commit f9cf93eaee
6 changed files with 53 additions and 38 deletions
+6 -5
View File
@@ -1,4 +1,5 @@
#include "texture.h"
#include "log.h"
int text_texture_init(text_texture* text_texture, SDL_Renderer* renderer)
{
@@ -6,7 +7,7 @@ int text_texture_init(text_texture* text_texture, SDL_Renderer* renderer)
text_texture->renderer = renderer;
text_texture->font = TTF_OpenFont("FiraCode-Regular.ttf", 24);
if (!text_texture->font) {
printf("Failed to load font! TTF_Error: %s\n", TTF_GetError());
log_message(LOG_ERROR, "Failed to load font! TTF_Error: %s", TTF_GetError());
return 0;
}
text_texture->width = 0;
@@ -24,13 +25,13 @@ int text_texture_load(text_texture* text_texture, char* string)
SDL_Color text_color = { 255, 255, 255 };
SDL_Surface* text_surface = TTF_RenderText_Solid(text_texture->font, string, text_color);
if (!text_surface) {
printf("Unable to render text surface! TTF_Error: %s\n", TTF_GetError());
log_message(LOG_ERROR, "Unable to render text surface! TTF_Error: %s", TTF_GetError());
return 0;
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(text_texture->renderer, text_surface);
if (!texture) {
printf("Unable to create texture from rendered text! SDL_Error: %s\n", SDL_GetError());
log_message(LOG_ERROR, "Unable to create texture from rendered text! SDL_Error: %s", SDL_GetError());
return 0;
}
@@ -45,11 +46,11 @@ int text_texture_load(text_texture* text_texture, char* string)
int text_texture_render(text_texture* text_texture, int x, int y)
{
if (!text_texture) {
printf("text_texture uninitialized");
log_message(LOG_ERROR, "text_texture uninitialized");
return 0;
}
if (!text_texture->texture) {
printf("text_texture->texture uninitialized");
log_message(LOG_ERROR, "text_texture->texture uninitialized");
return 0;
}