forked from tas/major_tom
47 lines
1.5 KiB
C
47 lines
1.5 KiB
C
#ifndef JNR_RENDERER_H
|
|
#define JNR_RENDERER_H
|
|
|
|
#include <SDL2/SDL.h>
|
|
#include <stdbool.h>
|
|
#include "config.h"
|
|
#include "util/vec2.h"
|
|
|
|
/* Forward declaration */
|
|
typedef struct Camera Camera;
|
|
|
|
typedef enum DrawLayer {
|
|
LAYER_BG_FAR, /* parallax background - far */
|
|
LAYER_BG_NEAR, /* parallax background - near */
|
|
LAYER_TILES_BG, /* tile background layer */
|
|
LAYER_ENTITIES, /* players, enemies, items */
|
|
LAYER_TILES_FG, /* tile foreground layer */
|
|
LAYER_PARTICLES, /* effects */
|
|
LAYER_HUD, /* UI overlay (screen-space) */
|
|
LAYER_COUNT
|
|
} DrawLayer;
|
|
|
|
typedef struct Sprite {
|
|
SDL_Texture *texture;
|
|
SDL_Rect src; /* source rect in spritesheet */
|
|
Vec2 pos; /* world position (top-left) */
|
|
Vec2 size; /* render size in world pixels */
|
|
bool flip_x;
|
|
bool flip_y;
|
|
DrawLayer layer;
|
|
uint8_t alpha; /* 0-255 */
|
|
double rotation; /* degrees, clockwise */
|
|
} Sprite;
|
|
|
|
void renderer_init(SDL_Renderer *r);
|
|
void renderer_set_clear_color(SDL_Color color);
|
|
void renderer_clear(void);
|
|
void renderer_submit(const Sprite *sprite);
|
|
void renderer_flush(const Camera *cam);
|
|
void renderer_present(void);
|
|
void renderer_shutdown(void);
|
|
|
|
/* Convenience: draw a filled rect (debug / HUD) */
|
|
void renderer_draw_rect(Vec2 pos, Vec2 size, SDL_Color color, DrawLayer layer, const Camera *cam);
|
|
|
|
#endif /* JNR_RENDERER_H */
|