summaryrefslogtreecommitdiff
path: root/src/texture.c
blob: 8f2a2a7dfe1e6e7404baa1855f18c84aa56ee88c (plain) (blame)
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 "texture.h"
#include "cglm/io.h"
#include "util.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb/stb_image.h"
#include <stdlib.h>
#include <string.h>
void texture_init(struct texture** texture) {
    *texture = malloc(sizeof(struct texture));
    memset(*texture, 0, sizeof(struct texture));
}

void texture_load(struct texture* texture, char* path) {
    int width, height, nr_channels;
    unsigned char *data = stbi_load(path, &width, &height, &nr_channels, 0);
    vec2 size = { width, height };
    glm_vec2_print(size, stderr);
    create_texture(&texture->_tbo, data, size);
    stbi_image_free(data);
    fprintf(stderr, "Loaded texture\n");
}

void texture_draw(struct texture* texture) {
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture->_tbo);
}