feat: rotating stars
BIN
resources/textures/background_no_stars.png
Normal file
|
After Width: | Height: | Size: 7.9 MiB |
BIN
resources/textures/star_1.png
Normal file
|
After Width: | Height: | Size: 386 KiB |
BIN
resources/textures/star_2.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
resources/textures/star_3.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
resources/textures/star_4.png
Normal file
|
After Width: | Height: | Size: 386 KiB |
BIN
resources/textures/star_5.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
BIN
resources/textures/star_6.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
@@ -8,10 +8,31 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define WIDTH 1920
|
#define WIDTH 1920
|
||||||
#define HEIGHT 1080
|
#define HEIGHT 1080
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* name;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int cx;
|
||||||
|
int cy;
|
||||||
|
float angle;
|
||||||
|
float angle_step;
|
||||||
|
} Star;
|
||||||
|
|
||||||
|
static Star stars[] = {
|
||||||
|
{ .name = "star_1.png", .x = 4, .y = 528, .cx = 165, .cy = 166, .angle = 90.0, .angle_step = -0.025 },
|
||||||
|
{ .name = "star_2.png", .x = 215, .y = 809, .cx = 82, .cy = 83, .angle = 90.0, .angle_step = 0.05 },
|
||||||
|
{ .name = "star_3.png", .x = 333, .y = 781, .cx = 25, .cy = 31, .angle = 90.0, .angle_step = 0.15 },
|
||||||
|
{ .name = "star_4.png", .x = 956, .y = 405, .cx = 166, .cy = 167, .angle = 90.0, .angle_step = -0.1 },
|
||||||
|
{ .name = "star_5.png", .x = 1164, .y = 570, .cx = 66, .cy = 70, .angle = 90.0, .angle_step = 0.075 },
|
||||||
|
};
|
||||||
|
|
||||||
|
#define STARS_COUNT (int)(sizeof(stars) / sizeof(stars[0]))
|
||||||
|
|
||||||
char *hyprland_socket_path;
|
char *hyprland_socket_path;
|
||||||
|
|
||||||
Vector2 hyprland_get_cursor_position() {
|
Vector2 hyprland_get_cursor_position() {
|
||||||
@@ -113,9 +134,14 @@ int main(void) {
|
|||||||
|
|
||||||
// initialize textures
|
// initialize textures
|
||||||
Texture2D distanceFieldTex = load_texture_from_file("resources/textures/background_distance_field.png");
|
Texture2D distanceFieldTex = load_texture_from_file("resources/textures/background_distance_field.png");
|
||||||
Texture2D backgroundTex = load_texture_from_file("resources/textures/background_transparent.png");
|
Texture2D backgroundTex = load_texture_from_file("resources/textures/background_no_stars.png");
|
||||||
RenderTexture2D target = LoadRenderTexture(WIDTH, HEIGHT);
|
RenderTexture2D target = LoadRenderTexture(WIDTH, HEIGHT);
|
||||||
|
|
||||||
|
Texture2D starTextures[STARS_COUNT];
|
||||||
|
for (int i = 0; i < STARS_COUNT; i++) {
|
||||||
|
starTextures[i] = load_texture_from_file(TextFormat("resources/textures/%s", stars[i].name));
|
||||||
|
}
|
||||||
|
|
||||||
// initialize shader
|
// initialize shader
|
||||||
Shader shader = load_shader_from_file("resources/shaders/basic.vs", "resources/shaders/distance_field.fs");
|
Shader shader = load_shader_from_file("resources/shaders/basic.vs", "resources/shaders/distance_field.fs");
|
||||||
|
|
||||||
@@ -165,12 +191,25 @@ int main(void) {
|
|||||||
|
|
||||||
DrawTextureRec(backgroundTex, (Rectangle){0, 0, screenWidth, screenHeight}, (Vector2){0, 0}, WHITE);
|
DrawTextureRec(backgroundTex, (Rectangle){0, 0, screenWidth, screenHeight}, (Vector2){0, 0}, WHITE);
|
||||||
|
|
||||||
|
for (int i = 0; i < STARS_COUNT; i++) {
|
||||||
|
stars[i].angle = fmodf(stars[i].angle + stars[i].angle_step, 360.0f);
|
||||||
|
|
||||||
|
Texture2D tex = starTextures[i];
|
||||||
|
Rectangle source = {0, 0, (float)tex.width, (float)tex.height};
|
||||||
|
Rectangle dest = {stars[i].x, stars[i].y, (float)tex.width, (float)tex.height};
|
||||||
|
Vector2 origin = {stars[i].cx, stars[i].cy};
|
||||||
|
DrawTexturePro(tex, source, dest, origin, stars[i].angle, WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadRenderTexture(target);
|
UnloadRenderTexture(target);
|
||||||
UnloadTexture(distanceFieldTex);
|
UnloadTexture(distanceFieldTex);
|
||||||
UnloadTexture(backgroundTex);
|
UnloadTexture(backgroundTex);
|
||||||
|
for (int i = 0; i < STARS_COUNT; i++) {
|
||||||
|
UnloadTexture(starTextures[i]);
|
||||||
|
}
|
||||||
UnloadShader(shader);
|
UnloadShader(shader);
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
|
|||||||