summaryrefslogtreecommitdiff
path: root/frontend/shared_cpp
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/shared_cpp')
-rw-r--r--frontend/shared_cpp/OrthographicRenderer.cpp45
-rw-r--r--frontend/shared_cpp/OrthographicRenderer.h38
-rw-r--r--frontend/shared_cpp/WebglContext.h2
-rw-r--r--frontend/shared_cpp/types.h20
4 files changed, 56 insertions, 49 deletions
diff --git a/frontend/shared_cpp/OrthographicRenderer.cpp b/frontend/shared_cpp/OrthographicRenderer.cpp
index 9dc9892..d160ecc 100644
--- a/frontend/shared_cpp/OrthographicRenderer.cpp
+++ b/frontend/shared_cpp/OrthographicRenderer.cpp
@@ -19,7 +19,7 @@ const char* orthographicFragment =
"}";
void OrthographicRenderer::load() {
- printf("Compiling orthographic...\n");
+ printf("Compiling orthographic shader...\n");
shader = loadShader(orthographicVertex, orthographicFragment);
useShader(shader);
@@ -28,10 +28,16 @@ void OrthographicRenderer::load() {
uniforms.projection = getShaderUniform(shader, "projection");
uniforms.model = getShaderUniform(shader, "model");
- printf("Orthographic compiled.\n");
+ printf("Orthographic shader compiled.\n");
}
void OrthographicRenderer::render() {
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LEQUAL);
+ glDepthMask(GL_TRUE);
+ glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
+ glClearDepth(1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
useShader(shader);
setShaderMat4(uniforms.projection, projection);
}
@@ -39,38 +45,3 @@ void OrthographicRenderer::render() {
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_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
diff --git a/frontend/shared_cpp/WebglContext.h b/frontend/shared_cpp/WebglContext.h
index cf9cce2..c8a9480 100644
--- a/frontend/shared_cpp/WebglContext.h
+++ b/frontend/shared_cpp/WebglContext.h
@@ -15,7 +15,7 @@ struct WebglContext {
attrs.majorVersion = 3;
attrs.minorVersion = 0;
- context = emscripten_webgl_create_context( "#wasm_canvas", &attrs );
+ context = emscripten_webgl_create_context(query, &attrs);
makeCurrentContext();
};
diff --git a/frontend/shared_cpp/types.h b/frontend/shared_cpp/types.h
index 39d6c17..7bac7f3 100644
--- a/frontend/shared_cpp/types.h
+++ b/frontend/shared_cpp/types.h
@@ -2,15 +2,15 @@
#include <cstdint>
-typedef int8 int8_t;
-typedef int16 int16_t;
-typedef int32 int32_t;
-typedef int64 int64_t;
+typedef int8_t int8;
+typedef int16_t int16;
+typedef int32_t int32;
+typedef int64_t int64;
-typedef uint8 uint8_t;
-typedef uint16 uint16_t;
-typedef uint32 uint32_t;
-typedef uint64 uint;
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef uint32_t uint32;
+typedef unsigned long uint64;
-typedef float32 float;
-typedef float64 double;
+typedef float float32;
+typedef double float64;