summaryrefslogtreecommitdiff
path: root/frontend/_shared
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-03-17 23:10:55 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-03-17 23:10:55 -0400
commitc29a911cd1a3f23f66478f205cace14487aadc56 (patch)
tree43308a2b186314c74e04441f5470a652cf607540 /frontend/_shared
parent1a08dd2bd6839f0be4b12dc5317ab0b00ca23ae1 (diff)
Beginning to build out the orthographic renderer, and updated styles
Diffstat (limited to 'frontend/_shared')
-rw-r--r--frontend/_shared/OrthographicRenderer.cpp76
-rw-r--r--frontend/_shared/OrthographicRenderer.cpp~0
-rw-r--r--frontend/_shared/OrthographicRenderer.h41
-rw-r--r--frontend/_shared/OrthographicRenderer.h~5
-rw-r--r--frontend/_shared/types.h16
-rw-r--r--frontend/_shared/types.h~6
6 files changed, 144 insertions, 0 deletions
diff --git a/frontend/_shared/OrthographicRenderer.cpp b/frontend/_shared/OrthographicRenderer.cpp
new file mode 100644
index 0000000..9dc9892
--- /dev/null
+++ b/frontend/_shared/OrthographicRenderer.cpp
@@ -0,0 +1,76 @@
+#include "OrthographicRenderer.h"
+
+const char* orthographicVertex =
+"attribute vec2 position; \n"
+"attribute vec4 color; \n"
+"uniform mat4 projection; \n"
+"uniform mat4 model; \n"
+"varying lowp vec4 VertexColor; \n"
+"void main() { \n"
+" vec4 fragmentPosition = projection * model * vec4(position, 1, 1); \n"
+" gl_Position = fragmentPosition; \n"
+" VertexColor = color; \n"
+"}";
+
+const char* orthographicFragment =
+"varying lowp vec4 VertexColor; \n"
+"void main() { \n"
+" gl_FragColor = VertexColor; \n"
+"}";
+
+void OrthographicRenderer::load() {
+ printf("Compiling orthographic...\n");
+ shader = loadShader(orthographicVertex, orthographicFragment);
+
+ useShader(shader);
+ attributes.position = getShaderAttribute(shader, "position");
+ attributes.color = getShaderAttribute(shader, "color");
+ uniforms.projection = getShaderUniform(shader, "projection");
+ uniforms.model = getShaderUniform(shader, "model");
+
+ printf("Orthographic compiled.\n");
+}
+
+void OrthographicRenderer::render() {
+ useShader(shader);
+ setShaderMat4(uniforms.projection, projection);
+}
+
+void OrthographicRenderer::unload() {
+ glDeleteProgram(shader);
+}
+
+template <uint32 N>
+void OrthographicShape::load(OrthographicRenderer* renderer) {
+ useShader(renderer->shader);
+
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+
+ glGenBuffeloadrs(1, &vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ glBufferData(GL_ARRAY_BUFFER, N * sizeof(OrthographicVertex), &vertices[0], GL_STATIC_DRAW);
+
+ glEnableVerloadtexAttribArray(renderer->attributes.position);
+ glVertexAttribPointer(attributes.position, 2, GL_FLOAT, GL_FALSE, sizeof(OrthographicVertex), (GLvoid *)0);
+
+ glEnableVertexAttribArray(renderer->attributes.color);
+ glVertexAttribPointer(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::render(OrthographicRenderer* renderer) {
+ setShaderMat4(renderer->uniforms.model, model);
+
+ glBindVertexArray(vao);
+ glDrawArrays(GL_TRIANGLES, 0, 3);
+ glBindVertexArray(0);
+}
+
+void OrthographicShape::unload() {
+ glDeleteVertexArrays(1, &vao);
+ gDeleteBuffers(1, &vbo);
+}
diff --git a/frontend/_shared/OrthographicRenderer.cpp~ b/frontend/_shared/OrthographicRenderer.cpp~
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/frontend/_shared/OrthographicRenderer.cpp~
diff --git a/frontend/_shared/OrthographicRenderer.h b/frontend/_shared/OrthographicRenderer.h
new file mode 100644
index 0000000..e04b5ec
--- /dev/null
+++ b/frontend/_shared/OrthographicRenderer.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include "types.h"
+#include "Shader.h"
+#include "mathlib.h"
+
+struct OrthographicRenderer {
+ Mat4x4 projection;
+ uint32 shader;
+
+ struct {
+ int32 position;
+ int32 color;
+ } attributes;
+
+ struct {
+ int32 projection;
+ int32 model;
+ } uniforms;
+
+ void load();
+ void render();
+ void unload();
+};
+
+struct OrthographicVertex {
+ Vector2 position;
+ Vector2 color;
+};
+
+template <uint32 N>
+struct OrthographicShape {
+ uint32 vao;
+ uint32 vbo;
+ OrthographicVertex vertices[N];
+ Mat4x4 model;
+
+ void load(OrthographicRenderer* renderer);
+ void render(OrthographicRenderer* renderer);
+ void unload();
+};
diff --git a/frontend/_shared/OrthographicRenderer.h~ b/frontend/_shared/OrthographicRenderer.h~
new file mode 100644
index 0000000..52f7326
--- /dev/null
+++ b/frontend/_shared/OrthographicRenderer.h~
@@ -0,0 +1,5 @@
+#pragma once
+
+struct OrthographicShader {
+
+};
diff --git a/frontend/_shared/types.h b/frontend/_shared/types.h
new file mode 100644
index 0000000..39d6c17
--- /dev/null
+++ b/frontend/_shared/types.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <cstdint>
+
+typedef int8 int8_t;
+typedef int16 int16_t;
+typedef int32 int32_t;
+typedef int64 int64_t;
+
+typedef uint8 uint8_t;
+typedef uint16 uint16_t;
+typedef uint32 uint32_t;
+typedef uint64 uint;
+
+typedef float32 float;
+typedef float64 double;
diff --git a/frontend/_shared/types.h~ b/frontend/_shared/types.h~
new file mode 100644
index 0000000..e092046
--- /dev/null
+++ b/frontend/_shared/types.h~
@@ -0,0 +1,6 @@
+#include <cstdint>
+
+typedef uint8 uint8_t;
+typedef uint8 uint16_t;
+typedef uint8 uint32_t;
+typedef uint64 uint;