summaryrefslogtreecommitdiffhomepage
path: root/examples/shaders/shaders_spotlight.c
diff options
context:
space:
mode:
authorRay <[email protected]>2021-04-22 18:55:24 +0200
committerRay <[email protected]>2021-04-22 18:55:24 +0200
commitdcf52c132fb0ca28f37dae9d957155e2541df812 (patch)
treeb6c263e59daba00fc33badd0a45fa6756d5df14c /examples/shaders/shaders_spotlight.c
parentf92ee46d86b5a0cfb05c10b0c31fb966a4784b44 (diff)
downloadraylib-dcf52c132fb0ca28f37dae9d957155e2541df812.tar.gz
raylib-dcf52c132fb0ca28f37dae9d957155e2541df812.zip
Remove trail spaces
Diffstat (limited to 'examples/shaders/shaders_spotlight.c')
-rw-r--r--examples/shaders/shaders_spotlight.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/examples/shaders/shaders_spotlight.c b/examples/shaders/shaders_spotlight.c
index f924bac7..40fd2317 100644
--- a/examples/shaders/shaders_spotlight.c
+++ b/examples/shaders/shaders_spotlight.c
@@ -5,7 +5,7 @@
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Example contributed by Chris Camacho (@chriscamacho - http://bedroomcoders.co.uk/)
+* Example contributed by Chris Camacho (@chriscamacho - http://bedroomcoders.co.uk/)
* and reviewed by Ramon Santamaria (@raysan5)
*
* Copyright (c) 2019 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
@@ -14,13 +14,13 @@
*
* The shader makes alpha holes in the forground to give the apearance of a top
* down look at a spotlight casting a pool of light...
-*
+*
* The right hand side of the screen there is just enough light to see whats
* going on without the spot light, great for a stealth type game where you
* have to avoid the spotlights.
-*
+*
* The left hand side of the screen is in pitch dark except for where the spotlights are.
-*
+*
* Although this example doesn't scale like the letterbox example, you could integrate
* the two techniques, but by scaling the actual colour of the render texture rather
* than using alpha as a mask.
@@ -43,12 +43,12 @@
#define MAX_STARS 400
// Spot data
-typedef struct {
+typedef struct {
Vector2 pos;
Vector2 vel;
float inner;
float radius;
-
+
// Shader locations
unsigned int posLoc;
unsigned int innerLoc;
@@ -75,26 +75,26 @@ int main(void)
HideCursor();
Texture texRay = LoadTexture("resources/raysan.png");
-
+
Star stars[MAX_STARS] = { 0 };
for (int n = 0; n < MAX_STARS; n++) ResetStar(&stars[n]);
// Progress all the stars on, so they don't all start in the centre
- for (int m = 0; m < screenWidth/2.0; m++)
+ for (int m = 0; m < screenWidth/2.0; m++)
{
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
}
int frameCounter = 0;
-
+
// Use default vert shader
Shader shdrSpot = LoadShader(0, TextFormat("resources/shaders/glsl%i/spotlight.fs", GLSL_VERSION));
-
+
// Get the locations of spots in the shader
Spot spots[MAX_SPOTS];
- for (int i = 0; i < MAX_SPOTS; i++)
+ for (int i = 0; i < MAX_SPOTS; i++)
{
char posName[32] = "spots[x].pos\0";
char innerName[32] = "spots[x].inner\0";
@@ -103,13 +103,13 @@ int main(void)
posName[6] = '0' + i;
innerName[6] = '0' + i;
radiusName[6] = '0' + i;
-
+
spots[i].posLoc = GetShaderLocation(shdrSpot, posName);
spots[i].innerLoc = GetShaderLocation(shdrSpot, innerName);
spots[i].radiusLoc = GetShaderLocation(shdrSpot, radiusName);
-
+
}
-
+
// Tell the shader how wide the screen is so we can have
// a pitch black half and a dimly lit half.
unsigned int wLoc = GetShaderLocation(shdrSpot, "screenWidth");
@@ -123,16 +123,16 @@ int main(void)
spots[i].pos.x = GetRandomValue(64, screenWidth - 64);
spots[i].pos.y = GetRandomValue(64, screenHeight - 64);
spots[i].vel = (Vector2){ 0, 0 };
-
+
while ((fabs(spots[i].vel.x) + fabs(spots[i].vel.y)) < 2)
{
spots[i].vel.x = GetRandomValue(-40, 40)/10.0;
spots[i].vel.y = GetRandomValue(-40, 40)/10.0;
}
-
+
spots[i].inner = 28 * (i + 1);
spots[i].radius = 48 * (i + 1);
-
+
SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
SetShaderValue(shdrSpot, spots[i].innerLoc, &spots[i].inner, SHADER_UNIFORM_FLOAT);
SetShaderValue(shdrSpot, spots[i].radiusLoc, &spots[i].radius, SHADER_UNIFORM_FLOAT);
@@ -140,7 +140,7 @@ int main(void)
SetTargetFPS(60); // Set to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
-
+
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
@@ -157,23 +157,23 @@ int main(void)
if (i == 0)
{
Vector2 mp = GetMousePosition();
- spots[i].pos.x = mp.x;
+ spots[i].pos.x = mp.x;
spots[i].pos.y = screenHeight - mp.y;
}
else
{
- spots[i].pos.x += spots[i].vel.x;
+ spots[i].pos.x += spots[i].vel.x;
spots[i].pos.y += spots[i].vel.y;
-
- if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
- if (spots[i].pos.x > (screenWidth - 64)) spots[i].vel.x = -spots[i].vel.x;
- if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
+
+ if (spots[i].pos.x < 64) spots[i].vel.x = -spots[i].vel.x;
+ if (spots[i].pos.x > (screenWidth - 64)) spots[i].vel.x = -spots[i].vel.x;
+ if (spots[i].pos.y < 64) spots[i].vel.y = -spots[i].vel.y;
if (spots[i].pos.y > (screenHeight - 64)) spots[i].vel.y = -spots[i].vel.y;
}
-
- SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
+
+ SetShaderValue(shdrSpot, spots[i].posLoc, &spots[i].pos.x, SHADER_UNIFORM_VEC2);
}
-
+
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
@@ -204,11 +204,11 @@ int main(void)
EndShaderMode();
DrawFPS(10, 10);
-
+
DrawText("Move the mouse!", 10, 30, 20, GREEN);
DrawText("Pitch Black", screenWidth*0.2f, screenHeight/2, 20, GREEN);
DrawText("Dark", screenWidth*.66f, screenHeight/2, 20, GREEN);
-
+
EndDrawing();
//----------------------------------------------------------------------------------
@@ -229,21 +229,21 @@ int main(void)
void ResetStar(Star *s)
{
s->pos = (Vector2){ GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
-
+
do
{
s->vel.x = (float)GetRandomValue(-1000, 1000)/100.0f;
s->vel.y = (float)GetRandomValue(-1000, 1000)/100.0f;
-
+
} while (!(fabs(s->vel.x) + (fabs(s->vel.y) > 1)));
-
+
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8.0f, 8.0f }));
}
void UpdateStar(Star *s)
{
s->pos = Vector2Add(s->pos, s->vel);
-
+
if ((s->pos.x < 0) || (s->pos.x > GetScreenWidth()) ||
(s->pos.y < 0) || (s->pos.y > GetScreenHeight()))
{