summary refs log tree commit diff
path: root/src/Util/ImageViewer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Util/ImageViewer.cpp')
-rw-r--r--src/Util/ImageViewer.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Util/ImageViewer.cpp b/src/Util/ImageViewer.cpp
new file mode 100644
index 0000000..76faa3e
--- /dev/null
+++ b/src/Util/ImageViewer.cpp
@@ -0,0 +1,59 @@
+#include <GL/glew.h>
+#include "ImageViewer.hpp"
+
+namespace MC::Util {
+
+void ImageViewer::render() {
+    m_program.bind();
+    m_texture.bind();
+    m_mesh.bind();
+    glDrawElements(GL_TRIANGLES, m_mesh.size(), GL_UNSIGNED_INT, nullptr);
+    m_mesh.unbind();
+    m_texture.unbind();
+    m_program.unbind();
+}
+
+GFX::Mesh ImageViewer::create_default_mesh() {
+    return {{
+        std::vector<Vector<3>>{
+            {0.0f,  1.0f, 0.0f},   // top left
+            {0.0f, 0.0f, 0.0f},   // bottom left
+            {1.0f, 0.0f, 0.0f},   // bottom right
+            {1.0f,  0.0f, 0.0f } // top right
+        },
+        std::vector<Vector<2>>{
+            {1.0f, 1.0f},
+            {1.0f, 0.0f,},
+            {0.0f, 0.0f},
+            {0.0f, 1.0f},
+        },
+    }, {0, 1, 2, 0, 2, 3}};
+}
+
+const char* ImageViewer::vertex = R"v(
+#version 330 core
+
+layout (location = 0) in vec3 position;
+layout (location = 1) in vec2 tex_coord;
+
+out vec2 frag_tex_coord;
+
+void main() {
+    gl_Position = vec4(position, 1.0);
+    frag_tex_coord = tex_coord;
+})v";
+
+const char* ImageViewer::fragment = R"f(
+#version 330 core
+
+uniform sampler2D image;
+
+in vec2 frag_tex_coord;
+out vec4 color;
+
+void main() {
+    //color = texture(image, frag_tex_coord);
+    color = vec4(0.3, 0.5, 1.0, 1.0);
+})f";
+
+}
\ No newline at end of file