From 1a721b98caf7559f4a18baa8d3b92269e8f1f6ce Mon Sep 17 00:00:00 2001 From: Aaditya Dhruv Date: Fri, 30 Jan 2026 19:12:03 -0600 Subject: Add basic block textures - Remove the code that sent colors through uniform variables, instead send texture data - Each vertex now has a texture coordinate - struct texture is a easy way to represent textures, can be extended later - Shaders updated to use textures --- src/texture.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/texture.c (limited to 'src/texture.c') diff --git a/src/texture.c b/src/texture.c new file mode 100644 index 0000000..8f2a2a7 --- /dev/null +++ b/src/texture.c @@ -0,0 +1,26 @@ +#include "texture.h" +#include "cglm/io.h" +#include "util.h" +#define STB_IMAGE_IMPLEMENTATION +#include "stb/stb_image.h" +#include +#include +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); +} -- cgit