I'm quite new to Raylib and trying to make a simple snow particle system. I managed to make it as below code and built it. But when I run it, the snowflakes flicker and I can easily notice it.
Here's the snowflake image(png) link.
and below is the captured video of flickering for your reference.
Can anyone please tell me what I'm missing here? Thank you.
#include "raylib.h" #include "raymath.h" const int screenWidth = 640; const int screenHeight = 480; Texture2D texture; typedef struct { Vector2 position; Vector2 velocity; } s_particle; const int number_particles = 400; s_particle particles[number_particles]; void spawn_particle(s_particle* pt) { pt->position.x = GetRandomValue(-screenWidth * 0.4f, screenWidth); pt->position.y = GetRandomValue(-screenHeight * 2, 0); float max = 10000.0f; pt->velocity.x = (float)(GetRandomValue(1, (int)max) / max) * 0.5f; pt->velocity.y = (float)(GetRandomValue(1, (int)max) / max) + 0.8f; } void draw_particle(s_particle pt[]) { for (int i = 0; i < number_particles; i++) { s_particle* particle = &pt[i]; particle->position.x += particle->velocity.x; particle->position.y += particle->velocity.y; if (particle->position.x > screenWidth || particle->position.y > screenHeight) spawn_particle(particle); DrawTexture(texture, particle->position.x, particle->position.y, WHITE); } } int main(void) { InitWindow(screenWidth, screenHeight, "raylib example"); SetTargetFPS(60); texture = LoadTexture("snow.png"); for (int i = 0; i < number_particles; i++) { spawn_particle(&particles[i]); } while (!WindowShouldClose()) { BeginDrawing(); { ClearBackground(BLACK); draw_particle(particles); DrawFPS(0, 0); } EndDrawing(); } UnloadTexture(texture); CloseWindow(); return 0; }