From 2d360229145c0c3995a75be2cbf5864580a91fe0 Mon Sep 17 00:00:00 2001
From: Dethcrvsh <fabianfabbe@hotmail.se>
Date: Sat, 16 Nov 2024 16:47:16 +0100
Subject: [PATCH] wip

---
 CMakeLists.txt       |  2 +-
 shaders/surface.vert |  5 ++++-
 src/main.cpp         |  3 +++
 src/waves.cpp        | 16 ++++++++++++++++
 src/waves.h          |  8 ++++++++
 5 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 src/waves.cpp
 create mode 100644 src/waves.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b8b3ddb..29a9666 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,7 @@ set(COMMON_SOURCES
     common/Linux/MicroGlut.c
 )
 
-file(GLOB_RECURSE SRC_SOURCES src/*.cpp src/*.c)
+file(GLOB_RECURSE SRC_SOURCES src/*.cpp src/*.c src/*.h)
 
 set(SOURCES ${COMMON_SOURCES} ${SRC_SOURCES})
 
diff --git a/shaders/surface.vert b/shaders/surface.vert
index 1296d38..e970ab7 100644
--- a/shaders/surface.vert
+++ b/shaders/surface.vert
@@ -8,6 +8,10 @@ uniform mat4 projectionMatrix;
 uniform mat4 modelToWorldToView;
 uniform float time;
 
+// layout(std140) uniform VertexBuffer {
+//     Wave waves_b[16];
+// };
+
 out vec3 world_pos;
 out vec3 normal;
 
@@ -57,7 +61,6 @@ vec3 get_waves(const vec3 pos, const float t) {
     }
     
     return offset + vec3(pos.x, 0.0, pos.z);
-
 }
 
 /* Get the normal for a wave */
diff --git a/src/main.cpp b/src/main.cpp
index 5ce9d97..96ce322 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,6 +9,7 @@
 #include "LoadTGA.h"
 #include "MicroGlut.h"
 #include "VectorUtils4.h"
+#include "waves.h"
 // uses framework OpenGL
 // uses framework Cocoa
 
@@ -256,6 +257,8 @@ int main(int argc, char* argv[])
     glutMotionFunc(on_mouse_move);
     glutMouseFunc(on_mouse_button);
 
+    Waves::init();
+
     glutMainLoop();
     exit(0);
 }
diff --git a/src/waves.cpp b/src/waves.cpp
new file mode 100644
index 0000000..853d614
--- /dev/null
+++ b/src/waves.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "waves.h"
+#include <GL/gl.h>
+
+
+namespace Waves {
+
+GLuint ubo;
+
+void init() {
+    glGenBuffers(1, &ubo);
+    glBindBuffer(GL_UNIFORM_BUFFER, ubo);
+    glBufferData(GL_UNIFORM_BUFFER, sizeof(Wave) * 16, nullptr, GL_DYNAMIC_DRAW);
+}
+
+};
diff --git a/src/waves.h b/src/waves.h
new file mode 100644
index 0000000..bcf9d29
--- /dev/null
+++ b/src/waves.h
@@ -0,0 +1,8 @@
+#pragma once
+
+
+namespace Waves {
+
+void init();
+
+};
-- 
GitLab