diff --git a/examples/Makefile b/examples/Makefile index 8517a91c..82e41f63 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -431,7 +431,7 @@ TEXTURES = \ textures/textures_blend_modes \ textures/textures_draw_tiled \ textures/textures_polygon \ - textures/textures_gif_anim + textures/textures_gif_player TEXT = \ text/text_raylib_fonts \ diff --git a/examples/README.md b/examples/README.md index 6fb65514..4769ff55 100644 --- a/examples/README.md +++ b/examples/README.md @@ -96,7 +96,7 @@ Examples using raylib textures functionality, including image/textures loading/g | 57 | [textures_blend_modes](textures/textures_blend_modes.c) | textures_blend_modes | [Karlo Licudine](https://github.com/accidentalrebel) | | | 58 | [textures_draw_tiled](textures/textures_draw_tiled.c) | textures_draw_tiled | [Vlad Adrian](https://github.com/demizdor) | | | -- | [textures_poly](textures/textures_poly.c) | textures_poly | [Chris Camacho](https://github.com/codifies) | ⭐️ | -| -- | [textures_gif_anim](textures/textures_gif_anim.c) | textures_gif_anim | [Chris Camacho](https://github.com/codifies) | ⭐️ | +| -- | [textures_gif_player](textures/textures_gif_player.c) | textures_gif_player | [Chris Camacho](https://github.com/codifies) | ⭐️ | ### category: text diff --git a/examples/textures/resources/scarfy_run.gif b/examples/textures/resources/scarfy_run.gif new file mode 100644 index 00000000..f0f712cc Binary files /dev/null and b/examples/textures/resources/scarfy_run.gif differ diff --git a/examples/textures/textures_gif_player.c b/examples/textures/textures_gif_player.c new file mode 100644 index 00000000..0bb42f16 --- /dev/null +++ b/examples/textures/textures_gif_player.c @@ -0,0 +1,119 @@ +/******************************************************************************************* +* +* raylib [textures] example - gif playing +* +* This example has been created using raylib 4.2 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2021-2022 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/examples/textures/textures_gif_player.png b/examples/textures/textures_gif_player.png new file mode 100644 index 00000000..20db76ed Binary files /dev/null and b/examples/textures/textures_gif_player.png differ diff --git a/projects/VS2022/examples/textures_gif_player.vcxproj b/projects/VS2022/examples/textures_gif_player.vcxproj new file mode 100644 index 00000000..d6c05cc9 --- /dev/null +++ b/projects/VS2022/examples/textures_gif_player.vcxproj @@ -0,0 +1,387 @@ + + + + + Debug.DLL + Win32 + + + Debug.DLL + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release.DLL + Win32 + + + Release.DLL + x64 + + + Release + Win32 + + + Release + x64 + + + + {191A5289-BA65-4638-A215-C521F0187313} + Win32Proj + textures_gif_player + 10.0 + textures_gif_player + + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + true + $(DefaultPlatformToolset) + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + Application + false + $(DefaultPlatformToolset) + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\build\$(ProjectName)\obj\$(Platform)\$(Configuration)\ + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\textures + WindowsLocalDebugger + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + /FS %(AdditionalOptions) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + Copy Debug DLL to output directory + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;PLATFORM_DESKTOP;%(PreprocessorDefinitions) + CompileAsC + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + Copy Debug DLL to output directory + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + + + Copy Release DLL to output directory + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);PLATFORM_DESKTOP + $(SolutionDir)..\..\src;%(AdditionalIncludeDirectories) + CompileAsC + true + + + Console + true + true + true + raylib.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winmm.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\ + + + xcopy /y /d "$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\raylib.dll" "$(SolutionDir)\build\$(ProjectName)\bin\$(Platform)\$(Configuration)" + + + Copy Release DLL to output directory + + + + + + + + {e89d61ac-55de-4482-afd4-df7242ebc859} + + + + + + \ No newline at end of file diff --git a/projects/VS2022/raylib.sln b/projects/VS2022/raylib.sln index 36c31220..b54bb3b1 100644 --- a/projects/VS2022/raylib.sln +++ b/projects/VS2022/raylib.sln @@ -251,6 +251,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core_window_should_close", EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "textures_fog_of_war", "examples\textures_fog_of_war.vcxproj", "{EBBBF4A0-2DA2-4DE6-B4FE-C6654A2417A0}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "textures_gif_player", "examples\textures_gif_player.vcxproj", "{191A5289-BA65-4638-A215-C521F0187313}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug.DLL|x64 = Debug.DLL|x64 @@ -2099,6 +2101,22 @@ Global {EBBBF4A0-2DA2-4DE6-B4FE-C6654A2417A0}.Release|x64.Build.0 = Release|x64 {EBBBF4A0-2DA2-4DE6-B4FE-C6654A2417A0}.Release|x86.ActiveCfg = Release|Win32 {EBBBF4A0-2DA2-4DE6-B4FE-C6654A2417A0}.Release|x86.Build.0 = Release|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Debug.DLL|x64.Build.0 = Debug.DLL|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Debug|x64.ActiveCfg = Debug|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Debug|x64.Build.0 = Debug|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Debug|x86.ActiveCfg = Debug|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Debug|x86.Build.0 = Debug|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Release.DLL|x64.ActiveCfg = Release.DLL|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Release.DLL|x64.Build.0 = Release.DLL|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Release.DLL|x86.Build.0 = Release.DLL|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Release|x64.ActiveCfg = Release|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Release|x64.Build.0 = Release|x64 + {191A5289-BA65-4638-A215-C521F0187313}.Release|x86.ActiveCfg = Release|Win32 + {191A5289-BA65-4638-A215-C521F0187313}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE