Skip to content
slaeshjag edited this page Apr 14, 2013 · 31 revisions

DARNIT_RENDER_LOGIC_OP

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;

DARNIT_RENDER_SCALE

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;

DARNIT_TILESHEET

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_TILE

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.

DARNIT_LINE

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_CIRCLE

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

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);

DARNIT_RENDER

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);

d_render_logic_op

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.

d_render_tilesheet_load

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.

d_render_tilesheet_isom_load

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.

d_render_tilesheet_new

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.

d_render_tilesheet_free

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

Return value

Returns NULL if the tilesheet was free'd. If not (in used by other resources,) tilesheet will be returned.

d_render_tilesheet_update

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.

d_render_tilesheet_geometrics

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.

d_render_tilesheet_animation_apply

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.

d_render_tilesheet_animate

void d_render_tilesheet_animate(DARNIT_TILESHEET *tilesheet);

Runs the animation procedure for a tilesheet.

Arguments

Return value None.

d_render_tilesheet_scale_algorithm

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.

d_render_tile_init

void d_render_tile_init(DARNIT_TILE *buf, unsigned int tile, unsigned int tile_ts, int x, int y);

Sets the tile number tile in buf to render tile tile_ts from its associated tilesheet. This resets size information to the size of the tile, and positions it on the screen at the coordinates x, y.

Arguments

  • buf - The DARNIT_TILE to modify a tile in
  • tile - Index of the tile inside the buffer to modify
  • tile_ts - Index of the tile in the tilesheet to set the tile buffer tile to
  • x - The X-position to place the tile at
  • y - The Y-position to place the tile at

Return value none.

d_render_tile_move

void d_render_tile_move(DARNIT_TILE *tile_p, unsigned int tile, int x, int y);

Moves a tile inside a DARNIT_TILE. This will reset its size.

Arguments

  • tile_p - The tile cache to modify a tile in
  • tile - The tile index in the tile buffer to modify
  • x - The X-coordinate to move the tile to
  • y - The Y-coordinate to move the tile to

Return value None.

d_render_tile_tilesheet_coord_set

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);

Changes the coordinates for a tile on a tilesheet. That is, its position on the screen remains unchanged, but the graphics from the tilesheet is updated. The size of the tile is not updated.

Arguments

  • tile_p - The tile buffer to update a tile in
  • tile - The tile in the tile buffer to update
  • x - The X-position on the tilesheet (in pixels) to use
  • y - The Y-position on the tilesheet (in pixels) to use
  • w - The width of the area to use when rendering the tile
  • h - The height of the area to use when rendering the tile

Return value None.

d_render_tile_size_set

void d_render_tile_size_set(DARNIT_TILE *buf, unsigned int tile, int w, int h);

Sets the size of a tile in a tile buffer. This can be used to scale a tile, as it doesn't modify tilesheet coordinates.

Arguments

  • buf - The tile buffer to modify a tile in
  • tile - The tile index in the tile buffer of the tile to modify
  • w - The new width of the tile
  • h - The new height of the tile

Return value None.

d_render_tile_set

void d_render_tile_set(DARNIT_TILE *tile_p, unsigned int tile, unsigned int tile_ts);

Sets the tilesheet tile that should be rendered by a tile buffer tile. This does not modify the rendered size of a tile.

Arguments

  • tile_p - The tile buffer to modify a tile in
  • tile - The tile buffer tile index to modify
  • tile_ts - The tilesheet tile index to set to the tile buffer tile

Return value None.

d_render_tile_tilesheet

void d_render_tile_tilesheet(DARNIT_TILE *tile_p, DARNIT_TILESHEET *tilesheet);

Sets a new tilesheet to a tile cache. This does not update any tilesheet coordinates. If a tilesheet of different size is loaded in, distortion will happen, as coordinates are saved as floats between 0 and 1.

Arguments

  • tile_p - The tile buffer to set tilesheet for
  • tilesheet - The tilesheet to set

Return value None.

d_render_tile_clear

void d_render_tile_clear(DARNIT_TILE *tile_p, unsigned int tile);

Makes a tile in a tile cache invisible, discarding position and tilesheet coordinates.

Arguments

  • tile_p - The tile cache to modify a tile in
  • tile - The tile index of the tile to clear

Return value None.

d_render_tile_draw

void d_render_tile_draw(DARNIT_TILE *tile_p, unsigned int tiles);

Draws tiles from a tile buffer starting from index 0.

Arguments

  • tile_p - Tile cache to draw
  • tiles - Number of tiles to draw from the tile cache

Return value None.

d_render_tile_new

DARNIT_TILE *d_render_tile_new(unsigned int tiles, DARNIT_TILESHEET *tilesheet);

Allocates a tile cache with room for tiles number of tiles, and sets tilesheet to it.

Arguments

  • tiles - The number of tiles to make room for
  • tilesheet * The tilesheet to render tiles with

Return value

Returns NULL on failure, anything else is a valid tile cache.

d_render_tile_free

DARNIT_TILE *d_render_tile_free(DARNIT_TILE *tile_p);

Free's a tile cache and returns a NULL-pointer for compact pointer clearing.

Arguments

  • tile_p - The tile cache to free

Return value

Returns NULL for compact pointer clearing.

d_render_line_new

DARNIT_LINE *d_render_line_new(unsigned int lines, unsigned int line_w);

Allocates a buffer for untextured and non-colored lines.

Arguments

  • lines - The number of lines to make space for
  • line_w - The width of the lines to draw in pixels

Return value

Returns NULL on fauilure, anything else is a valid line buffer.

d_render_line_move

void d_render_line_move(DARNIT_LINE *line_p, unsigned int line, int x1, int y1, int x2, int y2);

Sets the position to draw the line with index line.

Arguments

  • line_p - The line buffer to modify a line in
  • line - The line index of the line you want to modify. 0 is the first line.
  • x1 - The X-coordinate for where the line starts
  • y1 - The Y-coordinate for where the line starts
  • x2 - The X-coordinate for where the line ends
  • y2 - The Y-coordinate for where the line ends

Return value None.

d_render_line_draw

void d_render_line_draw(DARNIT_LINE *line_p, int lines);

Draws lines number of lines in the line buffer, starting with line 0.

Arguments

  • line_p - The line buffer to draw lines from
  • lines - The number of lines to draw

Return value None.

d_render_line_get

void d_render_line_get(DARNIT_LINE *buf, unsigned int line, int *x, int *y, int *x2, int *y2);

Returns an approximation of the coordinates line with index line in the buffer.

Arguments

  • buf - The line chache to get a line coordinate from
  • line - The line index to get the coordinates of
  • x - The X-coordinate of where the line starts will be written here
  • y - The Y-coordinate of where the line starts will be written here
  • x2 - The X-coordinate of where the line ends will we written here
  • y2 - The Y-coordinate of where the line ends will be written here

Return value None.

d_render_line_free

DARNIT_LINE *d_render_line_free(DARNIT_LINE *line_p);

Frees a line cache and returns a NULL-pointer for compact clearing.

Arguments

  • line_p - The line buffer to free

Return value

Returns NULL for compact pointer clearing.

Clone this wiki locally