summaryrefslogtreecommitdiff
path: root/height-map-display/src/sprites/loader.c
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2026-09-24 00:41:13 -0400
committerSchark <jordan@schark.online>2026-09-24 00:41:13 -0400
commit09beb96d7227ff2467b6c0e6fb404f2b99768a54 (patch)
treee3316af44b8e8b0e765e1fcae8b2e520471d5eca /height-map-display/src/sprites/loader.c
parent651fa5ef62cb9e8e1f47c07cc8d6b3abc4d70cd5 (diff)
parent9963f71b09a919cb37631f6764a7dc1a5fa273f2 (diff)
downloadgamedev-09beb96d7227ff2467b6c0e6fb404f2b99768a54.tar.gz
gamedev-09beb96d7227ff2467b6c0e6fb404f2b99768a54.zip
Merge remote-tracking branch 'origin/master'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to '')
-rw-r--r--height-map-display/src/sprites/loader.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/height-map-display/src/sprites/loader.c b/height-map-display/src/sprites/loader.c
new file mode 100644
index 0000000..393af10
--- /dev/null
+++ b/height-map-display/src/sprites/loader.c
@@ -0,0 +1,37 @@
+#include "loader.h"
+
+#define STB_IMAGE_IMPLEMENTATION
+#include "stb_image.h"
+#include <stdio.h>
+
+GLuint load_texture(const char* path) {
+
+ GLuint texture_id;
+ glGenTextures(1, &texture_id);
+
+ glBindTexture(GL_TEXTURE_2D, texture_id);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_REPEAT);
+
+
+ // Load image data
+ int width, height, nr_channels;
+ unsigned char* data = stbi_load(path, &width, &height, &nr_channels, 0);
+ if (data) {
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
+ glGenerateMipmap(GL_TEXTURE_2D);
+ } else {
+ printf("Failed to load texture: %s\n", path);
+ }
+ stbi_image_free(data);
+
+ // Unbind texture
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ return texture_id;
+
+}