diff --git a/examples/Makefile b/examples/Makefile index c16dbed53..aeee6db78 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -511,6 +511,8 @@ PHYSICS = \ physics/physics_restitution \ physics/physics_shatter +EFFECTS = \ + effects/top_down_lights CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST)) @@ -525,6 +527,7 @@ models: $(MODELS) shaders: $(SHADERS) audio: $(AUDIO) physics: $(PHYSICS) +effects: $(EFFECTS) # Generic compilation pattern # NOTE: Examples must be ready for Android compilation! diff --git a/examples/effects/top_down_lights.c b/examples/effects/top_down_lights.c new file mode 100644 index 000000000..df32d2918 --- /dev/null +++ b/examples/effects/top_down_lights.c @@ -0,0 +1,146 @@ +/******************************************************************************************* +* +* raylib [effects] example - Top Down Lights +* +* Welcome to raylib! +* +* To test examples, just press F6 and execute raylib_compile_execute script +* Note that compiled executable is placed in the same folder as .c file +* +* You can find all basic examples on C:\raylib\raylib\examples folder or +* raylib official webpage: www.raylib.com +* +* Enjoy using raylib. :) +* +* This example has been created using raylib 4.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2021 Jeffery Myers +* +********************************************************************************************/ + +#include "raylib.h" +#include "rlgl.h" + +// Custom Blend Modes +#define RLGL_SRC_ALPHA 0x0302 +#define RLGL_MIN 0x8007 +#define RLGL_MAX 0x8008 + + +#define MAX_BOXES 20 +Rectangle Boxes[MAX_BOXES]; + +typedef struct +{ + Vector2 Vertecies[4]; +}ShadowGeometry; + +#define MAX_SHADOWS 40 // MAX_BOXES * 2. Each box can cast up to two shadow volumes for the edges + +typedef struct +{ + // is this light slot active + bool Active; + + // does this light need to be updated + bool Dirty; + + // is this light in a valid position + bool Valid; + + // Light position + Vector2 Position; + + // alpha mask for the light + RenderTexture Mask; + + // the distance the light touches + float OuterRadius; + + // a cached rectangle of the light bounds to help with culling + Rectangle Bounds; + + ShadowGeometry Shadows[MAX_SHADOWS]; + int ShadowCount; +}LightInfo; + +#define MAX_LIGHTS 16 +LightInfo Lights[MAX_LIGHTS] = { 0 }; + + +// move a light and mark it as dirty so that we update it's mask next frame +void MoveLight(int slot, float x, float y) +{ + Lights[slot].Dirty = true; + Lights[slot].Position.x = x; + Lights[slot].Position.y = y; + + // update the cached bounds + Lights[slot].Bounds.x = x - Lights[slot].OuterRadius; + Lights[slot].Bounds.y = y - Lights[slot].OuterRadius; +} + +// setup a light +void SetUpLight(int slot, float x, float y, float radius) +{ + Lights[slot].Active = true; + Lights[slot].Mask = LoadRenderTexture(GetScreenWidth(), GetScreenHeight()); + Lights[slot].OuterRadius = radius; + + Lights[slot].Bounds.width = radius * 2; + Lights[slot].Bounds.height = radius * 2; + + MoveLight(slot, x, y); +} + +// see if a light needs to update it's mask +void UpdateLight(int slot, Rectangle* boxes, int count) +{ + if (!Lights[slot].Active || !Lights[slot].Dirty) + return; + + Lights[slot].Dirty = false; + + Lights[slot].ShadowCount = 0; +} + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [effects] example - top down lights"); + + 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); + + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/effects/top_down_lights.png b/examples/effects/top_down_lights.png new file mode 100644 index 000000000..346184417 Binary files /dev/null and b/examples/effects/top_down_lights.png differ diff --git a/projects/VS2019/examples/top_down_lights.vcxproj b/projects/VS2019/examples/top_down_lights.vcxproj new file mode 100644 index 000000000..10a43b89a --- /dev/null +++ b/projects/VS2019/examples/top_down_lights.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 + + + + {67A9CF3B-A5E8-442E-A437-ED74A08CA312} + Win32Proj + top_down_lights + 10.0 + top_down_lights + + + + 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\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + WindowsLocalDebugger + + + $(SolutionDir)..\..\examples\effects + 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/VS2019/raylib.sln b/projects/VS2019/raylib.sln index aa92a456c..d02a90fbe 100644 --- a/projects/VS2019/raylib.sln +++ b/projects/VS2019/raylib.sln @@ -257,6 +257,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "models_loading_vox", "examp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "models_loading_gltf", "examples\models_loading_gltf.vcxproj", "{F5FC9279-DE63-4EF3-B31F-CFCEF9B11F71}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "effects", "effects", "{CF7D4A13-AD48-42E2-9BD6-6EF466FE04D1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "top_down_lights", "examples\top_down_lights.vcxproj", "{67A9CF3B-A5E8-442E-A437-ED74A08CA312}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug.DLL|x64 = Debug.DLL|x64 @@ -2137,6 +2141,22 @@ Global {F5FC9279-DE63-4EF3-B31F-CFCEF9B11F71}.Release|x64.Build.0 = Release|x64 {F5FC9279-DE63-4EF3-B31F-CFCEF9B11F71}.Release|x86.ActiveCfg = Release|Win32 {F5FC9279-DE63-4EF3-B31F-CFCEF9B11F71}.Release|x86.Build.0 = Release|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug.DLL|x64.Build.0 = Debug.DLL|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug|x64.ActiveCfg = Debug|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug|x64.Build.0 = Debug|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug|x86.ActiveCfg = Debug|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Debug|x86.Build.0 = Debug|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release.DLL|x64.ActiveCfg = Release.DLL|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release.DLL|x64.Build.0 = Release.DLL|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release.DLL|x86.Build.0 = Release.DLL|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release|x64.ActiveCfg = Release|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release|x64.Build.0 = Release|x64 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release|x86.ActiveCfg = Release|Win32 + {67A9CF3B-A5E8-442E-A437-ED74A08CA312}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2267,6 +2287,8 @@ Global {946A1700-C7AA-46F0-AEF2-67C98B5722AC} = {6C82BAAE-BDDF-457D-8FA8-7E2490B07035} {2F1B955B-275E-4D8E-8864-06FEC44D7912} = {AF5BEC5C-1F2B-4DA8-B12D-D09FE569237C} {F5FC9279-DE63-4EF3-B31F-CFCEF9B11F71} = {AF5BEC5C-1F2B-4DA8-B12D-D09FE569237C} + {CF7D4A13-AD48-42E2-9BD6-6EF466FE04D1} = {8716DC0F-4FDE-4F57-8E25-5F78DFB80FE1} + {67A9CF3B-A5E8-442E-A437-ED74A08CA312} = {CF7D4A13-AD48-42E2-9BD6-6EF466FE04D1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E926C768-6307-4423-A1EC-57E95B1FAB29}