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 | a2ec7dabd48a70ea69623406ddd0f8f97af403c8 (patch) | |
| tree | 52d71b51753b88473607f5e97f8bc15bdb5ad7d3 /src/Core | |
| parent | 16dff443789c7f1461b46ce52966972ae14c042b (diff) | |
[add]: 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 | 10 |
3 files changed, 75 insertions, 2 deletions
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 <iostream> +#include <glm/glm.hpp> +#include <glm/gtc/matrix_transform.hpp> 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>(VertexArray::Create()); + m_VertexBuffer = std::shared_ptr<VertexBuffer>(VertexBuffer::Create(vertices, sizeof(vertices))); + + VertexBufferLayout layout; + layout.Push<float>(3); + layout.Push<float>(4); + m_VertexBuffer->SetLayout(layout); + + m_VertexArray->AddVertexBuffer(m_VertexBuffer); + + m_IndexBuffer = std::shared_ptr<IndexBuffer>(IndexBuffer::Create(indices, 3)); + m_VertexArray->SetIndexBuffer(m_IndexBuffer); + + m_Shader = std::shared_ptr<Shader>(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 @@ -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_VertexArray; + std::shared_ptr<VertexBuffer> m_VertexBuffer; + std::shared_ptr<IndexBuffer> m_IndexBuffer; + std::shared_ptr<Shader> 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 <cstdint> #include <iostream> +#include <glad/glad.h> 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); |
