summaryrefslogtreecommitdiff
path: root/frontend/shared_cpp/OrthographicRenderer.h
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-03-23 21:57:51 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-03-23 21:57:51 -0400
commit25e5dd3951e8cc7827761ea8ba2f5206b354d855 (patch)
tree6cea74cdcf8c366b279c357c0403ddcb7f841695 /frontend/shared_cpp/OrthographicRenderer.h
parentc36d05d5aed2f8f7c6342b174692146e2d11c386 (diff)
Working WebGl abstraction layer and build process
Diffstat (limited to 'frontend/shared_cpp/OrthographicRenderer.h')
-rw-r--r--frontend/shared_cpp/OrthographicRenderer.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/frontend/shared_cpp/OrthographicRenderer.h b/frontend/shared_cpp/OrthographicRenderer.h
index e04b5ec..c72639e 100644
--- a/frontend/shared_cpp/OrthographicRenderer.h
+++ b/frontend/shared_cpp/OrthographicRenderer.h
@@ -25,7 +25,7 @@ struct OrthographicRenderer {
struct OrthographicVertex {
Vector2 position;
- Vector2 color;
+ Vector4 color;
};
template <uint32 N>
@@ -39,3 +39,39 @@ struct OrthographicShape {
void render(OrthographicRenderer* renderer);
void unload();
};
+
+template <uint32 N>
+void OrthographicShape<N>::load(OrthographicRenderer* renderer) {
+ useShader(renderer->shader);
+
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+
+ glGenBuffers(1, &vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ glBufferData(GL_ARRAY_BUFFER, N * sizeof(OrthographicVertex), &vertices[0], GL_STATIC_DRAW);
+
+ glEnableVertexAttribArray(renderer->attributes.position);
+ glVertexAttribPointer(renderer->attributes.position, 2, GL_FLOAT, GL_FALSE, sizeof(OrthographicVertex), (GLvoid *)0);
+
+ glEnableVertexAttribArray(renderer->attributes.color);
+ glVertexAttribPointer(renderer->attributes.color, 4, GL_FLOAT, GL_FALSE, sizeof(OrthographicVertex), (GLvoid *)offsetof(OrthographicVertex, color));
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindVertexArray(0);
+}
+
+template <uint32 N>
+void OrthographicShape<N>::render(OrthographicRenderer* renderer) {
+ setShaderMat4(renderer->uniforms.model, model);
+
+ glBindVertexArray(vao);
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+ glBindVertexArray(0);
+}
+
+template <uint32 N>
+void OrthographicShape<N>::unload() {
+ glDeleteVertexArrays(1, &vao);
+ glDeleteBuffers(1, &vbo);
+} \ No newline at end of file