diff options
author | mattkae <mattkae@protonmail.com> | 2023-04-03 06:35:27 -0400 |
---|---|---|
committer | mattkae <mattkae@protonmail.com> | 2023-04-03 06:35:27 -0400 |
commit | 5d3ff36045bfb11af0f373d5ecee7c9b54e4c4f9 (patch) | |
tree | 1877c85fc652603312c1093ff31678ab807616b2 /themes/src/summer | |
parent | 9e21251ea16e594c8ef416cf8a6b8ebbbb42a858 (diff) |
Folderized all of the seasons and loading the shaders from a remote source
Diffstat (limited to 'themes/src/summer')
-rw-r--r-- | themes/src/summer/SummerTheme.cpp | 67 | ||||
-rw-r--r-- | themes/src/summer/SummerTheme.h | 23 |
2 files changed, 90 insertions, 0 deletions
diff --git a/themes/src/summer/SummerTheme.cpp b/themes/src/summer/SummerTheme.cpp new file mode 100644 index 0000000..406cd22 --- /dev/null +++ b/themes/src/summer/SummerTheme.cpp @@ -0,0 +1,67 @@ +#include "SummerTheme.h" +#include "../Renderer2d.h" +#include "../list.h" +#include "../mathlib.h" +#include <vector> + +void SummerTheme::load(Renderer2d* renderer) { + renderer->clearColor = Vector4(0, 181, 286, 255.f).toNormalizedColor(); + sun.sectors = 180; + sun.radius = renderer->context->width / 4.f; + sun.load(renderer); +} + +void SummerTheme::update(f32 dtSeconds) { + sun.update(dtSeconds); +} + +void SummerTheme::render(Renderer2d* renderer) { + sun.render(renderer); +} + +void SummerTheme::unload() { + sun.unload(); +} + +void Sun::load(Renderer2d* renderer) { + matte::List<Vertex2D> vertices; + matte::List<u32> indices; + Vector4 sunColor = Vector4(249, 215, 28, 255).toNormalizedColor(); + vertices.add({ Vector2(0, 0), sunColor, Mat4x4() }); + + f32 radiansPerSector = (2.f * PI) / sectors; + for (i32 i = 0; i <= sectors; i++) { + f32 radians = radiansPerSector * i; + f32 cosAngle = cosf(radians); + f32 sinAngle = sinf(radians); + Vector2 vertex = Vector2(radius * cosAngle, radius * sinAngle); + vertices.add({ vertex, sunColor, Mat4x4() }); + + u32 first = i; + u32 second = 0; + u32 third = i + 1; + indices.add(first); + indices.add(second); + indices.add(third); + } + + mesh.load(&vertices.data[0], vertices.numElements, &indices.data[0], indices.numElements, renderer); + mesh.model = Mat4x4().translateByVec2(Vector2(renderer->context->width / 2.f, renderer->context->height / 2.f)); + vertices.deallocate(); + indices.deallocate(); +} + +void Sun::update(f32 dtSeconds) { + +} + +void Sun::render(Renderer2d* renderer) { + setShaderMat4(renderer->uniforms.model, mesh.model); + glBindVertexArray(mesh.vao); + glDrawElements(GL_TRIANGLES, mesh.numIndices, GL_UNSIGNED_INT, 0); + glBindVertexArray(0); +} + +void Sun::unload() { + mesh.unload(); +} diff --git a/themes/src/summer/SummerTheme.h b/themes/src/summer/SummerTheme.h new file mode 100644 index 0000000..4a9f76b --- /dev/null +++ b/themes/src/summer/SummerTheme.h @@ -0,0 +1,23 @@ +#pragma once +#include "../types.h" +#include "../Renderer2d.h" +#include <vector> + +struct Sun { + f32 radius = 20.f; + i32 sectors = 180; + Mesh2D mesh; + + void load(Renderer2d* renderer); + void update(f32 dtSeconds); + void render(Renderer2d* renderer); + void unload(); +}; + +struct SummerTheme { + Sun sun; + void load(Renderer2d* renderer); + void update(f32 dtSeconds); + void render(Renderer2d* renderer); + void unload(); +}; |