#include "canvas/Sun.hpp" #include "sunShader.hpp" #include "Math.hpp" #include #include void Sun::init() { #if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) shader = LoadShaderFromMemory(0, (const char *)shaders_sun_100_fs); #else shader = LoadShaderFromMemory(0, (const char *)shaders_sun_330_fs); #endif target = LoadRenderTexture(sizeTexute, sizeTexute); sun_radius_loc = GetShaderLocation(shader, "sun_radius"); SetShaderValue(shader, sun_radius_loc, &sun_radius, SHADER_UNIFORM_FLOAT); start_transperency_loc = GetShaderLocation(shader, "start_transperency"); SetShaderValue(shader, start_transperency_loc, &start_transperency, SHADER_UNIFORM_FLOAT); colorLoc = GetShaderLocation(shader, "color"); SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3); // resitev da ne postane tekstura okoli sonca transparentna in da se ne vidi nasledna slika // https://github.com/raysan5/raylib/issues/3820 rlSetBlendFactorsSeparate(RL_SRC_ALPHA, RL_ONE_MINUS_SRC_ALPHA, RL_ONE, RL_ONE, RL_FUNC_ADD, RL_MAX); } void Sun::deinit() { UnloadShader(shader); UnloadRenderTexture(target); } void Sun::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) { Rectangle dest = {x - size, y - size, size * 2, size * 2}; // zgorni komentar da se mesanje barv oklopi pravilno BeginBlendMode(RL_BLEND_CUSTOM_SEPARATE); BeginShaderMode(shader); drawTexureWithRotation(target, dest, 0.0f); EndShaderMode(); EndBlendMode(); }