83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include "canvas/Circle.hpp"
|
|
#include "sunShader.hpp"
|
|
|
|
#include <raylib.h>
|
|
#include <rlgl.h>
|
|
|
|
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, sun_shader_100);
|
|
#else
|
|
shader = LoadShaderFromMemory(0, (const char *)shaders_sun_330_fs);
|
|
#endif
|
|
target = LoadRenderTexture(sizeTexute, sizeTexute);
|
|
|
|
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);
|
|
|
|
// 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 Circle::deinit()
|
|
{
|
|
UnloadShader(shader);
|
|
UnloadRenderTexture(target);
|
|
}
|
|
|
|
void Circle::setColor(Color color)
|
|
{
|
|
c[0] = color.r / 255.0f;
|
|
c[1] = color.g / 255.0f;
|
|
c[2] = color.b / 255.0f;
|
|
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
|
}
|
|
|
|
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);
|
|
DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);
|
|
EndShaderMode();
|
|
EndBlendMode();
|
|
} |