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/Platform/OpenGL/OpenGLRendererAPI.cpp | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Platform/OpenGL/OpenGLRendererAPI.cpp (limited to 'src/Platform/OpenGL/OpenGLRendererAPI.cpp') diff --git a/src/Platform/OpenGL/OpenGLRendererAPI.cpp b/src/Platform/OpenGL/OpenGLRendererAPI.cpp new file mode 100644 index 0000000..c1c2e9b --- /dev/null +++ b/src/Platform/OpenGL/OpenGLRendererAPI.cpp @@ -0,0 +1,34 @@ +#include "OpenGLRendererAPI.h" +#include + +namespace Donut +{ + void OpenGLRendererAPI::Init() + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_DEPTH_TEST); + } + + void OpenGLRendererAPI::SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) + { + glViewport(x, y, width, height); + } + + void OpenGLRendererAPI::SetClearColor(const glm::vec4& color) + { + glClearColor(color.r, color.g, color.b, color.a); + } + + void OpenGLRendererAPI::Clear() + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + void OpenGLRendererAPI::DrawIndexed(const std::shared_ptr& vertexArray, uint32_t indexCount) + { + uint32_t count = indexCount ? indexCount : vertexArray->GetIndexBuffer()->GetCount(); + glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr); + glBindTexture(GL_TEXTURE_2D, 0); + } +}; -- cgit v1.3