diff options
author | bonmas14 <bonmas14@gmail.com> | 2025-09-20 22:28:15 +0300 |
---|---|---|
committer | bonmas14 <bonmas14@gmail.com> | 2025-09-20 22:28:15 +0300 |
commit | cdda4c4182c9ee068567529715e4a5c68a8efb58 (patch) | |
tree | 38a63f62a64018a2d35fc33354f8589fd33b7514 /deps/raylib/examples/textures | |
download | c_wizard-cdda4c4182c9ee068567529715e4a5c68a8efb58.tar.gz c_wizard-cdda4c4182c9ee068567529715e4a5c68a8efb58.zip |
Init commit v1.0
Diffstat (limited to 'deps/raylib/examples/textures')
74 files changed, 3253 insertions, 0 deletions
diff --git a/deps/raylib/examples/textures/resources/KAISG.ttf b/deps/raylib/examples/textures/resources/KAISG.ttf Binary files differnew file mode 100644 index 0000000..04478b2 --- /dev/null +++ b/deps/raylib/examples/textures/resources/KAISG.ttf diff --git a/deps/raylib/examples/textures/resources/LICENSE.md b/deps/raylib/examples/textures/resources/LICENSE.md new file mode 100644 index 0000000..e4ee453 --- /dev/null +++ b/deps/raylib/examples/textures/resources/LICENSE.md @@ -0,0 +1,18 @@ +| resource | author | licence | notes | +| :------------------- | :---------: | :------ | :---- | +| boom.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) | +| buttonfx.wav | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) | +| button.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [rFXGen](https://raylibtech.itch.io/rfxgen) | +| spark_flame.png | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | Made with [EffectTextureMaker](https://mebiusbox.github.io/contents/EffectTextureMaker/) | +| ninepatch_button.png | [@overdev](https://github.com/overdev) | ❔ | +| explosion.png | [Unity Labs Paris](https://blogs.unity3d.com/2016/11/28/free-vfx-image-sequences-flipbooks/) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | +| parrots.png | [Kodak set](http://r0k.us/graphics/kodak/) | ❔ | Original name: `kodim23.png` +| cat.png | ❔ | ❔ | - | +| wabbit_alpha.png | ❔ | ❔ | - | +| custom_jupiter_crash.png | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | +| KAISG.ttf | [Dieter Steffmann](http://www.steffmann.de/wordpress/) | [Freeware](https://www.1001fonts.com/users/steffmann/) | [Kaiserzeit Gotisch](https://www.dafont.com/es/kaiserzeit-gotisch.font) font | +| fudesumi.png | [Eiden Marsal](https://www.artstation.com/marshall_z) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/) | - | +| scarfy.png | [Eiden Marsal](https://www.artstation.com/marshall_z) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/legalcode) | - | +| cyberpunk_street_background.png | [Luis Zuno](http://ansimuz.com/site/) | [CC-BY-3.0](http://creativecommons.org/licenses/by/3.0/) | [Cyberpunk Street Environment](https://ansimuz.itch.io/cyberpunk-street-environment) | +| cyberpunk_street_foreground.png | [Luis Zuno](http://ansimuz.com/site/) | [CC-BY-3.0](http://creativecommons.org/licenses/by/3.0/) | [Cyberpunk Street Environment](https://ansimuz.itch.io/cyberpunk-street-environment) | +| cyberpunk_street_midground.png | [Luis Zuno](http://ansimuz.com/site/) | [CC-BY-3.0](http://creativecommons.org/licenses/by/3.0/) | [Cyberpunk Street Environment](https://ansimuz.itch.io/cyberpunk-street-environment) | diff --git a/deps/raylib/examples/textures/resources/boom.wav b/deps/raylib/examples/textures/resources/boom.wav Binary files differnew file mode 100644 index 0000000..fd18137 --- /dev/null +++ b/deps/raylib/examples/textures/resources/boom.wav diff --git a/deps/raylib/examples/textures/resources/button.png b/deps/raylib/examples/textures/resources/button.png Binary files differnew file mode 100644 index 0000000..99a383b --- /dev/null +++ b/deps/raylib/examples/textures/resources/button.png diff --git a/deps/raylib/examples/textures/resources/buttonfx.wav b/deps/raylib/examples/textures/resources/buttonfx.wav Binary files differnew file mode 100644 index 0000000..b93b0ca --- /dev/null +++ b/deps/raylib/examples/textures/resources/buttonfx.wav diff --git a/deps/raylib/examples/textures/resources/cat.png b/deps/raylib/examples/textures/resources/cat.png Binary files differnew file mode 100644 index 0000000..db56b9e --- /dev/null +++ b/deps/raylib/examples/textures/resources/cat.png diff --git a/deps/raylib/examples/textures/resources/custom_jupiter_crash.png b/deps/raylib/examples/textures/resources/custom_jupiter_crash.png Binary files differnew file mode 100644 index 0000000..c89572e --- /dev/null +++ b/deps/raylib/examples/textures/resources/custom_jupiter_crash.png diff --git a/deps/raylib/examples/textures/resources/cyberpunk_street_background.png b/deps/raylib/examples/textures/resources/cyberpunk_street_background.png Binary files differnew file mode 100644 index 0000000..838d08a --- /dev/null +++ b/deps/raylib/examples/textures/resources/cyberpunk_street_background.png diff --git a/deps/raylib/examples/textures/resources/cyberpunk_street_foreground.png b/deps/raylib/examples/textures/resources/cyberpunk_street_foreground.png Binary files differnew file mode 100644 index 0000000..528b4ae --- /dev/null +++ b/deps/raylib/examples/textures/resources/cyberpunk_street_foreground.png diff --git a/deps/raylib/examples/textures/resources/cyberpunk_street_midground.png b/deps/raylib/examples/textures/resources/cyberpunk_street_midground.png Binary files differnew file mode 100644 index 0000000..73f24fe --- /dev/null +++ b/deps/raylib/examples/textures/resources/cyberpunk_street_midground.png diff --git a/deps/raylib/examples/textures/resources/explosion.png b/deps/raylib/examples/textures/resources/explosion.png Binary files differnew file mode 100644 index 0000000..6df1cf3 --- /dev/null +++ b/deps/raylib/examples/textures/resources/explosion.png diff --git a/deps/raylib/examples/textures/resources/fudesumi.png b/deps/raylib/examples/textures/resources/fudesumi.png Binary files differnew file mode 100644 index 0000000..c77c287 --- /dev/null +++ b/deps/raylib/examples/textures/resources/fudesumi.png diff --git a/deps/raylib/examples/textures/resources/fudesumi.raw b/deps/raylib/examples/textures/resources/fudesumi.raw Binary files differnew file mode 100644 index 0000000..dad6ff0 --- /dev/null +++ b/deps/raylib/examples/textures/resources/fudesumi.raw diff --git a/deps/raylib/examples/textures/resources/ninepatch_button.png b/deps/raylib/examples/textures/resources/ninepatch_button.png Binary files differnew file mode 100644 index 0000000..f10037a --- /dev/null +++ b/deps/raylib/examples/textures/resources/ninepatch_button.png diff --git a/deps/raylib/examples/textures/resources/parrots.png b/deps/raylib/examples/textures/resources/parrots.png Binary files differnew file mode 100644 index 0000000..9a0e7f8 --- /dev/null +++ b/deps/raylib/examples/textures/resources/parrots.png diff --git a/deps/raylib/examples/textures/resources/patterns.png b/deps/raylib/examples/textures/resources/patterns.png Binary files differnew file mode 100644 index 0000000..58b3c37 --- /dev/null +++ b/deps/raylib/examples/textures/resources/patterns.png diff --git a/deps/raylib/examples/textures/resources/raylib_logo.png b/deps/raylib/examples/textures/resources/raylib_logo.png Binary files differnew file mode 100644 index 0000000..15bbaa2 --- /dev/null +++ b/deps/raylib/examples/textures/resources/raylib_logo.png diff --git a/deps/raylib/examples/textures/resources/road.png b/deps/raylib/examples/textures/resources/road.png Binary files differnew file mode 100644 index 0000000..082f4cd --- /dev/null +++ b/deps/raylib/examples/textures/resources/road.png diff --git a/deps/raylib/examples/textures/resources/scarfy.png b/deps/raylib/examples/textures/resources/scarfy.png Binary files differnew file mode 100644 index 0000000..be3b83d --- /dev/null +++ b/deps/raylib/examples/textures/resources/scarfy.png diff --git a/deps/raylib/examples/textures/resources/scarfy_run.gif b/deps/raylib/examples/textures/resources/scarfy_run.gif Binary files differnew file mode 100644 index 0000000..f0f712c --- /dev/null +++ b/deps/raylib/examples/textures/resources/scarfy_run.gif diff --git a/deps/raylib/examples/textures/resources/spark_flame.png b/deps/raylib/examples/textures/resources/spark_flame.png Binary files differnew file mode 100644 index 0000000..72cea2e --- /dev/null +++ b/deps/raylib/examples/textures/resources/spark_flame.png diff --git a/deps/raylib/examples/textures/resources/wabbit_alpha.png b/deps/raylib/examples/textures/resources/wabbit_alpha.png Binary files differnew file mode 100644 index 0000000..db4081f --- /dev/null +++ b/deps/raylib/examples/textures/resources/wabbit_alpha.png diff --git a/deps/raylib/examples/textures/textures_background_scrolling.c b/deps/raylib/examples/textures/textures_background_scrolling.c new file mode 100644 index 0000000..0df159c --- /dev/null +++ b/deps/raylib/examples/textures/textures_background_scrolling.c @@ -0,0 +1,92 @@ +/******************************************************************************************* +* +* raylib [textures] example - Background scrolling +* +* Example originally created with raylib 2.0, last time updated with raylib 2.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling"); + + // NOTE: Be careful, background width must be equal or bigger than screen width + // if not, texture should be draw more than two times for scrolling effect + Texture2D background = LoadTexture("resources/cyberpunk_street_background.png"); + Texture2D midground = LoadTexture("resources/cyberpunk_street_midground.png"); + Texture2D foreground = LoadTexture("resources/cyberpunk_street_foreground.png"); + + float scrollingBack = 0.0f; + float scrollingMid = 0.0f; + float scrollingFore = 0.0f; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + scrollingBack -= 0.1f; + scrollingMid -= 0.5f; + scrollingFore -= 1.0f; + + // NOTE: Texture is scaled twice its size, so it sould be considered on scrolling + if (scrollingBack <= -background.width*2) scrollingBack = 0; + if (scrollingMid <= -midground.width*2) scrollingMid = 0; + if (scrollingFore <= -foreground.width*2) scrollingFore = 0; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(GetColor(0x052c46ff)); + + // Draw background image twice + // NOTE: Texture is scaled twice its size + DrawTextureEx(background, (Vector2){ scrollingBack, 20 }, 0.0f, 2.0f, WHITE); + DrawTextureEx(background, (Vector2){ background.width*2 + scrollingBack, 20 }, 0.0f, 2.0f, WHITE); + + // Draw midground image twice + DrawTextureEx(midground, (Vector2){ scrollingMid, 20 }, 0.0f, 2.0f, WHITE); + DrawTextureEx(midground, (Vector2){ midground.width*2 + scrollingMid, 20 }, 0.0f, 2.0f, WHITE); + + // Draw foreground image twice + DrawTextureEx(foreground, (Vector2){ scrollingFore, 70 }, 0.0f, 2.0f, WHITE); + DrawTextureEx(foreground, (Vector2){ foreground.width*2 + scrollingFore, 70 }, 0.0f, 2.0f, WHITE); + + DrawText("BACKGROUND SCROLLING & PARALLAX", 10, 10, 20, RED); + DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, RAYWHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(background); // Unload background texture + UnloadTexture(midground); // Unload midground texture + UnloadTexture(foreground); // Unload foreground texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_background_scrolling.png b/deps/raylib/examples/textures/textures_background_scrolling.png Binary files differnew file mode 100644 index 0000000..d21e269 --- /dev/null +++ b/deps/raylib/examples/textures/textures_background_scrolling.png diff --git a/deps/raylib/examples/textures/textures_blend_modes.c b/deps/raylib/examples/textures/textures_blend_modes.c new file mode 100644 index 0000000..d97432c --- /dev/null +++ b/deps/raylib/examples/textures/textures_blend_modes.c @@ -0,0 +1,101 @@ +/******************************************************************************************* +* +* raylib [textures] example - blend modes +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 3.5, last time updated with raylib 3.5 +* +* Example contributed by Karlo Licudine (@accidentalrebel) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2020-2024 Karlo Licudine (@accidentalrebel) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - blend modes"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Image bgImage = LoadImage("resources/cyberpunk_street_background.png"); // Loaded in CPU memory (RAM) + Texture2D bgTexture = LoadTextureFromImage(bgImage); // Image converted to texture, GPU memory (VRAM) + + Image fgImage = LoadImage("resources/cyberpunk_street_foreground.png"); // Loaded in CPU memory (RAM) + Texture2D fgTexture = LoadTextureFromImage(fgImage); // Image converted to texture, GPU memory (VRAM) + + // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + UnloadImage(bgImage); + UnloadImage(fgImage); + + const int blendCountMax = 4; + BlendMode blendMode = 0; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_SPACE)) + { + if (blendMode >= (blendCountMax - 1)) blendMode = 0; + else blendMode++; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(bgTexture, screenWidth/2 - bgTexture.width/2, screenHeight/2 - bgTexture.height/2, WHITE); + + // Apply the blend mode and then draw the foreground texture + BeginBlendMode(blendMode); + DrawTexture(fgTexture, screenWidth/2 - fgTexture.width/2, screenHeight/2 - fgTexture.height/2, WHITE); + EndBlendMode(); + + // Draw the texts + DrawText("Press SPACE to change blend modes.", 310, 350, 10, GRAY); + + switch (blendMode) + { + case BLEND_ALPHA: DrawText("Current: BLEND_ALPHA", (screenWidth / 2) - 60, 370, 10, GRAY); break; + case BLEND_ADDITIVE: DrawText("Current: BLEND_ADDITIVE", (screenWidth / 2) - 60, 370, 10, GRAY); break; + case BLEND_MULTIPLIED: DrawText("Current: BLEND_MULTIPLIED", (screenWidth / 2) - 60, 370, 10, GRAY); break; + case BLEND_ADD_COLORS: DrawText("Current: BLEND_ADD_COLORS", (screenWidth / 2) - 60, 370, 10, GRAY); break; + default: break; + } + + DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(fgTexture); // Unload foreground texture + UnloadTexture(bgTexture); // Unload background texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_blend_modes.png b/deps/raylib/examples/textures/textures_blend_modes.png Binary files differnew file mode 100644 index 0000000..3010ace --- /dev/null +++ b/deps/raylib/examples/textures/textures_blend_modes.png diff --git a/deps/raylib/examples/textures/textures_bunnymark.c b/deps/raylib/examples/textures/textures_bunnymark.c new file mode 100644 index 0000000..f3ef694 --- /dev/null +++ b/deps/raylib/examples/textures/textures_bunnymark.c @@ -0,0 +1,125 @@ +/******************************************************************************************* +* +* raylib [textures] example - Bunnymark +* +* Example originally created with raylib 1.6, last time updated with raylib 2.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include <stdlib.h> // Required for: malloc(), free() + +#define MAX_BUNNIES 50000 // 50K bunnies limit + +// This is the maximum amount of elements (quads) per batch +// NOTE: This value is defined in [rlgl] module and can be changed there +#define MAX_BATCH_ELEMENTS 8192 + +typedef struct Bunny { + Vector2 position; + Vector2 speed; + Color color; +} Bunny; + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark"); + + // Load bunny texture + Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); + + Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array + + int bunniesCount = 0; // Bunnies counter + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) + { + // Create more bunnies + for (int i = 0; i < 100; i++) + { + if (bunniesCount < MAX_BUNNIES) + { + bunnies[bunniesCount].position = GetMousePosition(); + bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f; + bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240), + GetRandomValue(80, 240), + GetRandomValue(100, 240), 255 }; + bunniesCount++; + } + } + } + + // Update bunnies + for (int i = 0; i < bunniesCount; i++) + { + bunnies[i].position.x += bunnies[i].speed.x; + bunnies[i].position.y += bunnies[i].speed.y; + + if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) || + ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1; + if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) || + ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + for (int i = 0; i < bunniesCount; i++) + { + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // a draw call is launched and buffer starts being filled again; + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // Process of sending data is costly and it could happen that GPU data has not been completely + // processed for drawing while new data is tried to be sent (updating current in-use buffers) + // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies + DrawTexture(texBunny, (int)bunnies[i].position.x, (int)bunnies[i].position.y, bunnies[i].color); + } + + DrawRectangle(0, 0, screenWidth, 40, BLACK); + DrawText(TextFormat("bunnies: %i", bunniesCount), 120, 10, 20, GREEN); + DrawText(TextFormat("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + free(bunnies); // Unload bunnies data array + + UnloadTexture(texBunny); // Unload bunny texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_bunnymark.png b/deps/raylib/examples/textures/textures_bunnymark.png Binary files differnew file mode 100644 index 0000000..4431cce --- /dev/null +++ b/deps/raylib/examples/textures/textures_bunnymark.png diff --git a/deps/raylib/examples/textures/textures_draw_tiled.c b/deps/raylib/examples/textures/textures_draw_tiled.c new file mode 100644 index 0000000..6998365 --- /dev/null +++ b/deps/raylib/examples/textures/textures_draw_tiled.c @@ -0,0 +1,256 @@ +/******************************************************************************************* +* +* raylib [textures] example - Draw part of the texture tiled +* +* Example originally created with raylib 3.0, last time updated with raylib 4.2 +* +* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2020-2024 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define SIZEOF(A) (sizeof(A)/sizeof(A[0])) +#define OPT_WIDTH 220 // Max width for the options container +#define MARGIN_SIZE 8 // Size for the margins +#define COLOR_SIZE 16 // Size of the color select buttons + +// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest. +void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable + InitWindow(screenWidth, screenHeight, "raylib [textures] example - Draw part of a texture tiled"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture texPattern = LoadTexture("resources/patterns.png"); + SetTextureFilter(texPattern, TEXTURE_FILTER_TRILINEAR); // Makes the texture smoother when upscaled + + // Coordinates for all patterns inside the texture + const Rectangle recPattern[] = { + (Rectangle){ 3, 3, 66, 66 }, + (Rectangle){ 75, 3, 100, 100 }, + (Rectangle){ 3, 75, 66, 66 }, + (Rectangle){ 7, 156, 50, 50 }, + (Rectangle){ 85, 106, 90, 45 }, + (Rectangle){ 75, 154, 100, 60} + }; + + // Setup colors + const Color colors[] = { BLACK, MAROON, ORANGE, BLUE, PURPLE, BEIGE, LIME, RED, DARKGRAY, SKYBLUE }; + enum { MAX_COLORS = SIZEOF(colors) }; + Rectangle colorRec[MAX_COLORS] = { 0 }; + + // Calculate rectangle for each color + for (int i = 0, x = 0, y = 0; i < MAX_COLORS; i++) + { + colorRec[i].x = 2.0f + MARGIN_SIZE + x; + colorRec[i].y = 22.0f + 256.0f + MARGIN_SIZE + y; + colorRec[i].width = COLOR_SIZE*2.0f; + colorRec[i].height = (float)COLOR_SIZE; + + if (i == (MAX_COLORS/2 - 1)) + { + x = 0; + y += COLOR_SIZE + MARGIN_SIZE; + } + else x += (COLOR_SIZE*2 + MARGIN_SIZE); + } + + int activePattern = 0, activeCol = 0; + float scale = 1.0f, rotation = 0.0f; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Handle mouse + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + { + const Vector2 mouse = GetMousePosition(); + + // Check which pattern was clicked and set it as the active pattern + for (int i = 0; i < SIZEOF(recPattern); i++) + { + if (CheckCollisionPointRec(mouse, (Rectangle){ 2 + MARGIN_SIZE + recPattern[i].x, 40 + MARGIN_SIZE + recPattern[i].y, recPattern[i].width, recPattern[i].height })) + { + activePattern = i; + break; + } + } + + // Check to see which color was clicked and set it as the active color + for (int i = 0; i < MAX_COLORS; ++i) + { + if (CheckCollisionPointRec(mouse, colorRec[i])) + { + activeCol = i; + break; + } + } + } + + // Handle keys + + // Change scale + if (IsKeyPressed(KEY_UP)) scale += 0.25f; + if (IsKeyPressed(KEY_DOWN)) scale -= 0.25f; + if (scale > 10.0f) scale = 10.0f; + else if ( scale <= 0.0f) scale = 0.25f; + + // Change rotation + if (IsKeyPressed(KEY_LEFT)) rotation -= 25.0f; + if (IsKeyPressed(KEY_RIGHT)) rotation += 25.0f; + + // Reset + if (IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + ClearBackground(RAYWHITE); + + // Draw the tiled area + DrawTextureTiled(texPattern, recPattern[activePattern], (Rectangle){(float)OPT_WIDTH+MARGIN_SIZE, (float)MARGIN_SIZE, GetScreenWidth() - OPT_WIDTH - 2.0f*MARGIN_SIZE, GetScreenHeight() - 2.0f*MARGIN_SIZE}, + (Vector2){0.0f, 0.0f}, rotation, scale, colors[activeCol]); + + // Draw options + DrawRectangle(MARGIN_SIZE, MARGIN_SIZE, OPT_WIDTH - MARGIN_SIZE, GetScreenHeight() - 2*MARGIN_SIZE, ColorAlpha(LIGHTGRAY, 0.5f)); + + DrawText("Select Pattern", 2 + MARGIN_SIZE, 30 + MARGIN_SIZE, 10, BLACK); + DrawTexture(texPattern, 2 + MARGIN_SIZE, 40 + MARGIN_SIZE, BLACK); + DrawRectangle(2 + MARGIN_SIZE + (int)recPattern[activePattern].x, 40 + MARGIN_SIZE + (int)recPattern[activePattern].y, (int)recPattern[activePattern].width, (int)recPattern[activePattern].height, ColorAlpha(DARKBLUE, 0.3f)); + + DrawText("Select Color", 2+MARGIN_SIZE, 10+256+MARGIN_SIZE, 10, BLACK); + for (int i = 0; i < MAX_COLORS; i++) + { + DrawRectangleRec(colorRec[i], colors[i]); + if (activeCol == i) DrawRectangleLinesEx(colorRec[i], 3, ColorAlpha(WHITE, 0.5f)); + } + + DrawText("Scale (UP/DOWN to change)", 2 + MARGIN_SIZE, 80 + 256 + MARGIN_SIZE, 10, BLACK); + DrawText(TextFormat("%.2fx", scale), 2 + MARGIN_SIZE, 92 + 256 + MARGIN_SIZE, 20, BLACK); + + DrawText("Rotation (LEFT/RIGHT to change)", 2 + MARGIN_SIZE, 122 + 256 + MARGIN_SIZE, 10, BLACK); + DrawText(TextFormat("%.0f degrees", rotation), 2 + MARGIN_SIZE, 134 + 256 + MARGIN_SIZE, 20, BLACK); + + DrawText("Press [SPACE] to reset", 2 + MARGIN_SIZE, 164 + 256 + MARGIN_SIZE, 10, DARKBLUE); + + // Draw FPS + DrawText(TextFormat("%i FPS", GetFPS()), 2 + MARGIN_SIZE, 2 + MARGIN_SIZE, 20, BLACK); + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texPattern); // Unload texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest. +void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint) +{ + if ((texture.id <= 0) || (scale <= 0.0f)) return; // Wanna see a infinite loop?!...just delete this line! + if ((source.width == 0) || (source.height == 0)) return; + + int tileWidth = (int)(source.width*scale), tileHeight = (int)(source.height*scale); + if ((dest.width < tileWidth) && (dest.height < tileHeight)) + { + // Can fit only one tile + DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)dest.width/tileWidth)*source.width, ((float)dest.height/tileHeight)*source.height}, + (Rectangle){dest.x, dest.y, dest.width, dest.height}, origin, rotation, tint); + } + else if (dest.width <= tileWidth) + { + // Tiled vertically (one column) + int dy = 0; + for (;dy+tileHeight < dest.height; dy += tileHeight) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)dest.width/tileWidth)*source.width, source.height}, (Rectangle){dest.x, dest.y + dy, dest.width, (float)tileHeight}, origin, rotation, tint); + } + + // Fit last tile + if (dy < dest.height) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)dest.width/tileWidth)*source.width, ((float)(dest.height - dy)/tileHeight)*source.height}, + (Rectangle){dest.x, dest.y + dy, dest.width, dest.height - dy}, origin, rotation, tint); + } + } + else if (dest.height <= tileHeight) + { + // Tiled horizontally (one row) + int dx = 0; + for (;dx+tileWidth < dest.width; dx += tileWidth) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, source.width, ((float)dest.height/tileHeight)*source.height}, (Rectangle){dest.x + dx, dest.y, (float)tileWidth, dest.height}, origin, rotation, tint); + } + + // Fit last tile + if (dx < dest.width) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)(dest.width - dx)/tileWidth)*source.width, ((float)dest.height/tileHeight)*source.height}, + (Rectangle){dest.x + dx, dest.y, dest.width - dx, dest.height}, origin, rotation, tint); + } + } + else + { + // Tiled both horizontally and vertically (rows and columns) + int dx = 0; + for (;dx+tileWidth < dest.width; dx += tileWidth) + { + int dy = 0; + for (;dy+tileHeight < dest.height; dy += tileHeight) + { + DrawTexturePro(texture, source, (Rectangle){dest.x + dx, dest.y + dy, (float)tileWidth, (float)tileHeight}, origin, rotation, tint); + } + + if (dy < dest.height) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, source.width, ((float)(dest.height - dy)/tileHeight)*source.height}, + (Rectangle){dest.x + dx, dest.y + dy, (float)tileWidth, dest.height - dy}, origin, rotation, tint); + } + } + + // Fit last column of tiles + if (dx < dest.width) + { + int dy = 0; + for (;dy+tileHeight < dest.height; dy += tileHeight) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)(dest.width - dx)/tileWidth)*source.width, source.height}, + (Rectangle){dest.x + dx, dest.y + dy, dest.width - dx, (float)tileHeight}, origin, rotation, tint); + } + + // Draw final tile in the bottom right corner + if (dy < dest.height) + { + DrawTexturePro(texture, (Rectangle){source.x, source.y, ((float)(dest.width - dx)/tileWidth)*source.width, ((float)(dest.height - dy)/tileHeight)*source.height}, + (Rectangle){dest.x + dx, dest.y + dy, dest.width - dx, dest.height - dy}, origin, rotation, tint); + } + } + } +} diff --git a/deps/raylib/examples/textures/textures_draw_tiled.png b/deps/raylib/examples/textures/textures_draw_tiled.png Binary files differnew file mode 100644 index 0000000..374dc0b --- /dev/null +++ b/deps/raylib/examples/textures/textures_draw_tiled.png diff --git a/deps/raylib/examples/textures/textures_fog_of_war.c b/deps/raylib/examples/textures/textures_fog_of_war.c new file mode 100644 index 0000000..2f72c0d --- /dev/null +++ b/deps/raylib/examples/textures/textures_fog_of_war.c @@ -0,0 +1,155 @@ +/******************************************************************************************* +* +* raylib [textures] example - Fog of war +* +* Example originally created with raylib 4.2, last time updated with raylib 4.2 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2018-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include <stdlib.h> // Required for: calloc(), free() + +#define MAP_TILE_SIZE 32 // Tiles size 32x32 pixels +#define PLAYER_SIZE 16 // Player size +#define PLAYER_TILE_VISIBILITY 2 // Player can see 2 tiles around its position + +// Map data type +typedef struct Map { + unsigned int tilesX; // Number of tiles in X axis + unsigned int tilesY; // Number of tiles in Y axis + unsigned char *tileIds; // Tile ids (tilesX*tilesY), defines type of tile to draw + unsigned char *tileFog; // Tile fog state (tilesX*tilesY), defines if a tile has fog or half-fog +} Map; + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - fog of war"); + + Map map = { 0 }; + map.tilesX = 25; + map.tilesY = 15; + + // NOTE: We can have up to 256 values for tile ids and for tile fog state, + // probably we don't need that many values for fog state, it can be optimized + // to use only 2 bits per fog state (reducing size by 4) but logic will be a bit more complex + map.tileIds = (unsigned char *)calloc(map.tilesX*map.tilesY, sizeof(unsigned char)); + map.tileFog = (unsigned char *)calloc(map.tilesX*map.tilesY, sizeof(unsigned char)); + + // Load map tiles (generating 2 random tile ids for testing) + // NOTE: Map tile ids should be probably loaded from an external map file + for (unsigned int i = 0; i < map.tilesY*map.tilesX; i++) map.tileIds[i] = GetRandomValue(0, 1); + + // Player position on the screen (pixel coordinates, not tile coordinates) + Vector2 playerPosition = { 180, 130 }; + int playerTileX = 0; + int playerTileY = 0; + + // Render texture to render fog of war + // NOTE: To get an automatic smooth-fog effect we use a render texture to render fog + // at a smaller size (one pixel per tile) and scale it on drawing with bilinear filtering + RenderTexture2D fogOfWar = LoadRenderTexture(map.tilesX, map.tilesY); + SetTextureFilter(fogOfWar.texture, TEXTURE_FILTER_BILINEAR); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Move player around + if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 5; + if (IsKeyDown(KEY_LEFT)) playerPosition.x -= 5; + if (IsKeyDown(KEY_DOWN)) playerPosition.y += 5; + if (IsKeyDown(KEY_UP)) playerPosition.y -= 5; + + // Check player position to avoid moving outside tilemap limits + if (playerPosition.x < 0) playerPosition.x = 0; + else if ((playerPosition.x + PLAYER_SIZE) > (map.tilesX*MAP_TILE_SIZE)) playerPosition.x = (float)map.tilesX*MAP_TILE_SIZE - PLAYER_SIZE; + if (playerPosition.y < 0) playerPosition.y = 0; + else if ((playerPosition.y + PLAYER_SIZE) > (map.tilesY*MAP_TILE_SIZE)) playerPosition.y = (float)map.tilesY*MAP_TILE_SIZE - PLAYER_SIZE; + + // Previous visited tiles are set to partial fog + for (unsigned int i = 0; i < map.tilesX*map.tilesY; i++) if (map.tileFog[i] == 1) map.tileFog[i] = 2; + + // Get current tile position from player pixel position + playerTileX = (int)((playerPosition.x + MAP_TILE_SIZE/2)/MAP_TILE_SIZE); + playerTileY = (int)((playerPosition.y + MAP_TILE_SIZE/2)/MAP_TILE_SIZE); + + // Check visibility and update fog + // NOTE: We check tilemap limits to avoid processing tiles out-of-array-bounds (it could crash program) + for (int y = (playerTileY - PLAYER_TILE_VISIBILITY); y < (playerTileY + PLAYER_TILE_VISIBILITY); y++) + for (int x = (playerTileX - PLAYER_TILE_VISIBILITY); x < (playerTileX + PLAYER_TILE_VISIBILITY); x++) + if ((x >= 0) && (x < (int)map.tilesX) && (y >= 0) && (y < (int)map.tilesY)) map.tileFog[y*map.tilesX + x] = 1; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + // Draw fog of war to a small render texture for automatic smoothing on scaling + BeginTextureMode(fogOfWar); + ClearBackground(BLANK); + for (unsigned int y = 0; y < map.tilesY; y++) + for (unsigned int x = 0; x < map.tilesX; x++) + if (map.tileFog[y*map.tilesX + x] == 0) DrawRectangle(x, y, 1, 1, BLACK); + else if (map.tileFog[y*map.tilesX + x] == 2) DrawRectangle(x, y, 1, 1, Fade(BLACK, 0.8f)); + EndTextureMode(); + + BeginDrawing(); + + ClearBackground(RAYWHITE); + + for (unsigned int y = 0; y < map.tilesY; y++) + { + for (unsigned int x = 0; x < map.tilesX; x++) + { + // Draw tiles from id (and tile borders) + DrawRectangle(x*MAP_TILE_SIZE, y*MAP_TILE_SIZE, MAP_TILE_SIZE, MAP_TILE_SIZE, + (map.tileIds[y*map.tilesX + x] == 0)? BLUE : Fade(BLUE, 0.9f)); + DrawRectangleLines(x*MAP_TILE_SIZE, y*MAP_TILE_SIZE, MAP_TILE_SIZE, MAP_TILE_SIZE, Fade(DARKBLUE, 0.5f)); + } + } + + // Draw player + DrawRectangleV(playerPosition, (Vector2){ PLAYER_SIZE, PLAYER_SIZE }, RED); + + + // Draw fog of war (scaled to full map, bilinear filtering) + DrawTexturePro(fogOfWar.texture, (Rectangle){ 0, 0, (float)fogOfWar.texture.width, (float)-fogOfWar.texture.height }, + (Rectangle){ 0, 0, (float)map.tilesX*MAP_TILE_SIZE, (float)map.tilesY*MAP_TILE_SIZE }, + (Vector2){ 0, 0 }, 0.0f, WHITE); + + // Draw player current tile + DrawText(TextFormat("Current tile: [%i,%i]", playerTileX, playerTileY), 10, 10, 20, RAYWHITE); + DrawText("ARROW KEYS to move", 10, screenHeight-25, 20, RAYWHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + free(map.tileIds); // Free allocated map tile ids + free(map.tileFog); // Free allocated map tile fog state + + UnloadRenderTexture(fogOfWar); // Unload render texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_fog_of_war.png b/deps/raylib/examples/textures/textures_fog_of_war.png Binary files differnew file mode 100644 index 0000000..01563c3 --- /dev/null +++ b/deps/raylib/examples/textures/textures_fog_of_war.png diff --git a/deps/raylib/examples/textures/textures_gif_player.c b/deps/raylib/examples/textures/textures_gif_player.c new file mode 100644 index 0000000..cf8492e --- /dev/null +++ b/deps/raylib/examples/textures/textures_gif_player.c @@ -0,0 +1,121 @@ +/******************************************************************************************* +* +* raylib [textures] example - gif playing +* +* Example originally created with raylib 4.2, last time updated with raylib 4.2 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2021-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_FRAME_DELAY 20 +#define MIN_FRAME_DELAY 1 + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - gif playing"); + + int animFrames = 0; + + // Load all GIF animation frames into a single Image + // NOTE: GIF data is always loaded as RGBA (32bit) by default + // NOTE: Frames are just appended one after another in image.data memory + Image imScarfyAnim = LoadImageAnim("resources/scarfy_run.gif", &animFrames); + + // Load texture from image + // NOTE: We will update this texture when required with next frame data + // WARNING: It's not recommended to use this technique for sprites animation, + // use spritesheets instead, like illustrated in textures_sprite_anim example + Texture2D texScarfyAnim = LoadTextureFromImage(imScarfyAnim); + + unsigned int nextFrameDataOffset = 0; // Current byte offset to next frame in image.data + + int currentAnimFrame = 0; // Current animation frame to load and draw + int frameDelay = 8; // Frame delay to switch between animation frames + int frameCounter = 0; // General frames counter + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + frameCounter++; + if (frameCounter >= frameDelay) + { + // Move to next frame + // NOTE: If final frame is reached we return to first frame + currentAnimFrame++; + if (currentAnimFrame >= animFrames) currentAnimFrame = 0; + + // Get memory offset position for next frame data in image.data + nextFrameDataOffset = imScarfyAnim.width*imScarfyAnim.height*4*currentAnimFrame; + + // Update GPU texture data with next frame image data + // WARNING: Data size (frame size) and pixel format must match already created texture + UpdateTexture(texScarfyAnim, ((unsigned char *)imScarfyAnim.data) + nextFrameDataOffset); + + frameCounter = 0; + } + + // Control frames delay + if (IsKeyPressed(KEY_RIGHT)) frameDelay++; + else if (IsKeyPressed(KEY_LEFT)) frameDelay--; + + if (frameDelay > MAX_FRAME_DELAY) frameDelay = MAX_FRAME_DELAY; + else if (frameDelay < MIN_FRAME_DELAY) frameDelay = MIN_FRAME_DELAY; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText(TextFormat("TOTAL GIF FRAMES: %02i", animFrames), 50, 30, 20, LIGHTGRAY); + DrawText(TextFormat("CURRENT FRAME: %02i", currentAnimFrame), 50, 60, 20, GRAY); + DrawText(TextFormat("CURRENT FRAME IMAGE.DATA OFFSET: %02i", nextFrameDataOffset), 50, 90, 20, GRAY); + + DrawText("FRAMES DELAY: ", 100, 305, 10, DARKGRAY); + DrawText(TextFormat("%02i frames", frameDelay), 620, 305, 10, DARKGRAY); + DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 350, 10, DARKGRAY); + + for (int i = 0; i < MAX_FRAME_DELAY; i++) + { + if (i < frameDelay) DrawRectangle(190 + 21*i, 300, 20, 20, RED); + DrawRectangleLines(190 + 21*i, 300, 20, 20, MAROON); + } + + DrawTexture(texScarfyAnim, GetScreenWidth()/2 - texScarfyAnim.width/2, 140, WHITE); + + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texScarfyAnim); // Unload texture + UnloadImage(imScarfyAnim); // Unload image (contains all frames) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_gif_player.png b/deps/raylib/examples/textures/textures_gif_player.png Binary files differnew file mode 100644 index 0000000..20db76e --- /dev/null +++ b/deps/raylib/examples/textures/textures_gif_player.png diff --git a/deps/raylib/examples/textures/textures_image_channel.c b/deps/raylib/examples/textures/textures_image_channel.c new file mode 100644 index 0000000..39618c5 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_channel.c @@ -0,0 +1,106 @@ +/******************************************************************************************* +* +* raylib [textures] example - Retrive image channel (mask) +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 5.1-dev, last time updated with raylib 5.1-dev +* +* Example contributed by Bruno Cabral (github.com/brccabral) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2024-2024 Bruno Cabral (github.com/brccabral) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include <raylib.h> + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - extract channel from image"); + + Image fudesumiImage = LoadImage("resources/fudesumi.png"); + + Image imageAlpha = ImageFromChannel(fudesumiImage, 3); + ImageAlphaMask(&imageAlpha, imageAlpha); + + Image imageRed = ImageFromChannel(fudesumiImage, 0); + ImageAlphaMask(&imageRed, imageAlpha); + + Image imageGreen = ImageFromChannel(fudesumiImage, 1); + ImageAlphaMask(&imageGreen, imageAlpha); + + Image imageBlue = ImageFromChannel(fudesumiImage, 2); + ImageAlphaMask(&imageBlue, imageAlpha); + + Image backgroundImage = GenImageChecked(screenWidth, screenHeight, screenWidth/20, screenHeight/20, ORANGE, YELLOW); + + Texture2D fudesumiTexture = LoadTextureFromImage(fudesumiImage); + Texture2D textureAlpha = LoadTextureFromImage(imageAlpha); + Texture2D textureRed = LoadTextureFromImage(imageRed); + Texture2D textureGreen = LoadTextureFromImage(imageGreen); + Texture2D textureBlue = LoadTextureFromImage(imageBlue); + Texture2D backgroundTexture = LoadTextureFromImage(backgroundImage); + + UnloadImage(fudesumiImage); + UnloadImage(imageAlpha); + UnloadImage(imageRed); + UnloadImage(imageGreen); + UnloadImage(imageBlue); + UnloadImage(backgroundImage); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + + Rectangle fudesumiRec = {0, 0, fudesumiImage.width, fudesumiImage.height}; + + Rectangle fudesumiPos = {50, 10, fudesumiImage.width*0.8f, fudesumiImage.height*0.8f}; + Rectangle redPos = { 410, 10, fudesumiPos.width / 2, fudesumiPos.height / 2 }; + Rectangle greenPos = { 600, 10, fudesumiPos.width / 2, fudesumiPos.height / 2 }; + Rectangle bluePos = { 410, 230, fudesumiPos.width / 2, fudesumiPos.height / 2 }; + Rectangle alphaPos = { 600, 230, fudesumiPos.width / 2, fudesumiPos.height / 2 }; + + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + DrawTexture(backgroundTexture, 0, 0, WHITE); + DrawTexturePro(fudesumiTexture, fudesumiRec, fudesumiPos, (Vector2) {0, 0}, 0, WHITE); + + DrawTexturePro(textureRed, fudesumiRec, redPos, (Vector2) {0, 0}, 0, RED); + DrawTexturePro(textureGreen, fudesumiRec, greenPos, (Vector2) {0, 0}, 0, GREEN); + DrawTexturePro(textureBlue, fudesumiRec, bluePos, (Vector2) {0, 0}, 0, BLUE); + DrawTexturePro(textureAlpha, fudesumiRec, alphaPos, (Vector2) {0, 0}, 0, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(backgroundTexture); + UnloadTexture(fudesumiTexture); + UnloadTexture(textureRed); + UnloadTexture(textureGreen); + UnloadTexture(textureBlue); + UnloadTexture(textureAlpha); + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_image_channel.png b/deps/raylib/examples/textures/textures_image_channel.png Binary files differnew file mode 100644 index 0000000..55e1d2e --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_channel.png diff --git a/deps/raylib/examples/textures/textures_image_drawing.c b/deps/raylib/examples/textures/textures_image_drawing.c new file mode 100644 index 0000000..d0eee99 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_drawing.c @@ -0,0 +1,96 @@ +/******************************************************************************************* +* +* raylib [textures] example - Image loading and drawing on it +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 1.4, last time updated with raylib 1.4 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2016-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Image cat = LoadImage("resources/cat.png"); // Load image in CPU memory (RAM) + ImageCrop(&cat, (Rectangle){ 100, 10, 280, 380 }); // Crop an image piece + ImageFlipHorizontal(&cat); // Flip cropped image horizontally + ImageResize(&cat, 150, 200); // Resize flipped-cropped image + + Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) + + // Draw one image over the other with a scaling of 1.5f + ImageDraw(&parrots, cat, (Rectangle){ 0, 0, (float)cat.width, (float)cat.height }, (Rectangle){ 30, 40, cat.width*1.5f, cat.height*1.5f }, WHITE); + ImageCrop(&parrots, (Rectangle){ 0, 50, (float)parrots.width, (float)parrots.height - 100 }); // Crop resulting image + + // Draw on the image with a few image draw methods + ImageDrawPixel(&parrots, 10, 10, RAYWHITE); + ImageDrawCircleLines(&parrots, 10, 10, 5, RAYWHITE); + ImageDrawRectangle(&parrots, 5, 20, 10, 10, RAYWHITE); + + UnloadImage(cat); // Unload image from RAM + + // Load custom font for drawing on image + Font font = LoadFont("resources/custom_jupiter_crash.png"); + + // Draw over image using custom font + ImageDrawTextEx(&parrots, font, "PARROTS & CAT", (Vector2){ 300, 230 }, (float)font.baseSize, -2, WHITE); + + UnloadFont(font); // Unload custom font (already drawn used on image) + + Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) + UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, WHITE); + DrawRectangleLines(screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2 - 40, texture.width, texture.height, DARKGRAY); + + DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, DARKGRAY); + DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_image_drawing.png b/deps/raylib/examples/textures/textures_image_drawing.png Binary files differnew file mode 100644 index 0000000..b8107bd --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_drawing.png diff --git a/deps/raylib/examples/textures/textures_image_generation.c b/deps/raylib/examples/textures/textures_image_generation.c new file mode 100644 index 0000000..97e43f0 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_generation.c @@ -0,0 +1,119 @@ +/******************************************************************************************* +* +* raylib [textures] example - Procedural images generation +* +* Example originally created with raylib 1.8, last time updated with raylib 1.8 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2O17-2024 Wilhem Barbier (@nounoursheureux) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_TEXTURES 9 // Currently we have 8 generation algorithms but some have multiple purposes (Linear and Square Gradients) + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - procedural images generation"); + + Image verticalGradient = GenImageGradientLinear(screenWidth, screenHeight, 0, RED, BLUE); + Image horizontalGradient = GenImageGradientLinear(screenWidth, screenHeight, 90, RED, BLUE); + Image diagonalGradient = GenImageGradientLinear(screenWidth, screenHeight, 45, RED, BLUE); + Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK); + Image squareGradient = GenImageGradientSquare(screenWidth, screenHeight, 0.0f, WHITE, BLACK); + Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE); + Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f); + Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f); + Image cellular = GenImageCellular(screenWidth, screenHeight, 32); + + Texture2D textures[NUM_TEXTURES] = { 0 }; + + textures[0] = LoadTextureFromImage(verticalGradient); + textures[1] = LoadTextureFromImage(horizontalGradient); + textures[2] = LoadTextureFromImage(diagonalGradient); + textures[3] = LoadTextureFromImage(radialGradient); + textures[4] = LoadTextureFromImage(squareGradient); + textures[5] = LoadTextureFromImage(checked); + textures[6] = LoadTextureFromImage(whiteNoise); + textures[7] = LoadTextureFromImage(perlinNoise); + textures[8] = LoadTextureFromImage(cellular); + + // Unload image data (CPU RAM) + UnloadImage(verticalGradient); + UnloadImage(horizontalGradient); + UnloadImage(diagonalGradient); + UnloadImage(radialGradient); + UnloadImage(squareGradient); + UnloadImage(checked); + UnloadImage(whiteNoise); + UnloadImage(perlinNoise); + UnloadImage(cellular); + + int currentTexture = 0; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) + { + // Update + //---------------------------------------------------------------------------------- + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_RIGHT)) + { + currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(textures[currentTexture], 0, 0, WHITE); + + DrawRectangle(30, 400, 325, 30, Fade(SKYBLUE, 0.5f)); + DrawRectangleLines(30, 400, 325, 30, Fade(WHITE, 0.5f)); + DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, WHITE); + + switch(currentTexture) + { + case 0: DrawText("VERTICAL GRADIENT", 560, 10, 20, RAYWHITE); break; + case 1: DrawText("HORIZONTAL GRADIENT", 540, 10, 20, RAYWHITE); break; + case 2: DrawText("DIAGONAL GRADIENT", 540, 10, 20, RAYWHITE); break; + case 3: DrawText("RADIAL GRADIENT", 580, 10, 20, LIGHTGRAY); break; + case 4: DrawText("SQUARE GRADIENT", 580, 10, 20, LIGHTGRAY); break; + case 5: DrawText("CHECKED", 680, 10, 20, RAYWHITE); break; + case 6: DrawText("WHITE NOISE", 640, 10, 20, RED); break; + case 7: DrawText("PERLIN NOISE", 640, 10, 20, RED); break; + case 8: DrawText("CELLULAR", 670, 10, 20, RAYWHITE); break; + default: break; + } + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + + // Unload textures data (GPU VRAM) + for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_image_generation.png b/deps/raylib/examples/textures/textures_image_generation.png Binary files differnew file mode 100644 index 0000000..398b046 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_generation.png diff --git a/deps/raylib/examples/textures/textures_image_kernel.c b/deps/raylib/examples/textures/textures_image_kernel.c new file mode 100644 index 0000000..b850b63 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_kernel.c @@ -0,0 +1,130 @@ +/******************************************************************************************* +* +* raylib [textures] example - Image loading and texture creation +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 1.3, last time updated with raylib 1.3 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2015-2024 Karim Salem (@kimo-s) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +void NormalizeKernel(float *kernel, int size) +{ + float sum = 0.0f; + for (int i = 0; i < size; i++) sum += kernel[i]; + + if (sum != 0.0f) + { + for (int i = 0; i < size; i++) kernel[i] /= sum; + } +} + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - image convolution"); + + Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM) + + float gaussiankernel[] = { + 1.0f, 2.0f, 1.0f, + 2.0f, 4.0f, 2.0f, + 1.0f, 2.0f, 1.0f }; + + float sobelkernel[] = { + 1.0f, 0.0f, -1.0f, + 2.0f, 0.0f, -2.0f, + 1.0f, 0.0f, -1.0f }; + + float sharpenkernel[] = { + 0.0f, -1.0f, 0.0f, + -1.0f, 5.0f, -1.0f, + 0.0f, -1.0f, 0.0f }; + + NormalizeKernel(gaussiankernel, 9); + NormalizeKernel(sharpenkernel, 9); + NormalizeKernel(sobelkernel, 9); + + Image catSharpend = ImageCopy(image); + ImageKernelConvolution(&catSharpend, sharpenkernel, 9); + + Image catSobel = ImageCopy(image); + ImageKernelConvolution(&catSobel, sobelkernel, 9); + + Image catGaussian = ImageCopy(image); + + for (int i = 0; i < 6; i++) + { + ImageKernelConvolution(&catGaussian, gaussiankernel, 9); + } + + ImageCrop(&image, (Rectangle){ 0, 0, (float)200, (float)450 }); + ImageCrop(&catGaussian, (Rectangle){ 0, 0, (float)200, (float)450 }); + ImageCrop(&catSobel, (Rectangle){ 0, 0, (float)200, (float)450 }); + ImageCrop(&catSharpend, (Rectangle){ 0, 0, (float)200, (float)450 }); + + // Images converted to texture, GPU memory (VRAM) + Texture2D texture = LoadTextureFromImage(image); + Texture2D catSharpendTexture = LoadTextureFromImage(catSharpend); + Texture2D catSobelTexture = LoadTextureFromImage(catSobel); + Texture2D catGaussianTexture = LoadTextureFromImage(catGaussian); + + // Once images have been converted to texture and uploaded to VRAM, + // they can be unloaded from RAM + UnloadImage(image); + UnloadImage(catGaussian); + UnloadImage(catSobel); + UnloadImage(catSharpend); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(catSharpendTexture, 0, 0, WHITE); + DrawTexture(catSobelTexture, 200, 0, WHITE); + DrawTexture(catGaussianTexture, 400, 0, WHITE); + DrawTexture(texture, 600, 0, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); + UnloadTexture(catGaussianTexture); + UnloadTexture(catSobelTexture); + UnloadTexture(catSharpendTexture); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_image_kernel.png b/deps/raylib/examples/textures/textures_image_kernel.png Binary files differnew file mode 100644 index 0000000..0fb36d1 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_kernel.png diff --git a/deps/raylib/examples/textures/textures_image_loading.c b/deps/raylib/examples/textures/textures_image_loading.c new file mode 100644 index 0000000..95175e0 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_loading.c @@ -0,0 +1,69 @@ +/******************************************************************************************* +* +* raylib [textures] example - Image loading and texture creation +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 1.3, last time updated with raylib 1.3 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM) + Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) + UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); + + DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_image_loading.png b/deps/raylib/examples/textures/textures_image_loading.png Binary files differnew file mode 100644 index 0000000..410103a --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_loading.png diff --git a/deps/raylib/examples/textures/textures_image_processing.c b/deps/raylib/examples/textures/textures_image_processing.c new file mode 100644 index 0000000..2692735 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_processing.c @@ -0,0 +1,177 @@ +/******************************************************************************************* +* +* raylib [textures] example - Image processing +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 1.4, last time updated with raylib 3.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2016-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include <stdlib.h> // Required for: free() + +#define NUM_PROCESSES 9 + +typedef enum { + NONE = 0, + COLOR_GRAYSCALE, + COLOR_TINT, + COLOR_INVERT, + COLOR_CONTRAST, + COLOR_BRIGHTNESS, + GAUSSIAN_BLUR, + FLIP_VERTICAL, + FLIP_HORIZONTAL +} ImageProcess; + +static const char *processText[] = { + "NO PROCESSING", + "COLOR GRAYSCALE", + "COLOR TINT", + "COLOR INVERT", + "COLOR CONTRAST", + "COLOR BRIGHTNESS", + "GAUSSIAN BLUR", + "FLIP VERTICAL", + "FLIP HORIZONTAL" +}; + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Image imOrigin = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM) + ImageFormat(&imOrigin, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE + Texture2D texture = LoadTextureFromImage(imOrigin); // Image converted to texture, GPU memory (VRAM) + + Image imCopy = ImageCopy(imOrigin); + + int currentProcess = NONE; + bool textureReload = false; + + Rectangle toggleRecs[NUM_PROCESSES] = { 0 }; + int mouseHoverRec = -1; + + for (int i = 0; i < NUM_PROCESSES; i++) toggleRecs[i] = (Rectangle){ 40.0f, (float)(50 + 32*i), 150.0f, 30.0f }; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + + // Mouse toggle group logic + for (int i = 0; i < NUM_PROCESSES; i++) + { + if (CheckCollisionPointRec(GetMousePosition(), toggleRecs[i])) + { + mouseHoverRec = i; + + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) + { + currentProcess = i; + textureReload = true; + } + break; + } + else mouseHoverRec = -1; + } + + // Keyboard toggle group logic + if (IsKeyPressed(KEY_DOWN)) + { + currentProcess++; + if (currentProcess > (NUM_PROCESSES - 1)) currentProcess = 0; + textureReload = true; + } + else if (IsKeyPressed(KEY_UP)) + { + currentProcess--; + if (currentProcess < 0) currentProcess = 7; + textureReload = true; + } + + // Reload texture when required + if (textureReload) + { + UnloadImage(imCopy); // Unload image-copy data + imCopy = ImageCopy(imOrigin); // Restore image-copy from image-origin + + // NOTE: Image processing is a costly CPU process to be done every frame, + // If image processing is required in a frame-basis, it should be done + // with a texture and by shaders + switch (currentProcess) + { + case COLOR_GRAYSCALE: ImageColorGrayscale(&imCopy); break; + case COLOR_TINT: ImageColorTint(&imCopy, GREEN); break; + case COLOR_INVERT: ImageColorInvert(&imCopy); break; + case COLOR_CONTRAST: ImageColorContrast(&imCopy, -40); break; + case COLOR_BRIGHTNESS: ImageColorBrightness(&imCopy, -80); break; + case GAUSSIAN_BLUR: ImageBlurGaussian(&imCopy, 10); break; + case FLIP_VERTICAL: ImageFlipVertical(&imCopy); break; + case FLIP_HORIZONTAL: ImageFlipHorizontal(&imCopy); break; + default: break; + } + + Color *pixels = LoadImageColors(imCopy); // Load pixel data from image (RGBA 32bit) + UpdateTexture(texture, pixels); // Update texture with new image data + UnloadImageColors(pixels); // Unload pixels data from RAM + + textureReload = false; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("IMAGE PROCESSING:", 40, 30, 10, DARKGRAY); + + // Draw rectangles + for (int i = 0; i < NUM_PROCESSES; i++) + { + DrawRectangleRec(toggleRecs[i], ((i == currentProcess) || (i == mouseHoverRec)) ? SKYBLUE : LIGHTGRAY); + DrawRectangleLines((int)toggleRecs[i].x, (int) toggleRecs[i].y, (int) toggleRecs[i].width, (int) toggleRecs[i].height, ((i == currentProcess) || (i == mouseHoverRec)) ? BLUE : GRAY); + DrawText( processText[i], (int)( toggleRecs[i].x + toggleRecs[i].width/2 - MeasureText(processText[i], 10)/2), (int) toggleRecs[i].y + 11, 10, ((i == currentProcess) || (i == mouseHoverRec)) ? DARKBLUE : DARKGRAY); + } + + DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE); + DrawRectangleLines(screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, texture.width, texture.height, BLACK); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Unload texture from VRAM + UnloadImage(imOrigin); // Unload image-origin from RAM + UnloadImage(imCopy); // Unload image-copy from RAM + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_image_processing.png b/deps/raylib/examples/textures/textures_image_processing.png Binary files differnew file mode 100644 index 0000000..c15e19f --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_processing.png diff --git a/deps/raylib/examples/textures/textures_image_rotate.c b/deps/raylib/examples/textures/textures_image_rotate.c new file mode 100644 index 0000000..94c4203 --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_rotate.c @@ -0,0 +1,83 @@ +/******************************************************************************************* +* +* raylib [textures] example - Image Rotation +* +* Example originally created with raylib 1.0, last time updated with raylib 1.0 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_TEXTURES 3 + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture rotation"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Image image45 = LoadImage("resources/raylib_logo.png"); + Image image90 = LoadImage("resources/raylib_logo.png"); + Image imageNeg90 = LoadImage("resources/raylib_logo.png"); + + ImageRotate(&image45, 45); + ImageRotate(&image90, 90); + ImageRotate(&imageNeg90, -90); + + Texture2D textures[NUM_TEXTURES] = { 0 }; + + textures[0] = LoadTextureFromImage(image45); + textures[1] = LoadTextureFromImage(image90); + textures[2] = LoadTextureFromImage(imageNeg90); + + int currentTexture = 0; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || IsKeyPressed(KEY_RIGHT)) + { + currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(textures[currentTexture], screenWidth/2 - textures[currentTexture].width/2, screenHeight/2 - textures[currentTexture].height/2, WHITE); + + DrawText("Press LEFT MOUSE BUTTON to rotate the image clockwise", 250, 420, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(textures[i]); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_image_rotate.png b/deps/raylib/examples/textures/textures_image_rotate.png Binary files differnew file mode 100644 index 0000000..862612e --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_rotate.png diff --git a/deps/raylib/examples/textures/textures_image_text.c b/deps/raylib/examples/textures/textures_image_text.c new file mode 100644 index 0000000..856b64e --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_text.c @@ -0,0 +1,88 @@ +/******************************************************************************************* +* +* raylib [texture] example - Image text drawing using TTF generated font +* +* Example originally created with raylib 1.8, last time updated with raylib 4.0 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2017-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); + + Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) + + // TTF Font loading with custom generation parameters + Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0); + + // Draw over image using custom font + ImageDrawTextEx(&parrots, font, "[Parrots font drawing]", (Vector2){ 20.0f, 20.0f }, (float)font.baseSize, 0.0f, RED); + + Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) + UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + + Vector2 position = { (float)(screenWidth/2 - texture.width/2), (float)(screenHeight/2 - texture.height/2 - 20) }; + + bool showFont = false; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyDown(KEY_SPACE)) showFont = true; + else showFont = false; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!showFont) + { + // Draw texture with text already drawn inside + DrawTextureV(texture, position, WHITE); + + // Draw text directly using sprite font + DrawTextEx(font, "[Parrots font drawing]", (Vector2){ position.x + 20, + position.y + 20 + 280 }, (float)font.baseSize, 0.0f, WHITE); + } + else DrawTexture(font.texture, screenWidth/2 - font.texture.width/2, 50, BLACK); + + DrawText("PRESS SPACE to SHOW FONT ATLAS USED", 290, 420, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + UnloadFont(font); // Unload custom font + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_image_text.png b/deps/raylib/examples/textures/textures_image_text.png Binary files differnew file mode 100644 index 0000000..dafbabf --- /dev/null +++ b/deps/raylib/examples/textures/textures_image_text.png diff --git a/deps/raylib/examples/textures/textures_logo_raylib.c b/deps/raylib/examples/textures/textures_logo_raylib.c new file mode 100644 index 0000000..35baa12 --- /dev/null +++ b/deps/raylib/examples/textures/textures_logo_raylib.c @@ -0,0 +1,64 @@ +/******************************************************************************************* +* +* raylib [textures] example - Texture loading and drawing +* +* Example originally created with raylib 1.0, last time updated with raylib 1.0 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); + + DrawText("this IS a texture!", 360, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_logo_raylib.png b/deps/raylib/examples/textures/textures_logo_raylib.png Binary files differnew file mode 100644 index 0000000..c18bf88 --- /dev/null +++ b/deps/raylib/examples/textures/textures_logo_raylib.png diff --git a/deps/raylib/examples/textures/textures_mouse_painting.c b/deps/raylib/examples/textures/textures_mouse_painting.c new file mode 100644 index 0000000..27bbc74 --- /dev/null +++ b/deps/raylib/examples/textures/textures_mouse_painting.c @@ -0,0 +1,226 @@ +/******************************************************************************************* +* +* raylib [textures] example - Mouse painting +* +* Example originally created with raylib 3.0, last time updated with raylib 3.0 +* +* Example contributed by Chris Dill (@MysteriousSpace) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2024 Chris Dill (@MysteriousSpace) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_COLORS_COUNT 23 // Number of colors available + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - mouse painting"); + + // Colors to choose from + Color colors[MAX_COLORS_COUNT] = { + RAYWHITE, YELLOW, GOLD, ORANGE, PINK, RED, MAROON, GREEN, LIME, DARKGREEN, + SKYBLUE, BLUE, DARKBLUE, PURPLE, VIOLET, DARKPURPLE, BEIGE, BROWN, DARKBROWN, + LIGHTGRAY, GRAY, DARKGRAY, BLACK }; + + // Define colorsRecs data (for every rectangle) + Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; + + for (int i = 0; i < MAX_COLORS_COUNT; i++) + { + colorsRecs[i].x = 10 + 30.0f*i + 2*i; + colorsRecs[i].y = 10; + colorsRecs[i].width = 30; + colorsRecs[i].height = 30; + } + + int colorSelected = 0; + int colorSelectedPrev = colorSelected; + int colorMouseHover = 0; + float brushSize = 20.0f; + bool mouseWasPressed = false; + + Rectangle btnSaveRec = { 750, 10, 40, 30 }; + bool btnSaveMouseHover = false; + bool showSaveMessage = false; + int saveMessageCounter = 0; + + // Create a RenderTexture2D to use as a canvas + RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); + + // Clear render texture before entering the game loop + BeginTextureMode(target); + ClearBackground(colors[0]); + EndTextureMode(); + + SetTargetFPS(120); // Set our game to run at 120 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + Vector2 mousePos = GetMousePosition(); + + // Move between colors with keys + if (IsKeyPressed(KEY_RIGHT)) colorSelected++; + else if (IsKeyPressed(KEY_LEFT)) colorSelected--; + + if (colorSelected >= MAX_COLORS_COUNT) colorSelected = MAX_COLORS_COUNT - 1; + else if (colorSelected < 0) colorSelected = 0; + + // Choose color with mouse + for (int i = 0; i < MAX_COLORS_COUNT; i++) + { + if (CheckCollisionPointRec(mousePos, colorsRecs[i])) + { + colorMouseHover = i; + break; + } + else colorMouseHover = -1; + } + + if ((colorMouseHover >= 0) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) + { + colorSelected = colorMouseHover; + colorSelectedPrev = colorSelected; + } + + // Change brush size + brushSize += GetMouseWheelMove()*5; + if (brushSize < 2) brushSize = 2; + if (brushSize > 50) brushSize = 50; + + if (IsKeyPressed(KEY_C)) + { + // Clear render texture to clear color + BeginTextureMode(target); + ClearBackground(colors[0]); + EndTextureMode(); + } + + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) || (GetGestureDetected() == GESTURE_DRAG)) + { + // Paint circle into render texture + // NOTE: To avoid discontinuous circles, we could store + // previous-next mouse points and just draw a line using brush size + BeginTextureMode(target); + if (mousePos.y > 50) DrawCircle((int)mousePos.x, (int)mousePos.y, brushSize, colors[colorSelected]); + EndTextureMode(); + } + + if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) + { + if (!mouseWasPressed) + { + colorSelectedPrev = colorSelected; + colorSelected = 0; + } + + mouseWasPressed = true; + + // Erase circle from render texture + BeginTextureMode(target); + if (mousePos.y > 50) DrawCircle((int)mousePos.x, (int)mousePos.y, brushSize, colors[0]); + EndTextureMode(); + } + else if (IsMouseButtonReleased(MOUSE_BUTTON_RIGHT) && mouseWasPressed) + { + colorSelected = colorSelectedPrev; + mouseWasPressed = false; + } + + // Check mouse hover save button + if (CheckCollisionPointRec(mousePos, btnSaveRec)) btnSaveMouseHover = true; + else btnSaveMouseHover = false; + + // Image saving logic + // NOTE: Saving painted texture to a default named image + if ((btnSaveMouseHover && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) || IsKeyPressed(KEY_S)) + { + Image image = LoadImageFromTexture(target.texture); + ImageFlipVertical(&image); + ExportImage(image, "my_amazing_texture_painting.png"); + UnloadImage(image); + showSaveMessage = true; + } + + if (showSaveMessage) + { + // On saving, show a full screen message for 2 seconds + saveMessageCounter++; + if (saveMessageCounter > 240) + { + showSaveMessage = false; + saveMessageCounter = 0; + } + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) + DrawTextureRec(target.texture, (Rectangle) { 0, 0, (float)target.texture.width, (float)-target.texture.height }, (Vector2) { 0, 0 }, WHITE); + + // Draw drawing circle for reference + if (mousePos.y > 50) + { + if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) DrawCircleLines((int)mousePos.x, (int)mousePos.y, brushSize, GRAY); + else DrawCircle(GetMouseX(), GetMouseY(), brushSize, colors[colorSelected]); + } + + // Draw top panel + DrawRectangle(0, 0, GetScreenWidth(), 50, RAYWHITE); + DrawLine(0, 50, GetScreenWidth(), 50, LIGHTGRAY); + + // Draw color selection rectangles + for (int i = 0; i < MAX_COLORS_COUNT; i++) DrawRectangleRec(colorsRecs[i], colors[i]); + DrawRectangleLines(10, 10, 30, 30, LIGHTGRAY); + + if (colorMouseHover >= 0) DrawRectangleRec(colorsRecs[colorMouseHover], Fade(WHITE, 0.6f)); + + DrawRectangleLinesEx((Rectangle){ colorsRecs[colorSelected].x - 2, colorsRecs[colorSelected].y - 2, + colorsRecs[colorSelected].width + 4, colorsRecs[colorSelected].height + 4 }, 2, BLACK); + + // Draw save image button + DrawRectangleLinesEx(btnSaveRec, 2, btnSaveMouseHover ? RED : BLACK); + DrawText("SAVE!", 755, 20, 10, btnSaveMouseHover ? RED : BLACK); + + // Draw save image message + if (showSaveMessage) + { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, 0.8f)); + DrawRectangle(0, 150, GetScreenWidth(), 80, BLACK); + DrawText("IMAGE SAVED: my_amazing_texture_painting.png", 150, 180, 20, RAYWHITE); + } + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadRenderTexture(target); // Unload render texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_mouse_painting.png b/deps/raylib/examples/textures/textures_mouse_painting.png Binary files differnew file mode 100644 index 0000000..a3dec5d --- /dev/null +++ b/deps/raylib/examples/textures/textures_mouse_painting.png diff --git a/deps/raylib/examples/textures/textures_npatch_drawing.c b/deps/raylib/examples/textures/textures_npatch_drawing.c new file mode 100644 index 0000000..5fb3999 --- /dev/null +++ b/deps/raylib/examples/textures/textures_npatch_drawing.c @@ -0,0 +1,114 @@ +/******************************************************************************************* +* +* raylib [textures] example - N-patch drawing +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 2.0, last time updated with raylib 2.5 +* +* Example contributed by Jorge A. Gomes (@overdev) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2018-2024 Jorge A. Gomes (@overdev) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - N-patch drawing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png"); + + Vector2 mousePosition = { 0 }; + Vector2 origin = { 0.0f, 0.0f }; + + // Position and size of the n-patches + Rectangle dstRec1 = { 480.0f, 160.0f, 32.0f, 32.0f }; + Rectangle dstRec2 = { 160.0f, 160.0f, 32.0f, 32.0f }; + Rectangle dstRecH = { 160.0f, 93.0f, 32.0f, 32.0f }; + Rectangle dstRecV = { 92.0f, 160.0f, 32.0f, 32.0f }; + + // A 9-patch (NPATCH_NINE_PATCH) changes its sizes in both axis + NPatchInfo ninePatchInfo1 = { (Rectangle){ 0.0f, 0.0f, 64.0f, 64.0f }, 12, 40, 12, 12, NPATCH_NINE_PATCH }; + NPatchInfo ninePatchInfo2 = { (Rectangle){ 0.0f, 128.0f, 64.0f, 64.0f }, 16, 16, 16, 16, NPATCH_NINE_PATCH }; + + // A horizontal 3-patch (NPATCH_THREE_PATCH_HORIZONTAL) changes its sizes along the x axis only + NPatchInfo h3PatchInfo = { (Rectangle){ 0.0f, 64.0f, 64.0f, 64.0f }, 8, 8, 8, 8, NPATCH_THREE_PATCH_HORIZONTAL }; + + // A vertical 3-patch (NPATCH_THREE_PATCH_VERTICAL) changes its sizes along the y axis only + NPatchInfo v3PatchInfo = { (Rectangle){ 0.0f, 192.0f, 64.0f, 64.0f }, 6, 6, 6, 6, NPATCH_THREE_PATCH_VERTICAL }; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + mousePosition = GetMousePosition(); + + // Resize the n-patches based on mouse position + dstRec1.width = mousePosition.x - dstRec1.x; + dstRec1.height = mousePosition.y - dstRec1.y; + dstRec2.width = mousePosition.x - dstRec2.x; + dstRec2.height = mousePosition.y - dstRec2.y; + dstRecH.width = mousePosition.x - dstRecH.x; + dstRecV.height = mousePosition.y - dstRecV.y; + + // Set a minimum width and/or height + if (dstRec1.width < 1.0f) dstRec1.width = 1.0f; + if (dstRec1.width > 300.0f) dstRec1.width = 300.0f; + if (dstRec1.height < 1.0f) dstRec1.height = 1.0f; + if (dstRec2.width < 1.0f) dstRec2.width = 1.0f; + if (dstRec2.width > 300.0f) dstRec2.width = 300.0f; + if (dstRec2.height < 1.0f) dstRec2.height = 1.0f; + if (dstRecH.width < 1.0f) dstRecH.width = 1.0f; + if (dstRecV.height < 1.0f) dstRecV.height = 1.0f; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw the n-patches + DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); + + // Draw the source texture + DrawRectangleLines(5, 88, 74, 266, BLUE); + DrawTexture(nPatchTexture, 10, 93, WHITE); + DrawText("TEXTURE", 15, 360, 10, DARKGRAY); + + DrawText("Move the mouse to stretch or shrink the n-patches", 10, 20, 20, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(nPatchTexture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/deps/raylib/examples/textures/textures_npatch_drawing.png b/deps/raylib/examples/textures/textures_npatch_drawing.png Binary files differnew file mode 100644 index 0000000..21df9ca --- /dev/null +++ b/deps/raylib/examples/textures/textures_npatch_drawing.png diff --git a/deps/raylib/examples/textures/textures_particles_blending.c b/deps/raylib/examples/textures/textures_particles_blending.c new file mode 100644 index 0000000..113b2b0 --- /dev/null +++ b/deps/raylib/examples/textures/textures_particles_blending.c @@ -0,0 +1,140 @@ +/******************************************************************************************* +* +* raylib example - particles blending +* +* Example originally created with raylib 1.7, last time updated with raylib 3.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2017-2024 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; + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); + + // Particles pool, reuse them! + Particle mouseTail[MAX_PARTICLES] = { 0 }; + + // 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 = (float)GetRandomValue(0, 360); + mouseTail[i].active = false; + } + + float gravity = 3.0f; + + Texture2D smoke = LoadTexture("resources/spark_flame.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/2; + mouseTail[i].alpha -= 0.005f; + + if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false; + + mouseTail[i].rotation += 2.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.0f, 0.0f, (float)smoke.width, (float)smoke.height }, + (Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size }, + (Vector2){ (float)(smoke.width*mouseTail[i].size/2.0f), (float)(smoke.height*mouseTail[i].size/2.0f) }, 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/deps/raylib/examples/textures/textures_particles_blending.png b/deps/raylib/examples/textures/textures_particles_blending.png Binary files differnew file mode 100644 index 0000000..d173461 --- /dev/null +++ b/deps/raylib/examples/textures/textures_particles_blending.png diff --git a/deps/raylib/examples/textures/textures_polygon.c b/deps/raylib/examples/textures/textures_polygon.c new file mode 100644 index 0000000..2491e1b --- /dev/null +++ b/deps/raylib/examples/textures/textures_polygon.c @@ -0,0 +1,140 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Draw Textured Polygon +* +* Example originally created with raylib 3.7, last time updated with raylib 3.7 +* +* Example contributed by Chris Camacho (@codifies) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2021-2024 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include "rlgl.h" // Required for: Vertex definition +#include "raymath.h" + +#define MAX_POINTS 11 // 10 points and back to the start + +// Draw textured polygon, defined by vertex and texture coordinates +void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon"); + + // Define texture coordinates to map our texture to poly + Vector2 texcoords[MAX_POINTS] = { + (Vector2){ 0.75f, 0.0f }, + (Vector2){ 0.25f, 0.0f }, + (Vector2){ 0.0f, 0.5f }, + (Vector2){ 0.0f, 0.75f }, + (Vector2){ 0.25f, 1.0f}, + (Vector2){ 0.375f, 0.875f}, + (Vector2){ 0.625f, 0.875f}, + (Vector2){ 0.75f, 1.0f}, + (Vector2){ 1.0f, 0.75f}, + (Vector2){ 1.0f, 0.5f}, + (Vector2){ 0.75f, 0.0f} // Close the poly + }; + + // Define the base poly vertices from the UV's + // NOTE: They can be specified in any other way + Vector2 points[MAX_POINTS] = { 0 }; + for (int i = 0; i < MAX_POINTS; i++) + { + points[i].x = (texcoords[i].x - 0.5f)*256.0f; + points[i].y = (texcoords[i].y - 0.5f)*256.0f; + } + + // Define the vertices drawing position + // NOTE: Initially same as points but updated every frame + Vector2 positions[MAX_POINTS] = { 0 }; + for (int i = 0; i < MAX_POINTS; i++) positions[i] = points[i]; + + // Load texture to be mapped to poly + Texture texture = LoadTexture("resources/cat.png"); + + float angle = 0.0f; // Rotation angle (in degrees) + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Update points rotation with an angle transform + // NOTE: Base points position are not modified + angle++; + for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], angle*DEG2RAD); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("textured polygon", 20, 20, 20, DARKGRAY); + + DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f }, + positions, texcoords, MAX_POINTS, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Unload texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +// Draw textured polygon, defined by vertex and texture coordinates +// NOTE: Polygon center must have straight line path to all points +// without crossing perimeter, points must be in anticlockwise order +void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint) +{ + rlSetTexture(texture.id); + + // Texturing is only supported on RL_QUADS + rlBegin(RL_QUADS); + + rlColor4ub(tint.r, tint.g, tint.b, tint.a); + + for (int i = 0; i < pointCount - 1; i++) + { + rlTexCoord2f(0.5f, 0.5f); + rlVertex2f(center.x, center.y); + + rlTexCoord2f(texcoords[i].x, texcoords[i].y); + rlVertex2f(points[i].x + center.x, points[i].y + center.y); + + rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y); + rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y); + + rlTexCoord2f(texcoords[i + 1].x, texcoords[i + 1].y); + rlVertex2f(points[i + 1].x + center.x, points[i + 1].y + center.y); + } + rlEnd(); + + rlSetTexture(0); +} diff --git a/deps/raylib/examples/textures/textures_polygon.png b/deps/raylib/examples/textures/textures_polygon.png Binary files differnew file mode 100644 index 0000000..b977ada --- /dev/null +++ b/deps/raylib/examples/textures/textures_polygon.png diff --git a/deps/raylib/examples/textures/textures_raw_data.c b/deps/raylib/examples/textures/textures_raw_data.c new file mode 100644 index 0000000..6fb41b1 --- /dev/null +++ b/deps/raylib/examples/textures/textures_raw_data.c @@ -0,0 +1,106 @@ +/******************************************************************************************* +* +* raylib [textures] example - Load textures from raw data +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 1.3, last time updated with raylib 3.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include <stdlib.h> // Required for: malloc() and free() + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + // Load RAW image data (512x512, 32bit RGBA, no file header) + Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 0); + Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) + UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data + + // Generate a checked texture by code + int width = 960; + int height = 480; + + // Dynamic memory allocation to store pixels data (Color type) + Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + if (((x/32+y/32)/1)%2 == 0) pixels[y*width + x] = ORANGE; + else pixels[y*width + x] = GOLD; + } + } + + // Load pixels data into an image structure and create texture + Image checkedIm = { + .data = pixels, // We can assign pixels directly to data + .width = width, + .height = height, + .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, + .mipmaps = 1 + }; + + Texture2D checked = LoadTextureFromImage(checkedIm); + UnloadImage(checkedIm); // Unload CPU (RAM) image data (pixels) + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f)); + DrawTexture(fudesumi, 430, -30, WHITE); + + DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN); + DrawText("GENERATED by CODE", 72, 148, 30, BROWN); + DrawText("and RAW IMAGE LOADING", 46, 210, 30, BROWN); + + DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(fudesumi); // Texture unloading + UnloadTexture(checked); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_raw_data.png b/deps/raylib/examples/textures/textures_raw_data.png Binary files differnew file mode 100644 index 0000000..437e4b5 --- /dev/null +++ b/deps/raylib/examples/textures/textures_raw_data.png diff --git a/deps/raylib/examples/textures/textures_sprite_anim.c b/deps/raylib/examples/textures/textures_sprite_anim.c new file mode 100644 index 0000000..deb6821 --- /dev/null +++ b/deps/raylib/examples/textures/textures_sprite_anim.c @@ -0,0 +1,105 @@ +/******************************************************************************************* +* +* raylib [textures] example - Sprite animation +* +* Example originally created with raylib 1.3, last time updated with raylib 1.3 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_FRAME_SPEED 15 +#define MIN_FRAME_SPEED 1 + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [texture] example - sprite anim"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading + + Vector2 position = { 350.0f, 280.0f }; + Rectangle frameRec = { 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height }; + int currentFrame = 0; + + int framesCounter = 0; + int framesSpeed = 8; // Number of spritesheet frames shown by second + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + framesCounter++; + + if (framesCounter >= (60/framesSpeed)) + { + framesCounter = 0; + currentFrame++; + + if (currentFrame > 5) currentFrame = 0; + + frameRec.x = (float)currentFrame*(float)scarfy.width/6; + } + + // Control frames speed + if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; + else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; + + if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; + else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(scarfy, 15, 40, WHITE); + DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); + DrawRectangleLines(15 + (int)frameRec.x, 40 + (int)frameRec.y, (int)frameRec.width, (int)frameRec.height, RED); + + DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); + DrawText(TextFormat("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); + DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); + + for (int i = 0; i < MAX_FRAME_SPEED; i++) + { + if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); + DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); + } + + DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture + + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(scarfy); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_sprite_anim.png b/deps/raylib/examples/textures/textures_sprite_anim.png Binary files differnew file mode 100644 index 0000000..aa66464 --- /dev/null +++ b/deps/raylib/examples/textures/textures_sprite_anim.png diff --git a/deps/raylib/examples/textures/textures_sprite_button.c b/deps/raylib/examples/textures/textures_sprite_button.c new file mode 100644 index 0000000..5d0153b --- /dev/null +++ b/deps/raylib/examples/textures/textures_sprite_button.c @@ -0,0 +1,102 @@ +/******************************************************************************************* +* +* raylib [textures] example - sprite button +* +* Example originally created with raylib 2.5, last time updated with raylib 2.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_FRAMES 3 // Number of frames (rectangles) for the button sprite texture + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite button"); + + InitAudioDevice(); // Initialize audio device + + Sound fxButton = LoadSound("resources/buttonfx.wav"); // Load button sound + Texture2D button = LoadTexture("resources/button.png"); // Load button texture + + // Define frame rectangle for drawing + float frameHeight = (float)button.height/NUM_FRAMES; + Rectangle sourceRec = { 0, 0, (float)button.width, frameHeight }; + + // Define button bounds on screen + Rectangle btnBounds = { screenWidth/2.0f - button.width/2.0f, screenHeight/2.0f - button.height/NUM_FRAMES/2.0f, (float)button.width, frameHeight }; + + int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED + bool btnAction = false; // Button action should be activated + + Vector2 mousePoint = { 0.0f, 0.0f }; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + mousePoint = GetMousePosition(); + btnAction = false; + + // Check button state + if (CheckCollisionPointRec(mousePoint, btnBounds)) + { + if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) btnState = 2; + else btnState = 1; + + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) btnAction = true; + } + else btnState = 0; + + if (btnAction) + { + PlaySound(fxButton); + + // TODO: Any desired action + } + + // Calculate button frame rectangle to draw depending on button state + sourceRec.y = btnState*frameHeight; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTextureRec(button, sourceRec, (Vector2){ btnBounds.x, btnBounds.y }, WHITE); // Draw button frame + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(button); // Unload button texture + UnloadSound(fxButton); // Unload sound + + CloseAudioDevice(); // Close audio device + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_sprite_button.png b/deps/raylib/examples/textures/textures_sprite_button.png Binary files differnew file mode 100644 index 0000000..8828e19 --- /dev/null +++ b/deps/raylib/examples/textures/textures_sprite_button.png diff --git a/deps/raylib/examples/textures/textures_sprite_explosion.c b/deps/raylib/examples/textures/textures_sprite_explosion.c new file mode 100644 index 0000000..a65426c --- /dev/null +++ b/deps/raylib/examples/textures/textures_sprite_explosion.c @@ -0,0 +1,125 @@ +/******************************************************************************************* +* +* raylib [textures] example - sprite explosion +* +* Example originally created with raylib 2.5, last time updated with raylib 3.5 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2024 Anata and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_FRAMES_PER_LINE 5 +#define NUM_LINES 5 + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite explosion"); + + InitAudioDevice(); + + // Load explosion sound + Sound fxBoom = LoadSound("resources/boom.wav"); + + // Load explosion texture + Texture2D explosion = LoadTexture("resources/explosion.png"); + + // Init variables for animation + float frameWidth = (float)(explosion.width/NUM_FRAMES_PER_LINE); // Sprite one frame rectangle width + float frameHeight = (float)(explosion.height/NUM_LINES); // Sprite one frame rectangle height + int currentFrame = 0; + int currentLine = 0; + + Rectangle frameRec = { 0, 0, frameWidth, frameHeight }; + Vector2 position = { 0.0f, 0.0f }; + + bool active = false; + int framesCounter = 0; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + + // Check for mouse button pressed and activate explosion (if not active) + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && !active) + { + position = GetMousePosition(); + active = true; + + position.x -= frameWidth/2.0f; + position.y -= frameHeight/2.0f; + + PlaySound(fxBoom); + } + + // Compute explosion animation frames + if (active) + { + framesCounter++; + + if (framesCounter > 2) + { + currentFrame++; + + if (currentFrame >= NUM_FRAMES_PER_LINE) + { + currentFrame = 0; + currentLine++; + + if (currentLine >= NUM_LINES) + { + currentLine = 0; + active = false; + } + } + + framesCounter = 0; + } + } + + frameRec.x = frameWidth*currentFrame; + frameRec.y = frameHeight*currentLine; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw explosion required frame rectangle + if (active) DrawTextureRec(explosion, frameRec, position, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(explosion); // Unload texture + UnloadSound(fxBoom); // Unload sound + + CloseAudioDevice(); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_sprite_explosion.png b/deps/raylib/examples/textures/textures_sprite_explosion.png Binary files differnew file mode 100644 index 0000000..00bd672 --- /dev/null +++ b/deps/raylib/examples/textures/textures_sprite_explosion.png diff --git a/deps/raylib/examples/textures/textures_srcrec_dstrec.c b/deps/raylib/examples/textures/textures_srcrec_dstrec.c new file mode 100644 index 0000000..035e303 --- /dev/null +++ b/deps/raylib/examples/textures/textures_srcrec_dstrec.c @@ -0,0 +1,87 @@ +/******************************************************************************************* +* +* raylib [textures] example - Texture source and destination rectangles +* +* Example originally created with raylib 1.3, last time updated with raylib 1.3 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading + + int frameWidth = scarfy.width/6; + int frameHeight = scarfy.height; + + // Source rectangle (part of the texture to use for drawing) + Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight }; + + // Destination rectangle (screen rectangle where drawing part of texture) + Rectangle destRec = { screenWidth/2.0f, screenHeight/2.0f, frameWidth*2.0f, frameHeight*2.0f }; + + // Origin of the texture (rotation/scale point), it's relative to destination rectangle size + Vector2 origin = { (float)frameWidth, (float)frameHeight }; + + int rotation = 0; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + rotation++; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw + // sourceRec defines the part of the texture we use for drawing + // destRec defines the rectangle where our texture part will fit (scaling it to fit) + // origin defines the point of the texture used as reference for rotation and scaling + // rotation defines the texture rotation (using origin as rotation point) + DrawTexturePro(scarfy, sourceRec, destRec, origin, (float)rotation, WHITE); + + DrawLine((int)destRec.x, 0, (int)destRec.x, screenHeight, GRAY); + DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); + + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(scarfy); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_srcrec_dstrec.png b/deps/raylib/examples/textures/textures_srcrec_dstrec.png Binary files differnew file mode 100644 index 0000000..7691ff2 --- /dev/null +++ b/deps/raylib/examples/textures/textures_srcrec_dstrec.png diff --git a/deps/raylib/examples/textures/textures_textured_curve.c b/deps/raylib/examples/textures/textures_textured_curve.c new file mode 100644 index 0000000..6e4c53c --- /dev/null +++ b/deps/raylib/examples/textures/textures_textured_curve.c @@ -0,0 +1,233 @@ +/******************************************************************************************* +* +* raylib [textures] example - Draw a texture along a segmented curve +* +* Example originally created with raylib 4.5, last time updated with raylib 4.5 +* +* Example contributed by Jeffery Myers and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2022-2024 Jeffery Myers and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include "raymath.h" +#include "rlgl.h" + +#include <math.h> // Required for: powf() +#include <stdlib.h> // Required for: NULL + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +static Texture texRoad = { 0 }; + +static bool showCurve = false; + +static float curveWidth = 50; +static int curveSegments = 24; + +static Vector2 curveStartPosition = { 0 }; +static Vector2 curveStartPositionTangent = { 0 }; + +static Vector2 curveEndPosition = { 0 }; +static Vector2 curveEndPositionTangent = { 0 }; + +static Vector2 *curveSelectedPoint = NULL; + +//---------------------------------------------------------------------------------- +// Module Functions Declaration +//---------------------------------------------------------------------------------- +static void DrawTexturedCurve(void); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + SetConfigFlags(FLAG_VSYNC_HINT | FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "raylib [textures] examples - textured curve"); + + // Load the road texture + texRoad = LoadTexture("resources/road.png"); + SetTextureFilter(texRoad, TEXTURE_FILTER_BILINEAR); + + // Setup the curve + curveStartPosition = (Vector2){ 80, 100 }; + curveStartPositionTangent = (Vector2){ 100, 300 }; + + curveEndPosition = (Vector2){ 700, 350 }; + curveEndPositionTangent = (Vector2){ 600, 100 }; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Curve config options + if (IsKeyPressed(KEY_SPACE)) showCurve = !showCurve; + if (IsKeyPressed(KEY_EQUAL)) curveWidth += 2; + if (IsKeyPressed(KEY_MINUS)) curveWidth -= 2; + if (curveWidth < 2) curveWidth = 2; + + // Update segments + if (IsKeyPressed(KEY_LEFT)) curveSegments -= 2; + if (IsKeyPressed(KEY_RIGHT)) curveSegments += 2; + + if (curveSegments < 2) curveSegments = 2; + + // Update curve logic + // If the mouse is not down, we are not editing the curve so clear the selection + if (!IsMouseButtonDown(MOUSE_LEFT_BUTTON)) curveSelectedPoint = NULL; + + // If a point was selected, move it + if (curveSelectedPoint) *curveSelectedPoint = Vector2Add(*curveSelectedPoint, GetMouseDelta()); + + // The mouse is down, and nothing was selected, so see if anything was picked + Vector2 mouse = GetMousePosition(); + if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) curveSelectedPoint = &curveStartPosition; + else if (CheckCollisionPointCircle(mouse, curveStartPositionTangent, 6)) curveSelectedPoint = &curveStartPositionTangent; + else if (CheckCollisionPointCircle(mouse, curveEndPosition, 6)) curveSelectedPoint = &curveEndPosition; + else if (CheckCollisionPointCircle(mouse, curveEndPositionTangent, 6)) curveSelectedPoint = &curveEndPositionTangent; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexturedCurve(); // Draw a textured Spline Cubic Bezier + + // Draw spline for reference + if (showCurve) DrawSplineSegmentBezierCubic(curveStartPosition, curveEndPosition, curveStartPositionTangent, curveEndPositionTangent, 2, BLUE); + + // Draw the various control points and highlight where the mouse is + DrawLineV(curveStartPosition, curveStartPositionTangent, SKYBLUE); + DrawLineV(curveStartPositionTangent, curveEndPositionTangent, Fade(LIGHTGRAY, 0.4f)); + DrawLineV(curveEndPosition, curveEndPositionTangent, PURPLE); + + if (CheckCollisionPointCircle(mouse, curveStartPosition, 6)) DrawCircleV(curveStartPosition, 7, YELLOW); + DrawCircleV(curveStartPosition, 5, RED); + + if (CheckCollisionPointCircle(mouse, curveStartPositionTangent, 6)) DrawCircleV(curveStartPositionTangent, 7, YELLOW); + DrawCircleV(curveStartPositionTangent, 5, MAROON); + + if (CheckCollisionPointCircle(mouse, curveEndPosition, 6)) DrawCircleV(curveEndPosition, 7, YELLOW); + DrawCircleV(curveEndPosition, 5, GREEN); + + if (CheckCollisionPointCircle(mouse, curveEndPositionTangent, 6)) DrawCircleV(curveEndPositionTangent, 7, YELLOW); + DrawCircleV(curveEndPositionTangent, 5, DARKGREEN); + + // Draw usage info + DrawText("Drag points to move curve, press SPACE to show/hide base curve", 10, 10, 10, DARKGRAY); + DrawText(TextFormat("Curve width: %2.0f (Use + and - to adjust)", curveWidth), 10, 30, 10, DARKGRAY); + DrawText(TextFormat("Curve segments: %d (Use LEFT and RIGHT to adjust)", curveSegments), 10, 50, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texRoad); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//---------------------------------------------------------------------------------- +// Module Functions Definition +//---------------------------------------------------------------------------------- + +// Draw textured curve using Spline Cubic Bezier +static void DrawTexturedCurve(void) +{ + const float step = 1.0f/curveSegments; + + Vector2 previous = curveStartPosition; + Vector2 previousTangent = { 0 }; + float previousV = 0; + + // We can't compute a tangent for the first point, so we need to reuse the tangent from the first segment + bool tangentSet = false; + + Vector2 current = { 0 }; + float t = 0.0f; + + for (int i = 1; i <= curveSegments; i++) + { + t = step*(float)i; + + float a = powf(1.0f - t, 3); + float b = 3.0f*powf(1.0f - t, 2)*t; + float c = 3.0f*(1.0f - t)*powf(t, 2); + float d = powf(t, 3); + + // Compute the endpoint for this segment + current.y = a*curveStartPosition.y + b*curveStartPositionTangent.y + c*curveEndPositionTangent.y + d*curveEndPosition.y; + current.x = a*curveStartPosition.x + b*curveStartPositionTangent.x + c*curveEndPositionTangent.x + d*curveEndPosition.x; + + // Vector from previous to current + Vector2 delta = { current.x - previous.x, current.y - previous.y }; + + // The right hand normal to the delta vector + Vector2 normal = Vector2Normalize((Vector2){ -delta.y, delta.x }); + + // The v texture coordinate of the segment (add up the length of all the segments so far) + float v = previousV + Vector2Length(delta); + + // Make sure the start point has a normal + if (!tangentSet) + { + previousTangent = normal; + tangentSet = true; + } + + // Extend out the normals from the previous and current points to get the quad for this segment + Vector2 prevPosNormal = Vector2Add(previous, Vector2Scale(previousTangent, curveWidth)); + Vector2 prevNegNormal = Vector2Add(previous, Vector2Scale(previousTangent, -curveWidth)); + + Vector2 currentPosNormal = Vector2Add(current, Vector2Scale(normal, curveWidth)); + Vector2 currentNegNormal = Vector2Add(current, Vector2Scale(normal, -curveWidth)); + + // Draw the segment as a quad + rlSetTexture(texRoad.id); + rlBegin(RL_QUADS); + rlColor4ub(255,255,255,255); + rlNormal3f(0.0f, 0.0f, 1.0f); + + rlTexCoord2f(0, previousV); + rlVertex2f(prevNegNormal.x, prevNegNormal.y); + + rlTexCoord2f(1, previousV); + rlVertex2f(prevPosNormal.x, prevPosNormal.y); + + rlTexCoord2f(1, v); + rlVertex2f(currentPosNormal.x, currentPosNormal.y); + + rlTexCoord2f(0, v); + rlVertex2f(currentNegNormal.x, currentNegNormal.y); + rlEnd(); + + // The current step is the start of the next step + previous = current; + previousTangent = normal; + previousV = v; + } +} + diff --git a/deps/raylib/examples/textures/textures_textured_curve.png b/deps/raylib/examples/textures/textures_textured_curve.png Binary files differnew file mode 100644 index 0000000..6d5efac --- /dev/null +++ b/deps/raylib/examples/textures/textures_textured_curve.png diff --git a/deps/raylib/examples/textures/textures_to_image.c b/deps/raylib/examples/textures/textures_to_image.c new file mode 100644 index 0000000..e1d88c4 --- /dev/null +++ b/deps/raylib/examples/textures/textures_to_image.c @@ -0,0 +1,75 @@ +/******************************************************************************************* +* +* raylib [textures] example - Retrieve image data from texture: LoadImageFromTexture() +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* Example originally created with raylib 1.3, last time updated with raylib 4.0 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM) + Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM) + UnloadImage(image); // Unload image data from CPU memory (RAM) + + image = LoadImageFromTexture(texture); // Load image from GPU texture (VRAM -> RAM) + UnloadTexture(texture); // Unload texture from GPU memory (VRAM) + + texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM) + UnloadImage(image); // Unload retrieved image data from CPU memory (RAM) + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); + + DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/deps/raylib/examples/textures/textures_to_image.png b/deps/raylib/examples/textures/textures_to_image.png Binary files differnew file mode 100644 index 0000000..410103a --- /dev/null +++ b/deps/raylib/examples/textures/textures_to_image.png |