From a2ec7dabd48a70ea69623406ddd0f8f97af403c8 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 12 Aug 2025 18:12:37 +0200 Subject: [add]: Start of a basic rendering backend --- src/Core/Application.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++-- src/Core/Application.h | 13 ++++++++++++ src/Core/Window.cpp | 10 +++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) (limited to 'src/Core') diff --git a/src/Core/Application.cpp b/src/Core/Application.cpp index 9ca060c..98d1de7 100644 --- a/src/Core/Application.cpp +++ b/src/Core/Application.cpp @@ -1,5 +1,14 @@ #include "Application.h" + +#include "Rendering/Renderer.h" +#include "Rendering/VertexArray.h" +#include "Rendering/VertexBuffer.h" +#include "Rendering/IndexBuffer.h" +#include "Rendering/Shader.h" + #include +#include +#include namespace Donut { @@ -73,8 +82,39 @@ namespace Donut }); } - void Application::OnInit() { } - void Application::OnShutdown() { } + void Application::OnInit() + { + 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_VertexArray = std::shared_ptr(VertexArray::Create()); + m_VertexBuffer = std::shared_ptr(VertexBuffer::Create(vertices, sizeof(vertices))); + + VertexBufferLayout layout; + layout.Push(3); + layout.Push(4); + m_VertexBuffer->SetLayout(layout); + + m_VertexArray->AddVertexBuffer(m_VertexBuffer); + + m_IndexBuffer = std::shared_ptr(IndexBuffer::Create(indices, 3)); + m_VertexArray->SetIndexBuffer(m_IndexBuffer); + + m_Shader = std::shared_ptr(Shader::Create("assets/Basic.glsl")); + } + + void Application::OnShutdown() + { + Renderer::Shutdown(); + } void Application::OnUpdate() { @@ -82,5 +122,15 @@ namespace Donut void Application::OnRender() { + Renderer::SetClearColor({ 0.1f, 0.1f, 0.1f, 1.0f }); + Renderer::Clear(); + + Renderer::BeginScene(); + + glm::mat4 viewProjection = glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); + + Renderer::Submit(m_Shader, m_VertexArray, glm::mat4(1.0f)); + + Renderer::EndScene(); } } diff --git a/src/Core/Application.h b/src/Core/Application.h index fca4c42..b8c9d49 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_VertexArray; + std::shared_ptr m_VertexBuffer; + std::shared_ptr m_IndexBuffer; + std::shared_ptr m_Shader; + static Application* s_Instance; }; } \ No newline at end of file diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp index 13025cf..440aeb1 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,15 @@ namespace Donut } glfwMakeContextCurrent(m_Window); + + // Initialize GLAD + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + std::cout << "Failed to initialize GLAD!" << std::endl; + glfwTerminate(); + return; + } + glfwSetWindowUserPointer(m_Window, this); glfwSetErrorCallback(GLFWErrorCallback); -- cgit v1.3