diff options
Diffstat (limited to 'src/core/application.cpp')
| -rw-r--r-- | src/core/application.cpp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/src/core/application.cpp b/src/core/application.cpp index d98ae4f..92bf211 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -1,5 +1,14 @@ #include "application.h" + +#include "rendering/renderer.h" +#include "rendering/vertex_array.h" +#include "rendering/vertex_buffer.h" +#include "rendering/index_buffer.h" +#include "rendering/shader.h" + #include <iostream> +#include <glm/glm.hpp> +#include <glm/gtc/matrix_transform.hpp> namespace Donut { @@ -73,8 +82,39 @@ namespace Donut }); } - void Application::on_init() { } - void Application::on_shutdown() { } + void Application::on_init() + { + Renderer::init(); + + float vertices[3 * 7] = + { + -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, + 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f + }; + + uint32_t indices[3] = { 0, 1, 2 }; + + m_vertex_array = std::shared_ptr<VertexArray>(VertexArray::create()); + m_vertex_buffer = std::shared_ptr<VertexBuffer>(VertexBuffer::create(vertices, sizeof(vertices))); + + VertexBufferLayout layout; + layout.push<float>(3); + layout.push<float>(4); + m_vertex_buffer->set_layout(layout); + + m_vertex_array->add_vertex_buffer(m_vertex_buffer); + + m_index_buffer = std::shared_ptr<IndexBuffer>(IndexBuffer::create(indices, 3)); + m_vertex_array->set_index_buffer(m_index_buffer); + + m_shader = std::shared_ptr<Shader>(Shader::create("assets/basic.glsl")); + } + + void Application::on_shutdown() + { + Renderer::shutdown(); + } void Application::on_update() { @@ -82,5 +122,15 @@ namespace Donut void Application::on_render() { + Renderer::set_clear_color({ 0.1f, 0.1f, 0.1f, 1.0f }); + Renderer::clear(); + + Renderer::begin_scene(); + + glm::mat4 view_projection = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); + + Renderer::submit(m_shader, m_vertex_array, glm::mat4(1.0f)); + + Renderer::end_scene(); } } |
