summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--height-map-display/CMakeLists.txt7
m---------height-map-display/lib/stb0
-rw-r--r--height-map-display/src/main.c4
-rw-r--r--height-map-display/src/sprites/loader.c37
-rw-r--r--height-map-display/src/sprites/loader.h14
5 files changed, 59 insertions, 3 deletions
diff --git a/height-map-display/CMakeLists.txt b/height-map-display/CMakeLists.txt
index c55a0fe..b5219bf 100644
--- a/height-map-display/CMakeLists.txt
+++ b/height-map-display/CMakeLists.txt
@@ -8,7 +8,10 @@ find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
find_package(Freetype REQUIRED)
-file(GLOB SOURCES "src/*.c" "src/map/*.c")
+# Include directory for STB headers
+include_directories(${CMAKE_SOURCE_DIR}/lib/stb)
+
+file(GLOB SOURCES "src/*.c" "src/map/*.c" "src/sprites/*.c")
add_executable(build ${SOURCES})
-target_link_libraries(build ${OPENGL_gl_LIBRARY} ${OPENGL_INCLUDE_DIRS} ${FREETYPE_LIBARIES} ${GLEW_LIBRARIES} glfw m)
+target_link_libraries(build ${OPENGL_gl_LIBRARY} ${OPENGL_INCLUDE_DIRS} ${FREETYPE_LIBRARIES} ${GLEW_LIBRARIES} glfw m)
diff --git a/height-map-display/lib/stb b/height-map-display/lib/stb
new file mode 160000
+Subproject ae721c50eaf761660b4f90cc590453cdb0c2acd
diff --git a/height-map-display/src/main.c b/height-map-display/src/main.c
index ad3f093..9860b0a 100644
--- a/height-map-display/src/main.c
+++ b/height-map-display/src/main.c
@@ -8,13 +8,15 @@
#include "map/node.h"
#include "map/square.h"
+#include "sprites/loader.h"
+
#define MAP_HEIGHT 10
#define MAP_WIDTH 10
float camera_pos_x = 0.0f;
float camera_pos_y = 0.0f;
float camera_pos_z = 0.0f;
-float camera_yaw = 33.4f; // rotation around y-axis
+float camera_yaw = 45.0f; // rotation around y-axis
float camera_pitch = -66.7f; // rotation aroudn x-axis
float camera_speed = 0.1f;
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;
+
+}
diff --git a/height-map-display/src/sprites/loader.h b/height-map-display/src/sprites/loader.h
new file mode 100644
index 0000000..5f3a35e
--- /dev/null
+++ b/height-map-display/src/sprites/loader.h
@@ -0,0 +1,14 @@
+#ifndef LOADER_H
+#define LOADER_H
+
+#include <GL/glew.h>
+
+typedef struct {
+ float x, y;
+ float width, height;
+ GLuint texture_id;
+} Sprite;
+
+GLuint load_texture(const char* path);
+
+#endif