diff options
| author | hachem <im@hachem.wtf> | 2025-08-12 18:12:37 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-08-12 18:12:37 +0200 |
| commit | 50cdd344a3ed87c75a67739e2ffd34762e9b0895 (patch) | |
| tree | 2a4a107e92687236c6676296281b89e14f8eac01 /src/core | |
| parent | dbe642e5e26cf2bd99218f727157b58c7fed286e (diff) | |
feat: start of a basic rendering backend
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/application.cpp | 54 | ||||
| -rw-r--r-- | src/core/application.h | 13 | ||||
| -rw-r--r-- | src/core/window.cpp | 9 |
3 files changed, 74 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(); } } 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 @@ -7,6 +7,14 @@ namespace Donut { + class VertexArray; + class VertexBuffer; + class IndexBuffer; + class Shader; +}; + +namespace Donut +{ class Application { public: @@ -30,6 +38,11 @@ namespace Donut bool m_running; bool m_minimized; + std::shared_ptr<VertexArray> m_vertex_array; + std::shared_ptr<VertexBuffer> m_vertex_buffer; + std::shared_ptr<IndexBuffer> m_index_buffer; + std::shared_ptr<Shader> 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 <cstdint> #include <iostream> +#include <glad/glad.h> 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); |
