From 50cdd344a3ed87c75a67739e2ffd34762e9b0895 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 12 Aug 2025 18:12:37 +0200 Subject: feat: start of a basic rendering backend --- src/core/application.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++-- src/core/application.h | 13 ++++++++++++ src/core/window.cpp | 9 ++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) (limited to 'src/core') 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 +#include +#include 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::create()); + m_vertex_buffer = std::shared_ptr(VertexBuffer::create(vertices, sizeof(vertices))); + + VertexBufferLayout layout; + layout.push(3); + layout.push(4); + m_vertex_buffer->set_layout(layout); + + m_vertex_array->add_vertex_buffer(m_vertex_buffer); + + m_index_buffer = std::shared_ptr(IndexBuffer::create(indices, 3)); + m_vertex_array->set_index_buffer(m_index_buffer); + + m_shader = std::shared_ptr(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(); } } diff --git a/src/core/application.h b/src/core/application.h index d88eab2..a860e1c 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -5,6 +5,14 @@ #include #include +namespace Donut +{ + class VertexArray; + class VertexBuffer; + class IndexBuffer; + class Shader; +}; + namespace Donut { class Application @@ -30,6 +38,11 @@ namespace Donut bool m_running; bool m_minimized; + std::shared_ptr m_vertex_array; + std::shared_ptr m_vertex_buffer; + std::shared_ptr m_index_buffer; + std::shared_ptr m_shader; + static Application* s_instance; }; } diff --git a/src/core/window.cpp b/src/core/window.cpp index ab5b977..77ef885 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -1,6 +1,7 @@ #include "window.h" #include #include +#include namespace Donut { @@ -42,6 +43,14 @@ namespace Donut } glfwMakeContextCurrent(m_window); + + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + std::cout << "Failed to initialize GLAD!" << std::endl; + glfwTerminate(); + return; + } + glfwSetWindowUserPointer(m_window, this); glfwSetErrorCallback(glfw_error_callback); -- cgit v1.3