Moved display functions to display.h/.c.

This commit is contained in:
Ulysse Cura 2026-08-03 23:29:27 +02:00
parent 7f66cb4172
commit 449bf60160
4 changed files with 43 additions and 18 deletions

View File

@ -313,18 +313,3 @@ texture_t *asset_manager_get_texture(asset_manager_t *asset_manager, const char
return asset->data.texture;
}
int asset_manager_draw_texture(texture_t *texture, rect_t *src_rect, rect_t *dst_rect, bool flip)
{
frect_t src_frect, dst_frect;
rect_to_frect(src_rect, &src_frect);
rect_to_frect(dst_rect, &dst_frect);
if(!SDL_RenderTextureRotated(renderer, texture, &src_frect, &dst_frect, 0, NULL, flip))
{
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -2,6 +2,7 @@
#include <SDL3/SDL.h>
#include <stdlib.h>
#include "asset_manager.h"
#include "errors.h"
SDL_Window *window = NULL;
@ -44,11 +45,15 @@ inline int display_init(void)
if(!SDL_SetRenderScale(renderer, RENDER_SCALE, RENDER_SCALE))
{
error_printf("Failed to set renderer logical presentation : %s", SDL_GetError());
error_printf("Failed to set renderer scale presentation : %s", SDL_GetError());
return EXIT_FAILURE;
}
SDL_SetDefaultTextureScaleMode(renderer, SDL_SCALEMODE_PIXELART);
if(!SDL_SetDefaultTextureScaleMode(renderer, SDL_SCALEMODE_PIXELART))
{
error_printf("Failed to set default texture scale mode : %s", SDL_GetError());
return EXIT_FAILURE;
}
debug_printf("Initialized display.");
return EXIT_SUCCESS;
@ -84,3 +89,35 @@ inline void display_update(void)
{
SDL_RenderPresent(renderer);
}
int display_draw_texture(texture_t *texture, rect_t *src_rect, rect_t *dst_rect, bool flip)
{
frect_t src_frect, dst_frect;
rect_to_frect(src_rect, &src_frect);
rect_to_frect(dst_rect, &dst_frect);
if(!SDL_RenderTextureRotated(renderer, texture, &src_frect, &dst_frect, 0, NULL, flip))
{
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int display_draw_frect(frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
{
if(!SDL_SetRenderDrawColor(renderer, r, g, b, a))
{
error_printf("Failed to change renderer draw color : %s", SDL_GetError());
return EXIT_FAILURE;
}
if(!SDL_RenderRect(renderer, frect))
{
error_printf("Failed to draw rectangle to renderer : %s", SDL_GetError());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -50,6 +50,5 @@ int asset_manager_load_asset(asset_manager_t *asset_manager, const char *asset_n
int asset_manager_let_go_asset(asset_manager_t *asset_manager, const char *asset_name);
texture_t *asset_manager_get_texture(asset_manager_t *asset_manager, const char *asset_name);
int asset_manager_draw_texture(texture_t *texture, rect_t *src_rect, rect_t *dst_rect, bool flip);
#endif // ASSET_MANAGER_H

View File

@ -2,6 +2,8 @@
#define DISPLAY_H
#include <SDL3/SDL_render.h>
#include <stdlib.h>
#include "asset_manager.h"
#define C_BLACK 0, 0, 0, 255
#define C_RED 255, 0, 0, 255
@ -25,5 +27,7 @@ void display_exit(void);
int display_clear(void);
void display_update(void);
int display_draw_texture(texture_t *texture, rect_t *src_rect, rect_t *dst_rect, bool flip);
int display_draw_frect(frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a);
#endif // DISPLAY_H