From b4d28cc7a1a0d9f5ce0c556535c612e67215bd18 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 16 Apr 2017 19:08:19 +0200 Subject: Working on examples... - Removed rbmf font example - Reviewed physac examples --- examples/textures/textures_particles_blending.c | 135 ++++++++++++++++++++++ examples/textures/textures_particles_blending.png | Bin 0 -> 421110 bytes 2 files changed, 135 insertions(+) create mode 100644 examples/textures/textures_particles_blending.c create mode 100644 examples/textures/textures_particles_blending.png (limited to 'examples/textures') diff --git a/examples/textures/textures_particles_blending.c b/examples/textures/textures_particles_blending.c new file mode 100644 index 00000000..842ac77d --- /dev/null +++ b/examples/textures/textures_particles_blending.c @@ -0,0 +1,135 @@ +/******************************************************************************************* +* +* raylib example - particles blending +* +* This example has been created using raylib 1.7 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2017 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_PARTICLES 200 + +// Particle structure with basic data +typedef struct { + Vector2 position; + Color color; + float alpha; + float size; + float rotation; + bool active; // NOTE: Use it to activate/deactive particle +} Particle; + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); + + // Particles pool, reuse them! + Particle mouseTail[MAX_PARTICLES]; + + // Initialize particles + for (int i = 0; i < MAX_PARTICLES; i++) + { + mouseTail[i].position = (Vector2){ 0, 0 }; + mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 }; + mouseTail[i].alpha = 1.0f; + mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f; + mouseTail[i].rotation = GetRandomValue(0, 360); + mouseTail[i].active = false; + } + + float gravity = 3.0f; + + Texture2D smoke = LoadTexture("resources/smoke.png"); + + int blending = BLEND_ALPHA; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + + // Activate one particle every frame and Update active particles + // NOTE: Particles initial position should be mouse position when activated + // NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0) + // NOTE: When a particle disappears, active = false and it can be reused. + for (int i = 0; i < MAX_PARTICLES; i++) + { + if (!mouseTail[i].active) + { + mouseTail[i].active = true; + mouseTail[i].alpha = 1.0f; + mouseTail[i].position = GetMousePosition(); + i = MAX_PARTICLES; + } + } + + for (int i = 0; i < MAX_PARTICLES; i++) + { + if (mouseTail[i].active) + { + mouseTail[i].position.y += gravity; + mouseTail[i].alpha -= 0.01f; + + if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false; + + mouseTail[i].rotation += 5.0f; + } + } + + if (IsKeyPressed(KEY_SPACE)) + { + if (blending == BLEND_ALPHA) blending = BLEND_ADDITIVE; + else blending = BLEND_ALPHA; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(DARKGRAY); + + BeginBlendMode(blending); + + // Draw active particles + for (int i = 0; i < MAX_PARTICLES; i++) + { + if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0, 0, smoke.width, smoke.height }, + (Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size }, + (Vector2){ smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2 }, mouseTail[i].rotation, + Fade(mouseTail[i].color, mouseTail[i].alpha)); + } + + EndBlendMode(); + + DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, BLACK); + + if (blending == BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, BLACK); + else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(smoke); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/textures/textures_particles_blending.png b/examples/textures/textures_particles_blending.png new file mode 100644 index 00000000..f90a87fd Binary files /dev/null and b/examples/textures/textures_particles_blending.png differ -- cgit v1.2.3 From 1df7a8b4a6833d0589470f42db97cc7a423dca0b Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 20 Apr 2017 18:09:30 +0200 Subject: Update some files --- docs/examples/web/textures/resources/scarfy.png | Bin 21597 -> 33146 bytes examples/textures/resources/scarfy.png | Bin 21597 -> 33146 bytes src/textures.c | 2 ++ 3 files changed, 2 insertions(+) (limited to 'examples/textures') diff --git a/docs/examples/web/textures/resources/scarfy.png b/docs/examples/web/textures/resources/scarfy.png index a377a712..beb5ffa0 100644 Binary files a/docs/examples/web/textures/resources/scarfy.png and b/docs/examples/web/textures/resources/scarfy.png differ diff --git a/examples/textures/resources/scarfy.png b/examples/textures/resources/scarfy.png index a377a712..beb5ffa0 100644 Binary files a/examples/textures/resources/scarfy.png and b/examples/textures/resources/scarfy.png differ diff --git a/src/textures.c b/src/textures.c index 9fd5944e..af95f9dc 100644 --- a/src/textures.c +++ b/src/textures.c @@ -379,6 +379,8 @@ Texture2D LoadTextureFromImage(Image image) texture.height = image.height; texture.mipmaps = image.mipmaps; texture.format = image.format; + + TraceLog(INFO, "[TEX %i] Parameters: %ix%i, %i mips, format %i", texture.width, texture.height, texture.mipmaps, texture.format); return texture; } -- cgit v1.2.3 From 8d3750e36d970d86507e6556bb2c61ee83e45e47 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 20 Apr 2017 23:26:16 +0200 Subject: Turn transparent pixels to black --- examples/shaders/resources/fudesumi.png | Bin 219234 -> 222742 bytes examples/textures/resources/fudesumi.png | Bin 219234 -> 222742 bytes examples/textures/resources/fudesumi.raw | Bin 786432 -> 786432 bytes 3 files changed, 0 insertions(+), 0 deletions(-) (limited to 'examples/textures') diff --git a/examples/shaders/resources/fudesumi.png b/examples/shaders/resources/fudesumi.png index 8ba983dc..9d9038fa 100644 Binary files a/examples/shaders/resources/fudesumi.png and b/examples/shaders/resources/fudesumi.png differ diff --git a/examples/textures/resources/fudesumi.png b/examples/textures/resources/fudesumi.png index 8ba983dc..9d9038fa 100644 Binary files a/examples/textures/resources/fudesumi.png and b/examples/textures/resources/fudesumi.png differ diff --git a/examples/textures/resources/fudesumi.raw b/examples/textures/resources/fudesumi.raw index e05fa0e1..dad6ff0a 100644 Binary files a/examples/textures/resources/fudesumi.raw and b/examples/textures/resources/fudesumi.raw differ -- cgit v1.2.3