diff options
Diffstat (limited to 'src/Util/ImageViewer.cpp')
| -rw-r--r-- | src/Util/ImageViewer.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/Util/ImageViewer.cpp b/src/Util/ImageViewer.cpp index 76faa3e..b4d8c6e 100644 --- a/src/Util/ImageViewer.cpp +++ b/src/Util/ImageViewer.cpp @@ -1,8 +1,29 @@ #include <GL/glew.h> #include "ImageViewer.hpp" +#include "../Math/MVP.hpp" namespace MC::Util { +ImageViewer::ImageViewer( + GFX::Image::RawImage& image +) : m_texture(image), + m_program( + {GFX::Shading::Shader::Type::Vertex, ImageViewer::vertex}, + {GFX::Shading::Shader::Type::Fragment, ImageViewer::fragment} + ), + m_mesh(GFX::Binder::load(default_mesh)) { + m_program.bind(); + auto model_uniform = m_program.uniform("model_matrix"); + auto view_uniform = m_program.uniform("view_matrix"); + auto projection_uniform = m_program.uniform("projection_matrix"); + + model_uniform.set(Math::MVP::model({}, {})); + view_uniform.set(Math::MVP::view({}, {})); + projection_uniform.set(Math::MVP::orthographic_projection(1000, 800, 0.0f, 100.0f)); + + m_program.unbind(); +} + void ImageViewer::render() { m_program.bind(); m_texture.bind(); @@ -16,10 +37,10 @@ void ImageViewer::render() { 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 + {300.0f, 200.0f, 0.0f}, // top left + {300.0f, 600.0f, 0.0f}, // bottom left + {700.0f, 600.0f, 0.0f}, // bottom right + {700.0f, 200.0f, 0.0f } // top right }, std::vector<Vector<2>>{ {1.0f, 1.0f}, @@ -33,13 +54,17 @@ GFX::Mesh ImageViewer::create_default_mesh() { const char* ImageViewer::vertex = R"v( #version 330 core +uniform mat4 model_matrix; +uniform mat4 view_matrix; +uniform mat4 projection_matrix; + 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); + gl_Position = projection_matrix * view_matrix * model_matrix * vec4(position, 1.0); frag_tex_coord = tex_coord; })v"; @@ -52,8 +77,7 @@ 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); + color = texture(image, frag_tex_coord); })f"; } \ No newline at end of file |
