124 lines
3.7 KiB
C
124 lines
3.7 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <string.h>
|
||
|
|
#include <SDL3/SDL.h>
|
||
|
|
|
||
|
|
#include "pxl8_types.h"
|
||
|
|
#include "pxl8_blit.h"
|
||
|
|
|
||
|
|
typedef struct pxl8_atlas_entry {
|
||
|
|
char path[256];
|
||
|
|
u32 sprite_id;
|
||
|
|
i32 x, y, w, h;
|
||
|
|
} pxl8_atlas_entry;
|
||
|
|
|
||
|
|
typedef struct pxl8_gfx_ctx {
|
||
|
|
SDL_Renderer* renderer;
|
||
|
|
SDL_Texture* framebuffer_texture;
|
||
|
|
SDL_Texture* sprite_atlas_texture;
|
||
|
|
SDL_Window* window;
|
||
|
|
|
||
|
|
u8* framebuffer;
|
||
|
|
u32* palette;
|
||
|
|
u32 palette_size;
|
||
|
|
|
||
|
|
i32 framebuffer_width;
|
||
|
|
i32 framebuffer_height;
|
||
|
|
pxl8_color_mode color_mode;
|
||
|
|
|
||
|
|
u32 sprite_atlas_width;
|
||
|
|
u32 sprite_atlas_height;
|
||
|
|
u32 sprite_frame_width;
|
||
|
|
u32 sprite_frame_height;
|
||
|
|
u32 sprite_frames_per_row;
|
||
|
|
|
||
|
|
pxl8_atlas_entry* atlas_entries;
|
||
|
|
u32 atlas_entries_len;
|
||
|
|
u32 atlas_entries_cap;
|
||
|
|
|
||
|
|
u8* atlas;
|
||
|
|
bool atlas_dirty;
|
||
|
|
|
||
|
|
i32 viewport_x, viewport_y;
|
||
|
|
i32 viewport_width, viewport_height;
|
||
|
|
|
||
|
|
bool initialized;
|
||
|
|
} pxl8_gfx_ctx;
|
||
|
|
|
||
|
|
typedef enum pxl8_blend_mode {
|
||
|
|
PXL8_BLEND_NONE,
|
||
|
|
PXL8_BLEND_ALPHA,
|
||
|
|
PXL8_BLEND_ADD,
|
||
|
|
PXL8_BLEND_MULTIPLY
|
||
|
|
} pxl8_blend_mode;
|
||
|
|
|
||
|
|
typedef struct pxl8_palette_cycle {
|
||
|
|
u8 start_index;
|
||
|
|
u8 end_index;
|
||
|
|
f32 speed;
|
||
|
|
f32 timer;
|
||
|
|
bool active;
|
||
|
|
} pxl8_palette_cycle;
|
||
|
|
|
||
|
|
typedef struct pxl8_scanline_effect {
|
||
|
|
void (*process)(pxl8_gfx_ctx* ctx, i32 line, f32 time);
|
||
|
|
bool active;
|
||
|
|
} pxl8_scanline_effect;
|
||
|
|
|
||
|
|
typedef struct pxl8_mode7_params {
|
||
|
|
f32 horizon;
|
||
|
|
f32 scale_x, scale_y;
|
||
|
|
f32 rotation;
|
||
|
|
f32 offset_x, offset_y;
|
||
|
|
bool active;
|
||
|
|
} pxl8_mode7_params;
|
||
|
|
|
||
|
|
typedef struct pxl8_effects {
|
||
|
|
pxl8_palette_cycle palette_cycles[8];
|
||
|
|
pxl8_scanline_effect scanline_effects[4];
|
||
|
|
|
||
|
|
f32 time;
|
||
|
|
} pxl8_effects;
|
||
|
|
|
||
|
|
pxl8_result pxl8_gfx_init(
|
||
|
|
pxl8_gfx_ctx* ctx,
|
||
|
|
pxl8_color_mode mode,
|
||
|
|
pxl8_resolution resolution,
|
||
|
|
const char* title,
|
||
|
|
i32 window_width,
|
||
|
|
i32 window_height
|
||
|
|
);
|
||
|
|
|
||
|
|
void pxl8_gfx_shutdown(pxl8_gfx_ctx* ctx);
|
||
|
|
|
||
|
|
pxl8_result pxl8_gfx_init_atlas(pxl8_gfx_ctx* ctx, u32 width, u32 height);
|
||
|
|
pxl8_result pxl8_gfx_load_sprite(pxl8_gfx_ctx* ctx, const char* path);
|
||
|
|
pxl8_result pxl8_gfx_load_palette(pxl8_gfx_ctx* ctx, const char* path);
|
||
|
|
pxl8_result pxl8_gfx_load_font_atlas(pxl8_gfx_ctx* ctx);
|
||
|
|
|
||
|
|
void pxl8_gfx_get_resolution_dimensions(pxl8_resolution resolution, i32* width, i32* height);
|
||
|
|
void pxl8_gfx_upload_framebuffer(pxl8_gfx_ctx* ctx);
|
||
|
|
void pxl8_gfx_upload_atlas(pxl8_gfx_ctx* ctx);
|
||
|
|
void pxl8_gfx_present(pxl8_gfx_ctx* ctx);
|
||
|
|
|
||
|
|
void pxl8_gfx_viewport(pxl8_gfx_ctx* ctx, i32 x, i32 y, i32 width, i32 height);
|
||
|
|
void pxl8_gfx_project(pxl8_gfx_ctx* ctx, f32 left, f32 right, f32 top, f32 bottom);
|
||
|
|
|
||
|
|
void pxl8_clr(pxl8_gfx_ctx* ctx, u32 color);
|
||
|
|
void pxl8_pixel(pxl8_gfx_ctx* ctx, i32 x, i32 y, u32 color);
|
||
|
|
u32 pxl8_get_pixel(pxl8_gfx_ctx* ctx, i32 x, i32 y);
|
||
|
|
void pxl8_line(pxl8_gfx_ctx* ctx, i32 x0, i32 y0, i32 x1, i32 y1, u32 color);
|
||
|
|
void pxl8_rect(pxl8_gfx_ctx* ctx, i32 x, i32 y, i32 w, i32 h, u32 color);
|
||
|
|
void pxl8_rect_fill(pxl8_gfx_ctx* ctx, i32 x, i32 y, i32 w, i32 h, u32 color);
|
||
|
|
void pxl8_circle(pxl8_gfx_ctx* ctx, i32 cx, i32 cy, i32 radius, u32 color);
|
||
|
|
void pxl8_circle_fill(pxl8_gfx_ctx* ctx, i32 cx, i32 cy, i32 radius, u32 color);
|
||
|
|
void pxl8_text(pxl8_gfx_ctx* ctx, const char* text, i32 x, i32 y, u32 color);
|
||
|
|
void pxl8_sprite(pxl8_gfx_ctx* ctx, u32 sprite_id, i32 x, i32 y, i32 w, i32 h);
|
||
|
|
|
||
|
|
void pxl8_gfx_color_ramp(pxl8_gfx_ctx* ctx, u8 start, u8 count, u32 from_color, u32 to_color);
|
||
|
|
void pxl8_gfx_cycle_palette(pxl8_gfx_ctx* ctx, u8 start, u8 count, i32 step);
|
||
|
|
void pxl8_gfx_fade_palette(pxl8_gfx_ctx* ctx, u8 start, u8 count, f32 amount, u32 target_color);
|
||
|
|
void pxl8_gfx_interpolate_palettes(pxl8_gfx_ctx* ctx, u32* palette1, u32* palette2, u8 start, u8 count, f32 t);
|
||
|
|
void pxl8_gfx_process_effects(pxl8_gfx_ctx* ctx, pxl8_effects* effects, f32 dt);
|
||
|
|
void pxl8_gfx_swap_palette(pxl8_gfx_ctx* ctx, u8 start, u8 count, u32* new_colors);
|