[examples] Improve core_smooth_pixelperfect (#5803)

* Improve smooth pixel-perfect example: add overscan and smoothing toggles

* Add render size
This commit is contained in:
RaZe
2026-04-27 03:08:12 -05:00
committed by GitHub
parent 8e82249f65
commit ba72d25867
2 changed files with 29 additions and 5 deletions

View File

@ -52,7 +52,7 @@ int main(void)
// The target's height is flipped (in the source Rectangle), due to OpenGL reasons
Rectangle sourceRec = { 0.0f, 0.0f, (float)target.texture.width, -(float)target.texture.height };
Rectangle destRec = { -virtualRatio, -virtualRatio, screenWidth + (virtualRatio*2), screenHeight + (virtualRatio*2) };
Rectangle destRec = { (screenWidth - screenWidth/1.25f)/2.0f, (screenHeight - screenHeight/1.25f)/2.0f, screenWidth/1.25f, screenHeight/1.25f };
Vector2 origin = { 0.0f, 0.0f };
@ -61,6 +61,9 @@ int main(void)
float cameraX = 0.0f;
float cameraY = 0.0f;
bool smoothOn = true;
bool overscan = false;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@ -86,6 +89,18 @@ int main(void)
worldSpaceCamera.target.y = truncf(screenSpaceCamera.target.y);
screenSpaceCamera.target.y -= worldSpaceCamera.target.y;
screenSpaceCamera.target.y *= virtualRatio;
if (IsKeyPressed(KEY_S)) smoothOn = !smoothOn;
if (IsKeyPressed(KEY_O)) overscan = !overscan;
if (overscan)
{
destRec = (Rectangle) { -virtualRatio, -virtualRatio, screenWidth + (virtualRatio*2), screenHeight + (virtualRatio*2) };
}
else
{
destRec = (Rectangle) { (screenWidth - screenWidth/1.25f)/2.0f, (screenHeight - screenHeight/1.25f)/2.0f, screenWidth/1.25f, screenHeight/1.25f };
}
//----------------------------------------------------------------------------------
// Draw
@ -101,14 +116,23 @@ int main(void)
EndTextureMode();
BeginDrawing();
ClearBackground(RED);
ClearBackground(LIGHTGRAY);
BeginMode2D(screenSpaceCamera);
if (smoothOn)
{
BeginMode2D(screenSpaceCamera);
DrawTexturePro(target.texture, sourceRec, destRec, origin, 0.0f, WHITE);
EndMode2D();
}
else
{
DrawTexturePro(target.texture, sourceRec, destRec, origin, 0.0f, WHITE);
EndMode2D();
}
DrawText(TextFormat("Screen resolution: %ix%i", screenWidth, screenHeight), 10, 10, 20, DARKBLUE);
DrawText(TextFormat("World resolution: %ix%i", virtualScreenWidth, virtualScreenHeight), 10, 40, 20, DARKGREEN);
DrawText(TextFormat("Smooth: %s", (smoothOn ? "ON" : "OFF")), 10, screenHeight - 60, 20, RED);
DrawText(TextFormat("Overscan: %s", (overscan ? "ON" : "OFF")), 10, screenHeight - 30, 20, RED);
DrawFPS(GetScreenWidth() - 95, 10);
EndDrawing();
//----------------------------------------------------------------------------------
@ -122,4 +146,4 @@ int main(void)
//--------------------------------------------------------------------------------------
return 0;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB