summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xthemes/dist/output.wasmbin147546 -> 149889 bytes
-rw-r--r--themes/src/Renderer2d.cpp8
-rw-r--r--themes/src/Renderer2d.h2
-rw-r--r--themes/src/autumn/AutumnTheme.cpp12
-rw-r--r--themes/src/autumn/AutumnTheme.hpp5
-rw-r--r--themes/src/shapes_2d.cpp39
-rw-r--r--themes/src/shapes_2d.h29
7 files changed, 93 insertions, 2 deletions
diff --git a/themes/dist/output.wasm b/themes/dist/output.wasm
index c5c2a1a..24cbd12 100755
--- a/themes/dist/output.wasm
+++ b/themes/dist/output.wasm
Binary files differ
diff --git a/themes/src/Renderer2d.cpp b/themes/src/Renderer2d.cpp
index 196ef7e..f1d78e3 100644
--- a/themes/src/Renderer2d.cpp
+++ b/themes/src/Renderer2d.cpp
@@ -48,6 +48,14 @@ void Renderer2d::unload() {
glDeleteProgram(shader);
}
+f32 Renderer2d::get_width() {
+ return context->width;
+}
+
+f32 Renderer2d::get_height() {
+ return context->height;
+}
+
void Mesh2D::load(Vertex2D* inVertices, u32 inNumVertices, Renderer2d* renderer) {
ebo = 0;
diff --git a/themes/src/Renderer2d.h b/themes/src/Renderer2d.h
index 56b79fc..7432894 100644
--- a/themes/src/Renderer2d.h
+++ b/themes/src/Renderer2d.h
@@ -32,6 +32,8 @@ struct Renderer2d {
void load(WebglContext* context, const char* vertexShader = NULL, const char* fragmentShader = NULL);
void render();
void unload();
+ f32 get_width();
+ f32 get_height();
};
struct Vertex2D {
diff --git a/themes/src/autumn/AutumnTheme.cpp b/themes/src/autumn/AutumnTheme.cpp
index 6e6fe2b..754a841 100644
--- a/themes/src/autumn/AutumnTheme.cpp
+++ b/themes/src/autumn/AutumnTheme.cpp
@@ -1,10 +1,18 @@
#include "AutumnTheme.hpp"
#include "../Renderer2d.h"
+#include "../shapes_2d.h"
+#include <memory>
void AutumnTheme::load(Renderer2d* renderer) {
renderer->clearColor = Vector4(252, 210, 153, 255).toNormalizedColor();
auto lr = tree.load(renderer);
leafParticles.load(renderer, &lr);
+ background = new RectangularGradient(*renderer,
+ Vector4{135, 206, 235, 255}.toNormalizedColor(),
+ Vector4(252, 210, 153, 255).toNormalizedColor(),
+ renderer->get_width(),
+ renderer->get_height(),
+ {0, 0});
}
void AutumnTheme::update(f32 dtSeconds) {
@@ -13,6 +21,7 @@ void AutumnTheme::update(f32 dtSeconds) {
}
void AutumnTheme::render(Renderer2d* renderer) {
+ background->render();
tree.render(renderer);
leafParticles.render(renderer);
}
@@ -20,4 +29,5 @@ void AutumnTheme::render(Renderer2d* renderer) {
void AutumnTheme::unload() {
tree.unload();
leafParticles.unload();
-} \ No newline at end of file
+ delete background;
+}
diff --git a/themes/src/autumn/AutumnTheme.hpp b/themes/src/autumn/AutumnTheme.hpp
index 18da959..7c1f4f2 100644
--- a/themes/src/autumn/AutumnTheme.hpp
+++ b/themes/src/autumn/AutumnTheme.hpp
@@ -4,12 +4,15 @@
#include "TreeShape.h"
#include "LeafParticleRender.h"
#include "../types.h"
+#include <memory>
struct Renderer2d;
+class RectangularGradient;
struct AutumnTheme {
TreeShape tree;
LeafParticleRender leafParticles;
+ RectangularGradient* background;
void load(Renderer2d* renderer);
void update(f32 dtSeconds);
@@ -17,4 +20,4 @@ struct AutumnTheme {
void unload();
};
-#endif \ No newline at end of file
+#endif
diff --git a/themes/src/shapes_2d.cpp b/themes/src/shapes_2d.cpp
new file mode 100644
index 0000000..a85e0da
--- /dev/null
+++ b/themes/src/shapes_2d.cpp
@@ -0,0 +1,39 @@
+#include "shapes_2d.h"
+#include "Renderer2d.h"
+#include "mathlib.h"
+
+RectangularGradient::RectangularGradient(Renderer2d& renderer,
+ Vector4 top,
+ Vector4 bottom,
+ f32 width,
+ f32 height,
+ Vector2 position)
+ : renderer{renderer},
+ top{top},
+ bottom{bottom},
+ width{width},
+ height{height}
+{
+ Vertex2D vertices[6];
+ vertices[0].position = position;
+ vertices[0].color = bottom;
+ vertices[1].position = { position.x + width, position.y };
+ vertices[1].color = bottom;
+ vertices[2].position = { position.x, position.y + height };
+ vertices[2].color = top;
+ vertices[3] = vertices[2];
+ vertices[4] = vertices[1];
+ vertices[5].position = { position.x + width, position.y + height };
+ vertices[5].color = top;
+ mesh.load(vertices, 6, &renderer);
+}
+
+RectangularGradient::~RectangularGradient()
+{
+ mesh.unload();
+}
+
+void RectangularGradient::render()
+{
+ mesh.render(&renderer);
+}
diff --git a/themes/src/shapes_2d.h b/themes/src/shapes_2d.h
new file mode 100644
index 0000000..acb8522
--- /dev/null
+++ b/themes/src/shapes_2d.h
@@ -0,0 +1,29 @@
+#ifndef SHAPES_2D
+#define SHAPES_2D
+
+#include "mathlib.h"
+#include "Renderer2d.h"
+#include "types.h"
+
+class RectangularGradient
+{
+ public:
+ RectangularGradient(Renderer2d& renderer,
+ Vector4 top,
+ Vector4 bottom,
+ f32 width,
+ f32 height,
+ Vector2 position);
+ ~RectangularGradient();
+ void render();
+
+ private:
+ Renderer2d& renderer;
+ Vector4 top;
+ Vector4 bottom;
+ f32 width;
+ f32 height;
+ Mesh2D mesh;
+};
+
+#endif