~mika/sofa

sofa/canvas.c -rw-r--r-- 454 bytes
3922037a — m1ka Add licensing + fix last memory mgmt issue 27 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>

#include <glad/gl.h>

#include "canvas.h"


canvas_t canvas_create(GLint w, GLint h) {
    color_t* data = calloc(w * h, sizeof(color_t));

    return (canvas_t){
        .data = data,
        .w = w,
        .h = h
    };
}

void canvas_clear(canvas_t* self, color_t clear) {
    for (int i = 0; i < ( self->w * self->h ); i++) {
        self->data[i] = clear;
    }
}

void canvas_destroy(canvas_t* self) {
    free(self->data);
}