-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_render.h
- DARNIT_RENDER_LOGIC_OP - Set a logic function that is applied when rendering to the framebuffer
- DARNIT_RENDER_SCALE - Set how tilesheets are interpolated when stretched.
- DARNIT_TILESHEET - Functions for handling tilesheets
- DARNIT_TILE - Functions for rendering tiles (quads)
- DARNIT_LINE - Functions for rendering lines
- DARNIT_CIRCLE - Functions for rendering circles
- DARNIT_RECT - Functions for rendering filled solid-color rectangles.
- DARNIT_RENDER - General functions not specific to any special kind of rendering.
Used with d_render_logic_op to wrap glLogicOp.
typedef enum {
DARNIT_RENDER_LOGIC_OP_NONE = 0,
DARNIT_RENDER_LOGIC_OP_AND = 1,
DARNIT_RENDER_LOGIC_OP_NAND = 2,
DARNIT_RENDER_LOGIC_OP_OR = 3,
DARNIT_RENDER_LOGIC_OP_NOR = 4,
DARNIT_RENDER_LOGIC_OP_XOR = 5,
} DARNIT_RENDER_LOGIC_OP;- void d_render_logic_op(DARNIT_RENDER_LOGIC_OP logicop);
Used with d_render_tilesheet_scale_algorithm to change how a tilesheet is interpolated if it's stretched when rendered. Default is DARNIT_SCALE_NEAREST.
typedef enum {
DARNIT_SCALE_NEAREST = 1,
DARNIT_SCALE_LINEAR = 2,
} DARNIT_RENDER_SCALE;A DARNIT_TILESHEET is a texture with a virtual tile grid applied over it. Tilesheets are memory managed, if you load the same tilesheet several time, only one copy is present in memory. While this saves VRAM, it also means that if you apply an animation to it or update a region of it with new pixel data, it affects everything that uses the tilesheet. Changes persists until everything that uses it has been unloaded, then the tilesheet itself is unloaded too.
If a tilesheet is already loaded or not is determined via the path to the image file. So if you overlay a directory with an LDI and then try to load a tilesheet inside the LDI, and it has the same path as an already loaded image, the already loaded one will trigger as the same one.
- DARNIT_TILESHEET *d_render_tilesheet_load(const char *fname, unsigned int wsq, unsigned int hsq, DARNIT_PFORMAT target_format);
- DARNIT_TILESHEET *d_render_tilesheet_isom_load(const char *fname, unsigned int wsq, unsigned int hsq, DARNIT_PFORMAT target_format);
- DARNIT_TILESHEET *d_render_tilesheet_new(int tiles_w, int tiles_h, int tile_w, int tile_h, DARNIT_PFORMAT format);
- DARNIT_TILESHEET *d_render_tilesheet_free(DARNIT_TILESHEET *tilesheet);
- void d_render_tilesheet_update(DARNIT_TILESHEET *tilesheet, int sheet_x, int sheet_y, int change_w, int change_h, void *data);
- void d_render_tilesheet_geometrics(DARNIT_TILESHEET *tilesheet, int *w, int *h, int *tile_w, int *tile_h);
- int d_render_tilesheet_animation_apply(DARNIT_TILESHEET *tilesheet, const char *fname);
- void d_render_tilesheet_animate(DARNIT_TILESHEET *tilesheet);
- void d_render_tilesheet_scale_algorithm(DARNIT_TILESHEET *tilesheet, DARNIT_RENDER_SCALE scaling);
DARNIT_TILE is used to batch-render tiles. They do not have to be all groped together like a tilemap, they can be placed whereever on the screen. All tiles in a DARNIT_TILE has to be using the same tilesheet though.
- void d_render_tile_init(DARNIT_TILE *buf, unsigned int tile, unsigned int tile_ts, int x, int y);
- void d_render_tile_move(DARNIT_TILE *tile_p, unsigned int tile, int x, int y);
- void d_render_tile_tilesheet_coord_set(DARNIT_TILE *tile_p, unsigned int tile, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
- void d_render_tile_size_set(DARNIT_TILE *buf, unsigned int tile, int w, int h);
- void d_render_tile_set(DARNIT_TILE *tile_p, unsigned int tile, unsigned int tile_ts);
- void d_render_tile_tilesheet(DARNIT_TILE *tile_p, DARNIT_TILESHEET *tilesheet);
- void d_render_tile_clear(DARNIT_TILE *tile_p, unsigned int tile);
- void d_render_tile_draw(DARNIT_TILE *tile_p, unsigned int tiles);
- DARNIT_TILE *d_render_tile_new(unsigned int tiles, DARNIT_TILESHEET *tilesheet);
- DARNIT_TILE *d_render_tile_free(DARNIT_TILE *tile_p);
Like DARNIT_TILE, but with lines. No texture mapping or color mapping is done, just while lines. Use d_render_tint to change the color on all the lines in the DARNIT_LINE drawn.
- DARNIT_LINE *d_render_line_new(unsigned int lines, unsigned int line_w);
- void d_render_line_move(DARNIT_LINE *line_p, unsigned int line, int x1, int y1, int x2, int y2);
- void d_render_line_draw(DARNIT_LINE *line_p, int lines);
- void d_render_line_get(DARNIT_LINE *buf, unsigned int line, int *x, int *y, int *x2, int *y2);
- DARNIT_LINE *d_render_line_free(DARNIT_LINE *line_p);
DARNIT_CIRCLE is a special case of DARNIT_LINE in which a bunch on lines are used to apprioximate a circle. No texture or color mapping is done, use d_render_tint to color the circle.
- DARNIT_CIRCLE *d_render_circle_new(unsigned int lines, unsigned int line_w);
- void d_render_circle_move(DARNIT_CIRCLE *circle_p, int x, int y, int radius);
- void d_render_circle_draw(DARNIT_CIRCLE *circle_p);
- DARNIT_CIRCLE *d_render_circle_free(DARNIT_CIRCLE *circle_p);
DARNIT_RECT renders filled rectangles. No texture or color mapping is done, use d_render_tint for coloring the rectangles.
- DARNIT_RECT *d_render_rect_new(unsigned int rects);
- void d_render_rect_move(DARNIT_RECT *rect_p, unsigned int rect, int x1, int y1, int x2, int y2);
- void d_render_rect_draw(DARNIT_RECT *rect_p, int rects);
- void d_render_rect_get(DARNIT_RECT *buf, unsigned int rect, int *x1, int *y1, int *x2, int *y2);
- DARNIT_RECT *d_render_rect_free(DARNIT_RECT *rect_p);
Various rendering functions that are used for pretty much all kinds of rendering.
- void d_render_begin();
- void d_render_end();
- void d_render_blend_enable();
- void d_render_blend_disable();
- void d_render_tint(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
- void d_render_tint_get(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a);
- void d_render_clearcolor_set(unsigned char r, unsigned char g, unsigned char b);
- void d_render_offset(int x, int y);
- void d_render_fade_in(unsigned int time, unsigned char r, unsigned char g, unsigned char b);
- void d_render_fade_out(unsigned int time);
- int d_render_fade_status();
- void d_render_state_restore(); void d_render_tile_blit(void *tilesheet, unsigned int tile, int x, int y);
void d_render_logic_op(DARNIT_RENDER_LOGIC_OP logicop);
Selects a logic operation to use when overwriting pixels in the framebuffer. This is a wrapper of glLogicOp.
Arguments
- logicop - The logic operation to use when overwriting pixels in the framebuffer. See DARNIT_RENDER_LOGIC_OP for a list of logic operations available.
Return value None.
DARNIT_TILESHEET *d_render_tilesheet_load(const char *fname, unsigned int wsq, unsigned int hsq, DARNIT_PFORMAT target_format);
Loads a tilesheet from file. The tilesheet can be an image of any of the supported image formats.
Arguments
- fname - Filename of the tilesheet to load
- wsq - The width of each tile. If a tile on the right side of the tilesheet doesn't fit, it is ignored.
- hsq - The height of each tile. If a row of tile doesn't fit at the very bottom, it is ignored.
- target_format - Downsamples the image to the selected bit depth. A 16 bpp format is recommended as they're faster on limited systems.
Return value
Returns NULL on failure. Anything else is a valid DARNIT_TILESHEET.
DARNIT_TILESHEET *d_render_tilesheet_isom_load(const char *fname, unsigned int wsq, unsigned int hsq, DARNIT_PFORMAT target_format);
Loads a tilesheet from file. The tilesheet can be an image of any of the supported image formats. This funnction differs from d_render_tilesheet_load in the way that the tiles are trimmed from the top until a pixel that isn't completely transparent is found. This makes for more efficient rendering when drawing isometric maps as the amount of unrendered pixels are reduced. This makes a difference on low-bandwidth systems.
Arguments
- fname - Filename of the tilesheet to load
- wsq - The width of each tile. If a tile on the right side of the tilesheet doesn't fit, it is ignored.
- hsq - The height of each tile. If a row of tile doesn't fit at the very bottom, it is ignored.
- target_format - Downsamples the image to the selected bit depth. A 16 bpp format is recommended as they're faster on limited systems.
Return value
Returns NULL on failure. Anything else is a valid DARNIT_TILESHEET.
DARNIT_TILESHEET *d_render_tilesheet_new(int tiles_w, int tiles_h, int tile_w, int tile_h, DARNIT_PFORMAT format);
Creates a new blank tilesheet. To fill in pixel data into the tilesheet, use d_render_tilesheet_update.
Arguments
- tiles_w - How many tiles on the width that the tilesheet needs to fit
- tiles_h - How many tiles on the hight that the tilesheet needs to fit
- tile_w - How wide each tile is
- tile_h - How tall each tile is
- format - What pixel format the tilesheet should use
Return value
Returns NULL on failure. Anything else is a valid DARNIT_TILESHEET.
DARNIT_TILESHEET *d_render_tilesheet_free(DARNIT_TILESHEET *tilesheet);
Tries to free a tilesheet. If not successful (tilesheet us used by other resources,) the internal reference counter is decreased and another attempt to unload it will happen next time something using the tilesheet unloads.
Arguments
- tilesheet - The DARNIT_TILESHEET to unload
Return value
Returns NULL if the tilesheet was free'd. If not (in used by other resources,) tilesheet will be returned.
void d_render_tilesheet_update(DARNIT_TILESHEET *tilesheet, int sheet_x, int sheet_y, int change_w, int change_h, void *data);
Updates an area in the tilesheet texture with new texture data found in data. This operation affects everything using the tilesheet, and changes persists until everything that uses the tilesheet is unloaded. data should be in RGBA8 format unless the tilesheet you're updating is RGB0A8. If the tilesheet is in RGB0A8, then you should also upload RGB0A8 data.
Arguments
- tilesheet - The DARNIT_TILESHEET to update
- sheet_x - The X-coordinate in pixels at which the rectangle to update starts. 0 is to the left.
- sheet_y - The Y-coordinate in pixels at which the rectangle to update starts. 0 is at the top.
- change_w - The width of the rectangle to update in pixels.
- change_h - The height of the rectangle to update in pixels.
- data - A memory buffer containing the new pixels to load the tilesheet with. Pixels must be ordered in rows.
Return value None.
void d_render_tilesheet_geometrics(DARNIT_TILESHEET *tilesheet, int *w, int *h, int *tile_w, int *tile_h);
Returns the width and height of a tilesheet, as well as the tile width and height.
Arguments
- tilesheet - The DARNIT_TILESHEET to get information about
- w - The width of the tilesheet in pixels. This pointer can be NULL.
- h - The height of the tilehseet in pixels. This pointer can be NULL.
- tile_w - The width of a tile in pixels. This pointer can be NULL.
- tile_h - The height of a tile in pixels. This pointer can be NULL.
Return value None.
int d_render_tilesheet_animation_apply(DARNIT_TILESHEET *tilesheet, const char *fname);
Applies a TMA to a tilesheet. This animation will affect everything that uses a tilesheet. The animation will persist until the tilesheet is no longer used by anything. Please note that animation does not happen automatically. Once per frame, you need to call d_render_tilesheet_animate.
Arguments
- tilesheet - The [DARNIT_TILESHEET] to apply the animation to
- fname - The TMA file to apply to tilesheet.
Return value None.
void d_render_tilesheet_animate(DARNIT_TILESHEET *tilesheet);
Runs the animation procedure for a tilesheet.
Arguments
- tilesheet - The [DARNIT_TILESHEET] to animate
Return value None.
void d_render_tilesheet_scale_algorithm(DARNIT_TILESHEET *tilesheet, DARNIT_RENDER_SCALE scaling);
Sets the scaling algorithm to use for the tilesheet when a tile is stretched.
Arguments
- tilesheet - The tilesheet to change the scaling algorithm for
- scaling - A scaling algorithm from DARNIT_RENDER_SCALE to use
Return value None.