Improved text rendering and fixed a bug with the texture rendering
This commit is contained in:
1 parent
4659a4cd49
commit
8a4697e121
4 files changed
+44
-8
No files matched your search
+24
-4
@@ -10,6 +10,7 @@
|
||||
#include "SDL_mixer.h"
|
||||
#include "SDL_pixels.h"
|
||||
#include "SDL_platform.h"
|
||||
#include "SDL_rect.h"
|
||||
#include "SDL_render.h"
|
||||
#include "SDL_surface.h"
|
||||
#include "SDL_timer.h"
|
||||
@@ -322,8 +323,25 @@ void render_texture_asset(AssetID id, RenderRect *src, RenderRect *dest) {
|
||||
render_texture(GameEngine.window.renderer, texture, src, dest);
|
||||
}
|
||||
|
||||
void render_text_with_font_asset(AssetID id, const char *text, float x,
|
||||
float y) {
|
||||
TextSize get_text_size_from_font_asset(AssetID id, const char *text) {
|
||||
TextSize output = {};
|
||||
|
||||
if (id < 0) {
|
||||
return output;
|
||||
}
|
||||
|
||||
TTF_Font *font = get_font(GameEngine.asset_manager, id);
|
||||
if (!font) {
|
||||
return output;
|
||||
}
|
||||
|
||||
TTF_SizeText(font, text, &(output.width), &(output.height));
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void render_text_with_font_asset(AssetID id, const char *text, float x, float y,
|
||||
SDL_Color color) {
|
||||
if (id < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -333,8 +351,10 @@ void render_text_with_font_asset(AssetID id, const char *text, float x,
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Surface *surface =
|
||||
TTF_RenderText_Solid(font, text, (SDL_Color){0, 0, 0, 255});
|
||||
SDL_Surface *surface = TTF_RenderText_Solid(font, text, color);
|
||||
if (!surface) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the width and height, in pixels, of the text rendered using the font
|
||||
int32_t w = 0;
|
||||
|
||||
Reference in new issue
Block a user