59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
#ifndef RENDERER_H
|
|
#define RENDERER_H
|
|
|
|
#include "SDL.h"
|
|
#include "SDL_render.h"
|
|
#include "SDL_surface.h"
|
|
#include "SDL_video.h"
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // !__cplusplus
|
|
|
|
typedef struct renderer Renderer;
|
|
|
|
/**
|
|
* Attempts to allocate a Renderer object on the heap.
|
|
*
|
|
* Returns the pointer to the object when it succeeds, or NULL if it fails.
|
|
*/
|
|
Renderer *create_renderer(SDL_Window *window);
|
|
|
|
/**
|
|
* Returns the valid drawable area that the renderer can use.
|
|
*
|
|
* Useful when rendering on screens that support high DPI since the drawable
|
|
* area is usually bigger than the user-defined size.
|
|
*/
|
|
void get_render_output_size(Renderer *renderer, int32_t *w, int32_t *h);
|
|
|
|
void render_clear(const Renderer *renderer, SDL_Color color);
|
|
void fill_rect(const Renderer *renderer, SDL_Color color, float x, float y,
|
|
float w, float h);
|
|
void render_surface(const Renderer *renderer, SDL_Surface *surface, float x,
|
|
float y, float w, float h);
|
|
void render_texture(const Renderer *renderer, SDL_Texture *texture, float x,
|
|
float y, float w, float h);
|
|
void swap_buffers(const Renderer *renderer);
|
|
|
|
/**
|
|
* Attempts to load an SDL_Texture from a file path.
|
|
*
|
|
* Returns a pointer to the object if it succeeds or NULL when it fails.
|
|
*/
|
|
SDL_Texture *load_texture(const Renderer *renderer, const char *path);
|
|
|
|
/**
|
|
* Frees the memory allocated to the Renderer object and performs the
|
|
* necessary cleanup.
|
|
*/
|
|
void destroy_renderer(Renderer **renderer);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif // !__cplusplus
|
|
|
|
#endif // !RENDERER_H
|