diff --git a/inc/canvas/BackGround.hpp b/inc/canvas/BackGround.hpp index 321754e..403a67e 100644 --- a/inc/canvas/BackGround.hpp +++ b/inc/canvas/BackGround.hpp @@ -1,6 +1,5 @@ #include -#include "canvas/Sun.hpp" #include "values/Dna.hpp" #include @@ -25,8 +24,6 @@ private: uint128 mountenSeed; uint128 starSeed; - Sun sun; - int canvasSize = 0; constexpr static size_t numOfStarts = 150; diff --git a/inc/canvas/Circle.hpp b/inc/canvas/Circle.hpp new file mode 100644 index 0000000..73958c5 --- /dev/null +++ b/inc/canvas/Circle.hpp @@ -0,0 +1,26 @@ +#include + +class Circle +{ +public: + static void init(); + static void deinit(); + static void setColor(Color color); + static void setSoftEdge(bool soft); + static void draw(float x, float y, float size); + + Circle() = delete; + +private: + static const int sizeTexute = 250; + static RenderTexture2D target; + static Shader shader; + + static float radius; + static float start_transperency; + static float c[3]; + + static int radius_loc; + static int start_transperency_loc; + static int colorLoc; +}; diff --git a/inc/canvas/Sun.hpp b/inc/canvas/Sun.hpp deleted file mode 100644 index 7366d79..0000000 --- a/inc/canvas/Sun.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -class Sun -{ -public: - Sun() = default; - ~Sun() = default; - void init(); - void deinit(); - void setColor(Color color); - void draw(float x, float y, float size); -private: - const int sizeTexute = 250; - RenderTexture2D target = { 0 }; - Shader shader = { 0 }; - - float sun_radius = 0.60f; - float start_transperency = 0.40f; - float c[3] = { 240.0f / 255.0f, 240.0f / 255.0f, 190.0f / 255.0f }; - - int sun_radius_loc = 0; - int start_transperency_loc = 0; - int colorLoc = 0; -}; - - diff --git a/src/canvas/BackGround.cpp b/src/canvas/BackGround.cpp index 0c38c45..955caf4 100644 --- a/src/canvas/BackGround.cpp +++ b/src/canvas/BackGround.cpp @@ -2,6 +2,7 @@ #include "canvas/BackGround.hpp" #include "canvas/BackGroundColors.hpp" +#include "canvas/Circle.hpp" #include "Math.hpp" #include "values/mrand.hpp" @@ -13,12 +14,10 @@ void BackGround::init(int canvasSize) { this->canvasSize = canvasSize; - sun.init(); } void BackGround::deinit() { - sun.deinit(); } void BackGround::draw(Dna *dna) @@ -93,7 +92,7 @@ void BackGround::drawSun() if (m_dna->colorSet == 3) { - sun.setColor(BackGroundColors::moonColor); + Circle::setColor(BackGroundColors::moonColor); r = ((m_dna->moon.size * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize; } else @@ -104,9 +103,9 @@ void BackGround::drawSun() color.b = std::lerp(50, 0, m_dna->moon.y); color.a = 255; - sun.setColor(color); + Circle::setColor(color); } - sun.draw(xpos, ypos, r); + Circle::draw(xpos, ypos, r); } void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color color) diff --git a/src/canvas/Canvas.cpp b/src/canvas/Canvas.cpp index 7d4dd6c..4ef1c14 100644 --- a/src/canvas/Canvas.cpp +++ b/src/canvas/Canvas.cpp @@ -1,9 +1,11 @@ #include "canvas/Canvas.hpp" +#include "canvas/Circle.hpp" void Canvas::init(int size) { backGround.init(size); tree.init(size); + Circle::init(); } void Canvas::newGen(RenderTexture2D &target, Dna *dna) @@ -20,4 +22,5 @@ void Canvas::newGen(RenderTexture2D &target, Dna *dna) void Canvas::deinit() { backGround.deinit(); + Circle::deinit(); } diff --git a/src/canvas/Sun.cpp b/src/canvas/Circle.cpp similarity index 57% rename from src/canvas/Sun.cpp rename to src/canvas/Circle.cpp index b299168..c222553 100644 --- a/src/canvas/Sun.cpp +++ b/src/canvas/Circle.cpp @@ -1,4 +1,4 @@ -#include "canvas/Sun.hpp" +#include "canvas/Circle.hpp" #include "sunShader.hpp" #include "Math.hpp" @@ -6,7 +6,16 @@ #include #include -void Sun::init() +RenderTexture2D Circle::target; +Shader Circle::shader; +float Circle::radius; +float Circle::start_transperency; +float Circle::c[3]; +int Circle::radius_loc; +int Circle::start_transperency_loc; +int Circle::colorLoc; + +void Circle::init() { #if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) shader = LoadShaderFromMemory(0, (const char *)shaders_sun_100_fs); @@ -15,12 +24,17 @@ void Sun::init() #endif target = LoadRenderTexture(sizeTexute, sizeTexute); - sun_radius_loc = GetShaderLocation(shader, "sun_radius"); - SetShaderValue(shader, sun_radius_loc, &sun_radius, SHADER_UNIFORM_FLOAT); + radius = 0.6f; + radius_loc = GetShaderLocation(shader, "sun_radius"); + SetShaderValue(shader, radius_loc, &radius, SHADER_UNIFORM_FLOAT); + start_transperency = 0.40f; start_transperency_loc = GetShaderLocation(shader, "start_transperency"); SetShaderValue(shader, start_transperency_loc, &start_transperency, SHADER_UNIFORM_FLOAT); + c[0] = 1.0f; + c[1] = 1.0f; + c[2] = 1.0f; colorLoc = GetShaderLocation(shader, "color"); SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3); @@ -29,28 +43,43 @@ void Sun::init() rlSetBlendFactorsSeparate(RL_SRC_ALPHA, RL_ONE_MINUS_SRC_ALPHA, RL_ONE, RL_ONE, RL_FUNC_ADD, RL_MAX); } -void Sun::deinit() +void Circle::deinit() { UnloadShader(shader); UnloadRenderTexture(target); } -void Sun::setColor(Color color) +void Circle::setColor(Color color) { c[0] = color.r / 255.0f; c[1] = color.g / 255.0f; c[2] = color.b / 255.0f; - colorLoc = GetShaderLocation(shader, "color"); SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3); } -void Sun::draw(float x, float y, float size) +void Circle::setSoftEdge(bool soft) +{ + if (soft) + { + radius = 0.6f; + } + else + { + radius = 1.0f; + } + SetShaderValue(shader, radius_loc, &radius, SHADER_UNIFORM_FLOAT); +} + +void Circle::draw(float x, float y, float size) { Rectangle dest = {x - size, y - size, size * 2, size * 2}; + Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height}; + Vector2 origin = {0.0f, 0.0f}; + // zgorni komentar da se mesanje barv oklopi pravilno BeginBlendMode(RL_BLEND_CUSTOM_SEPARATE); BeginShaderMode(shader); - drawTexureWithRotation(target, dest, 0.0f); + DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE); EndShaderMode(); EndBlendMode(); -} +} \ No newline at end of file diff --git a/src/values/Dna.cpp b/src/values/Dna.cpp index edd0bc5..206f4e3 100644 --- a/src/values/Dna.cpp +++ b/src/values/Dna.cpp @@ -7,7 +7,7 @@ void newDna(Dna &dna) { dna.moon = {mrand::getFloat(), mrand::getFloat(), mrand::getFloat()}; dna.colorSet = mrand::getValue(0, 3); - dna.time = std::floor(Remap(mrand::getFloat(), 0, 1, 4, 0)); + dna.time = std::floor(Remap(dna.moon.y, 0, 1, 4, 0)); dna.mountenSeed.a = mrand::getInt(); dna.mountenSeed.b = mrand::getInt();