A few patches

This commit is contained in:
2023-01-20 22:51:21 +01:00
parent 8d62c17715
commit 2d62bfc599
5 changed files with 40 additions and 10 deletions
+14 -4
View File
@@ -1,3 +1,5 @@
#include <SDL2/SDL_error.h>
#include <unistd.h>
#include "text.h"
#include <SDL2/SDL_log.h>
@@ -20,7 +22,11 @@ void text_freeFontCache(void){
}
}
int text_renderText(RenderObject_t* renderObject, Position position, SDL_Color color, const char* fontFilename, int fontSize, char* format, ...){
int text_renderText(RenderObject_t* renderObject, float x, float y, int z, SDL_Color color, const char* fontFilename, int fontSize, char* format, ...){
if(access(fontFilename, F_OK) != 0) {
fprintf(stderr, "Font file not found: %s\n", fontFilename);
return -1;
}
TTF_Font* font = NULL;
for(unsigned i = 0; i < fontCacheSize; ++i){
@@ -33,6 +39,7 @@ int text_renderText(RenderObject_t* renderObject, Position position, SDL_Color c
font = TTF_OpenFont(fontFilename, fontSize);
if(font == NULL) {
SDL_LogError(SDL_LOG_PRIORITY_ERROR, "TTF_OpenFont");
fprintf(stderr, "Error while opening font: %s\n", SDL_GetError());
return -1;
}
FontCacheObject_t fontCacheObject;
@@ -56,9 +63,12 @@ int text_renderText(RenderObject_t* renderObject, Position position, SDL_Color c
SDL_Surface* surface = TTF_RenderText_Blended(font, text, color);
renderObject->x = position.x;
renderObject->y = position.y;
renderObject->z = position.z;
renderObject->x = x;
renderObject->y = y;
renderObject->z = z;
renderObject->width = strlen(text) * fontSize;
renderObject->height = fontSize;
renderObject->angle_degre = 0;
renderObject->surface = surface;
return 0;