Skip to content

Commit ba72d25

Browse files
authored
[examples] Improve core_smooth_pixelperfect (#5803)
* Improve smooth pixel-perfect example: add overscan and smoothing toggles * Add render size
1 parent 8e82249 commit ba72d25

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

examples/core/core_smooth_pixelperfect.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main(void)
5252

5353
// The target's height is flipped (in the source Rectangle), due to OpenGL reasons
5454
Rectangle sourceRec = { 0.0f, 0.0f, (float)target.texture.width, -(float)target.texture.height };
55-
Rectangle destRec = { -virtualRatio, -virtualRatio, screenWidth + (virtualRatio*2), screenHeight + (virtualRatio*2) };
55+
Rectangle destRec = { (screenWidth - screenWidth/1.25f)/2.0f, (screenHeight - screenHeight/1.25f)/2.0f, screenWidth/1.25f, screenHeight/1.25f };
5656

5757
Vector2 origin = { 0.0f, 0.0f };
5858

@@ -61,6 +61,9 @@ int main(void)
6161
float cameraX = 0.0f;
6262
float cameraY = 0.0f;
6363

64+
bool smoothOn = true;
65+
bool overscan = false;
66+
6467
SetTargetFPS(60);
6568
//--------------------------------------------------------------------------------------
6669

@@ -86,6 +89,18 @@ int main(void)
8689
worldSpaceCamera.target.y = truncf(screenSpaceCamera.target.y);
8790
screenSpaceCamera.target.y -= worldSpaceCamera.target.y;
8891
screenSpaceCamera.target.y *= virtualRatio;
92+
93+
if (IsKeyPressed(KEY_S)) smoothOn = !smoothOn;
94+
if (IsKeyPressed(KEY_O)) overscan = !overscan;
95+
96+
if (overscan)
97+
{
98+
destRec = (Rectangle) { -virtualRatio, -virtualRatio, screenWidth + (virtualRatio*2), screenHeight + (virtualRatio*2) };
99+
}
100+
else
101+
{
102+
destRec = (Rectangle) { (screenWidth - screenWidth/1.25f)/2.0f, (screenHeight - screenHeight/1.25f)/2.0f, screenWidth/1.25f, screenHeight/1.25f };
103+
}
89104
//----------------------------------------------------------------------------------
90105

91106
// Draw
@@ -101,14 +116,23 @@ int main(void)
101116
EndTextureMode();
102117

103118
BeginDrawing();
104-
ClearBackground(RED);
105-
106-
BeginMode2D(screenSpaceCamera);
119+
ClearBackground(LIGHTGRAY);
120+
121+
if (smoothOn)
122+
{
123+
BeginMode2D(screenSpaceCamera);
124+
DrawTexturePro(target.texture, sourceRec, destRec, origin, 0.0f, WHITE);
125+
EndMode2D();
126+
}
127+
else
128+
{
107129
DrawTexturePro(target.texture, sourceRec, destRec, origin, 0.0f, WHITE);
108-
EndMode2D();
130+
}
109131

110132
DrawText(TextFormat("Screen resolution: %ix%i", screenWidth, screenHeight), 10, 10, 20, DARKBLUE);
111133
DrawText(TextFormat("World resolution: %ix%i", virtualScreenWidth, virtualScreenHeight), 10, 40, 20, DARKGREEN);
134+
DrawText(TextFormat("Smooth: %s", (smoothOn ? "ON" : "OFF")), 10, screenHeight - 60, 20, RED);
135+
DrawText(TextFormat("Overscan: %s", (overscan ? "ON" : "OFF")), 10, screenHeight - 30, 20, RED);
112136
DrawFPS(GetScreenWidth() - 95, 10);
113137
EndDrawing();
114138
//----------------------------------------------------------------------------------
@@ -122,4 +146,4 @@ int main(void)
122146
//--------------------------------------------------------------------------------------
123147

124148
return 0;
125-
}
149+
}
-12.1 KB
Loading

0 commit comments

Comments
 (0)