92 lines
2.7 KiB
C
92 lines
2.7 KiB
C
#include <raylib.h>
|
|
|
|
#define WIDTH 800
|
|
#define HEIGHT 600
|
|
|
|
typedef struct
|
|
{
|
|
Vector2 points[6];
|
|
int numPoints;
|
|
float influence;
|
|
} Polygon;
|
|
|
|
Polygon poly = {
|
|
{{WIDTH / 2 + 50, HEIGHT / 2 - 50},
|
|
{WIDTH / 2 + 80, HEIGHT / 2},
|
|
{WIDTH / 2 + 50, HEIGHT / 2 + 50},
|
|
{WIDTH / 2 - 50, HEIGHT / 2 + 50},
|
|
{WIDTH / 2 - 80, HEIGHT / 2},
|
|
{WIDTH / 2 - 50, HEIGHT / 2 - 50}},
|
|
6,
|
|
3000.0f};
|
|
|
|
int main(void)
|
|
{
|
|
InitWindow(WIDTH, HEIGHT, "Wallpaper");
|
|
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
|
SetTargetFPS(60);
|
|
|
|
// initialize shader
|
|
Shader shader = LoadShader("resources/shaders/basic.vs", "resources/shaders/basic.fs");
|
|
|
|
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
|
int mousePosLoc = GetShaderLocation(shader, "mouse_pos");
|
|
int ballRadiusLoc = GetShaderLocation(shader, "ball_radius");
|
|
int polygonPointsLoc = GetShaderLocation(shader, "polygon_points");
|
|
int polygonInfluenceLoc = GetShaderLocation(shader, "polygon_influence");
|
|
|
|
Vector2 resolution = {WIDTH, HEIGHT};
|
|
SetShaderValue(shader, resolutionLoc, &resolution, SHADER_UNIFORM_VEC2);
|
|
|
|
// send ball data
|
|
float ballRadius = 40.0f;
|
|
SetShaderValue(shader, ballRadiusLoc, &ballRadius, SHADER_UNIFORM_FLOAT);
|
|
|
|
// send polygon data
|
|
float polygonInfluence = poly.influence;
|
|
SetShaderValue(shader, polygonInfluenceLoc, &polygonInfluence, SHADER_UNIFORM_FLOAT);
|
|
|
|
float polygonPoints[12];
|
|
for (int i = 0; i < poly.numPoints; i++)
|
|
{
|
|
polygonPoints[i * 2] = poly.points[i].x;
|
|
polygonPoints[i * 2 + 1] = poly.points[i].y;
|
|
}
|
|
SetShaderValueV(shader, polygonPointsLoc, polygonPoints, SHADER_UNIFORM_VEC2, poly.numPoints);
|
|
|
|
// initializee render texture
|
|
RenderTexture2D target = LoadRenderTexture(WIDTH, HEIGHT);
|
|
|
|
while (!WindowShouldClose())
|
|
{
|
|
int screenWidth = GetScreenWidth();
|
|
int screenHeight = GetScreenHeight();
|
|
|
|
if (IsWindowResized())
|
|
{
|
|
UnloadRenderTexture(target);
|
|
target = LoadRenderTexture(screenWidth, screenHeight);
|
|
|
|
Vector2 resolution = {screenWidth, screenHeight};
|
|
SetShaderValue(shader, resolutionLoc, &resolution, SHADER_UNIFORM_VEC2);
|
|
}
|
|
|
|
Vector2 mousePos = GetMousePosition();
|
|
mousePos.y = screenHeight - mousePos.y;
|
|
SetShaderValue(shader, mousePosLoc, &mousePos, SHADER_UNIFORM_VEC2);
|
|
|
|
BeginDrawing();
|
|
|
|
BeginShaderMode(shader);
|
|
DrawTextureRec(target.texture, (Rectangle){0, 0, screenWidth, -screenHeight}, (Vector2){0, 0}, WHITE);
|
|
EndShaderMode();
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
UnloadRenderTexture(target);
|
|
UnloadShader(shader);
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
} |