From cc8bbef4bc8257b65757396e4431e2ca9b5f30ff Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 9 Oct 2022 15:11:13 -0400 Subject: At least I have a working sun theme, but this will have to wait until next summer I suppose --- themes/Renderer2d.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'themes/Renderer2d.cpp') diff --git a/themes/Renderer2d.cpp b/themes/Renderer2d.cpp index dacebe3..606b7fc 100644 --- a/themes/Renderer2d.cpp +++ b/themes/Renderer2d.cpp @@ -5,7 +5,7 @@ #include // Note: In the 'transform' attribute, the transform.x is the scale, -// transform.y is the rotation, and transform.zw is the translatiob. +// transform.y is the rotation, and transform.zw is the translation. const char* Vertex2DShader = "attribute vec2 position; \n" "attribute vec4 color; \n" @@ -64,6 +64,7 @@ void Renderer2d::unload() { void Mesh2D::load(Vertex2D* inVertices, u32 inNumVertices, Renderer2d* renderer) { + ebo = 0; numVertices = inNumVertices; useShader(renderer->shader); @@ -89,15 +90,40 @@ void Mesh2D::load(Vertex2D* inVertices, u32 inNumVertices, Renderer2d* renderer) glBindVertexArray(0); } -void Mesh2D::render(Renderer2d* renderer, GLenum drawType) { - setShaderMat4(renderer->uniforms.model, model); +void Mesh2D::load(Vertex2D* vertices, + u32 numVertices, + u32* indices, + u32 inNumIndices, + Renderer2d* renderer) { + load(vertices, numVertices, renderer); glBindVertexArray(vao); - glDrawArrays(drawType, 0, numVertices); + glGenBuffers(1, &ebo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, inNumIndices * sizeof(u32), &indices[0], GL_STATIC_DRAW); + numIndices = inNumIndices; glBindVertexArray(0); } +void Mesh2D::render(Renderer2d* renderer, GLenum drawType) { + setShaderMat4(renderer->uniforms.model, model); + + if (ebo == 0) { + glBindVertexArray(vao); + glDrawArrays(drawType, 0, numVertices); + glBindVertexArray(0); + } + else { + glBindVertexArray(vao); + glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0); + glBindVertexArray(0); + } +} + void Mesh2D::unload() { glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); + if (ebo) { + glDeleteBuffers(1, &ebo); + } } -- cgit v1.2.1