summaryrefslogtreecommitdiff
path: root/src/texture.c
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2026-01-30 19:12:03 -0600
committerAaditya Dhruv <[email protected]>2026-01-30 19:12:03 -0600
commit1a721b98caf7559f4a18baa8d3b92269e8f1f6ce (patch)
tree32be8966361f8f8ae74c6c0af226e39fe9feb375 /src/texture.c
parent4992ce0098cac8caef6c9315816b688d96259bce (diff)
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
Diffstat (limited to 'src/texture.c')
-rw-r--r--src/texture.c26
1 files changed, 26 insertions, 0 deletions
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 <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);
+}