Skip to content

Commit

Permalink
example resize fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jopadan committed Feb 25, 2025
1 parent e4993c5 commit 9472356
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/shaders/shaders_model_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(void)

EndMode3D();

DrawText("(c) Watermill 3D model by Alberto Cano", screenWidth - 210, screenHeight - 20, 10, GRAY);
DrawText("(c) Watermill 3D model by Alberto Cano", GetScreenWidth() - 210, GetScreenHeight() - 20, 10, GRAY);

DrawFPS(10, 10);

Expand All @@ -106,4 +106,4 @@ int main(void)
//--------------------------------------------------------------------------------------

return 0;
}
}
8 changes: 5 additions & 3 deletions examples/shaders/shaders_postprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ int main(void)

// Draw
//----------------------------------------------------------------------------------
UnloadRenderTexture(target);
target = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
BeginTextureMode(target); // Enable drawing to texture
ClearBackground(RAYWHITE); // Clear texture background

Expand All @@ -148,17 +150,17 @@ int main(void)
// Render generated texture using selected postprocessing shader
BeginShaderMode(shaders[currentShader]);
// 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);
DrawTextureRec(target.texture, (Rectangle){ 0, 0, (float)GetScreenWidth(), (float)-GetScreenHeight() }, (Vector2){0, 0}, WHITE);
EndShaderMode();

// Draw 2d shapes and text over drawn texture
DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f));

DrawText("(c) Church 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
DrawText("(c) Church 3D model by Alberto Cano", GetScreenWidth() - 200, GetScreenHeight() - 20, 10, GRAY);
DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK);
DrawText(postproShaderText[currentShader], 330, 15, 20, RED);
DrawText("< >", 540, 10, 30, DARKBLUE);
DrawFPS(700, 15);
DrawFPS(GetScreenWidth() - 100, 15);
EndDrawing();
//----------------------------------------------------------------------------------
}
Expand Down
2 changes: 1 addition & 1 deletion examples/shaders/shaders_shadowmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int main(void)

EndMode3D();

DrawText("Shadows in raylib using the shadowmapping algorithm!", screenWidth - 320, screenHeight - 20, 10, GRAY);
DrawText("Shadows in raylib using the shadowmapping algorithm!", GetScreenWidth() - 320, GetScreenHeight() - 20, 10, GRAY);
DrawText("Use the arrow keys to rotate the light!", 10, 10, 30, RED);

EndDrawing();
Expand Down
25 changes: 14 additions & 11 deletions examples/shaders/shaders_spotlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int main(void)
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 < GetScreenWidth()/2.0; m++)
{
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);
}
Expand Down Expand Up @@ -124,8 +124,8 @@ int main(void)
// and initialize the shader locations
for (int i = 0; i < MAX_SPOTS; i++)
{
spots[i].position.x = (float)GetRandomValue(64, screenWidth - 64);
spots[i].position.y = (float)GetRandomValue(64, screenHeight - 64);
spots[i].position.x = (float)GetRandomValue(64, GetScreenWidth() - 64);
spots[i].position.y = (float)GetRandomValue(64, GetScreenHeight() - 64);
spots[i].speed = (Vector2){ 0, 0 };

while ((fabs(spots[i].speed.x) + fabs(spots[i].speed.y)) < 2)
Expand All @@ -152,6 +152,9 @@ int main(void)
//----------------------------------------------------------------------------------
frameCounter++;

sw = (float)GetScreenWidth();
SetShaderValue(shdrSpot, wLoc, &sw, SHADER_UNIFORM_FLOAT);

// Move the stars, resetting them if the go offscreen
for (int n = 0; n < MAX_STARS; n++) UpdateStar(&stars[n]);

Expand All @@ -162,17 +165,17 @@ int main(void)
{
Vector2 mp = GetMousePosition();
spots[i].position.x = mp.x;
spots[i].position.y = screenHeight - mp.y;
spots[i].position.y = GetScreenHeight() - mp.y;
}
else
{
spots[i].position.x += spots[i].speed.x;
spots[i].position.y += spots[i].speed.y;

if (spots[i].position.x < 64) spots[i].speed.x = -spots[i].speed.x;
if (spots[i].position.x > (screenWidth - 64)) spots[i].speed.x = -spots[i].speed.x;
if (spots[i].position.x > (GetScreenWidth() - 64)) spots[i].speed.x = -spots[i].speed.x;
if (spots[i].position.y < 64) spots[i].speed.y = -spots[i].speed.y;
if (spots[i].position.y > (screenHeight - 64)) spots[i].speed.y = -spots[i].speed.y;
if (spots[i].position.y > (GetScreenHeight() - 64)) spots[i].speed.y = -spots[i].speed.y;
}

SetShaderValue(shdrSpot, spots[i].positionLoc, &spots[i].position.x, SHADER_UNIFORM_VEC2);
Expand All @@ -194,8 +197,8 @@ int main(void)
for (int i = 0; i < 16; i++)
{
DrawTexture(texRay,
(int)((screenWidth/2.0f) + cos((frameCounter + i*8)/51.45f)*(screenWidth/2.2f) - 32),
(int)((screenHeight/2.0f) + sin((frameCounter + i*8)/17.87f)*(screenHeight/4.2f)), WHITE);
(int)((GetScreenWidth()/2.0f) + cos((frameCounter + i*8)/51.45f)*(GetScreenWidth()/2.2f) - 32),
(int)((GetScreenHeight()/2.0f) + sin((frameCounter + i*8)/17.87f)*(GetScreenHeight()/4.2f)), WHITE);
}

// Draw spot lights
Expand All @@ -204,14 +207,14 @@ int main(void)
// a render texture of the full screen used to do screen
// scaling (slight adjustment to shader would be required
// to actually pay attention to the colour!)
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), WHITE);
EndShaderMode();

DrawFPS(10, 10);

DrawText("Move the mouse!", 10, 30, 20, GREEN);
DrawText("Pitch Black", (int)(screenWidth*0.2f), screenHeight/2, 20, GREEN);
DrawText("Dark", (int)(screenWidth*.66f), screenHeight/2, 20, GREEN);
DrawText("Pitch Black", (int)(GetScreenWidth()*0.2f), GetScreenHeight()/2, 20, GREEN);
DrawText("Dark", (int)(GetScreenWidth()*.66f), GetScreenHeight()/2, 20, GREEN);

EndDrawing();
//----------------------------------------------------------------------------------
Expand Down

0 comments on commit 9472356

Please sign in to comment.