Files
dangerzone/src/engine/render/misc.c
T

72 lines
1.5 KiB
C

#include <dangerzone/engine.h>
#include <dangerzone/render/misc.h>
#include <dangerzone/render/rect.h>
#include "internal/engine_internal.h"
#include "internal/util/error.h"
#include <stdint.h>
// helper function to return the correct pointer to a framebuffer for drawing selection
uint32_t*
get_framebuffer(
framebuffer_e framebuffer
) {
switch (framebuffer) {
case BASE:
return game_state->framebuffer_base;
case OVERDRAW:
return game_state->framebuffer_overdraw;
default:
return game_state->framebuffer_base;
}
}
// alter a pixel at an imaginary x & y coordinates
void
put_pixel(
framebuffer_e framebuffer,
unsigned int x,
unsigned int y,
uint32_t color
) {
uint32_t *current_framebuffer = get_framebuffer(framebuffer);
uint16_t w = game_state->width;
uint16_t h = game_state->height;
if (x < 0 || x >= w || y < 0 || y >= h) {
eprintf(
"CRITICAL: attempted buffer overflow in put_pixel\n"
"at x = %d, y = %d", x, y
);
} else {
current_framebuffer[game_state->width * y + x]
= color;
mark_dirty_rect(x, y, 1, 1);
}
}
// fill the entire framebuffer with a given color
void
clear_framebuffer(
framebuffer_e framebuffer,
uint32_t color
) {
uint32_t *current_framebuffer = get_framebuffer(framebuffer);
for (size_t i = 0;
i < (size_t)game_state->width * game_state->height;
++i) {
current_framebuffer[i] = color;
}
mark_dirty_rect(
0,
0,
game_state->width,
game_state->height
);
}