diff options
| author | Mel <einebeere@gmail.com> | 2022-10-14 13:30:15 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-14 13:30:15 +0200 |
| commit | 8ec223cd4ffec8ff883e022db94714a0b814ae58 (patch) | |
| tree | 65347fb1981ce2bb76ac84e0a82ab215f92a9fe0 /src/main.cpp | |
| parent | cb3ddae385c03a8830d39dc37fcd5bf273524d5e (diff) | |
| download | meowcraft-8ec223cd4ffec8ff883e022db94714a0b814ae58.tar.zst meowcraft-8ec223cd4ffec8ff883e022db94714a0b814ae58.zip | |
Textured Cube
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/src/main.cpp b/src/main.cpp index 1f5d3a2..58c7b8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,8 @@ #include "Math/MVP.hpp" #include "Shader/ShaderProgram.hpp" #include "Mouse.hpp" +#include "Texture.hpp" +#include "Image/PPMParser.hpp" #define APP_NAME "Meowcraft" @@ -21,7 +23,7 @@ #define FOV 45 void run(); -void render(MC::BindableMesh&); +void render(MC::BindableMesh&, MC::Texture&); void process_input(MC::Window&, MC::Mouse&, MC::Camera&); void setup_gl(); void fix_macos_render(MC::Window&); @@ -51,30 +53,37 @@ void run() { glViewport(0, 0, w, h); }); + auto image = MC::Image::PPMParser(MC::Assets::Images::atlas).parse(); + auto texture = MC::Texture(image); + MC::Mesh shape({ - {-0.5f, -0.5f, 0.5f}, - {0.5f, -0.5f, 0.5f}, - {0.5f, 0.5f, 0.5f}, - {-0.5f, 0.5f, 0.5f}, - - {-0.5f, -0.5f, -0.5f}, - {0.5f, -0.5f, -0.5f}, - {0.5f, 0.5f, -0.5f}, - {-0.5f, 0.5f, -0.5f} + {-1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, + {-1.0f, 1.0f, -1.0f}, {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, + + {-1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, -1.0f}, + {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, 1.0f}, + + {-1.0f, 1.0f, -1.0f}, {1.0f, 1.0f, -1.0f}, {1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, + {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, }, { - {-0.5f, -0.5f}, {0.5f, 0.5f}, - {-0.5f, 0.5f}, {0.5f, 0.5f}, - {0.5f, -0.5f}, {0.5f, 0.5f}, - {-0.5f, -0.5f}, {-0.5f, 0.5f} + {0.5f, 0.5f}, {0.0f, 0.5f}, {0.0f, 1.0f}, {0.5f, 1.0f}, + {0.5f, 0.5f}, {0.0f, 0.5f}, {0.0f, 1.0f}, {0.5f, 1.0f}, + + {0.5f, 0.5f}, {0.0f, 0.5f}, {0.0f, 1.0f}, {0.5f, 1.0f}, + {0.5f, 0.5f}, {0.0f, 0.5f}, {0.0f, 1.0f}, {0.5f, 1.0f}, + + {0.0f, 0.5f}, {0.5f, 0.5f}, {0.5f, 0.0f}, {0.0f, 0.0f}, + {0.5f, 0.5f}, {1.0f, 0.5f}, {1.0f, 0.0f}, {0.5f, 0.0f}, }, { - 0, 1, 2, 2, 3, 0, - 1, 5, 6, 6, 2, 1, - 7, 6, 5, 5, 4, 7, - 4, 0, 3, 3, 7, 4, - 4, 5, 1, 1, 0, 4, - 3, 2, 6, 6, 7, 3 + 0, 1, 3, 1, 2, 3, + 4, 5, 7, 5, 6, 7, + 8, 9, 11, 9, 10, 11, + 12, 13, 15, 13, 14, 15, + 16, 17, 19, 17, 18, 19, + 20, 21, 23, 21, 22, 23, + 24, 25, 27, 25, 26, 27, }); auto mesh = MC::Binder::load(shape); @@ -92,6 +101,9 @@ void run() { auto projection = Math::MVP::projection(ASPECT, FOV, 0.1f, 100.0f); projection_uniform.set(projection); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + uint64_t time = 0; while (!window.should_close()) { @@ -105,25 +117,27 @@ void run() { program.bind(); - auto angle = fmod(time / 10.0f, 360.0f); + auto angle = std::fmod(time / 10.0f, 360.0f); auto model = Math::MVP::model({0.0f, 0.0f, 0.0f}, {angle, angle, 0.0f}); model_uniform.set(model); auto view = Math::MVP::view(camera.position(), camera.angles()); view_uniform.set(view); - render(mesh); + render(mesh, texture); time++; } } -void render(MC::BindableMesh& mesh) { +void render(MC::BindableMesh& mesh, MC::Texture& texture) { glClearColor(0.85f, 0.85f, 0.85f, 1.0f); // #DBDBDB - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + texture.bind(); mesh.bind(); glDrawElements(GL_TRIANGLES, mesh.size(), GL_UNSIGNED_INT, 0); mesh.unbind(); + texture.unbind(); } void process_input(MC::Window& window, MC::Mouse& mouse, MC::Camera& camera) { |
