summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorRay <[email protected]>2019-04-11 17:40:13 +0200
committerRay <[email protected]>2019-04-11 17:40:13 +0200
commit24f07aaf5a58aa1fc1d18a9eae4327f5a3f58014 (patch)
tree57e0eb2c2810c250b4ecb54def15a2060b50caee /examples
parent129703fad18b478d015a520524d46ab4afa2cb79 (diff)
downloadraylib-24f07aaf5a58aa1fc1d18a9eae4327f5a3f58014.tar.gz
raylib-24f07aaf5a58aa1fc1d18a9eae4327f5a3f58014.zip
new example: core_window_scale_letterbox
Diffstat (limited to 'examples')
-rw-r--r--examples/core/core_window_scale_letterbox.c88
-rw-r--r--examples/core/core_window_scale_letterbox.pngbin0 -> 17967 bytes
2 files changed, 88 insertions, 0 deletions
diff --git a/examples/core/core_window_scale_letterbox.c b/examples/core/core_window_scale_letterbox.c
new file mode 100644
index 00000000..ea4a375a
--- /dev/null
+++ b/examples/core/core_window_scale_letterbox.c
@@ -0,0 +1,88 @@
+/*******************************************************************************************
+*
+* raylib [core] example - window scale letterbox
+*
+* 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)
+*
+* Copyright (c) 2019 Anata and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#define max(a, b) ((a)>(b)? (a) : (b))
+#define min(a, b) ((a)<(b)? (a) : (b))
+
+int main()
+{
+ const int windowWidth = 800;
+ const int windowHeight = 450;
+
+ // Enable config flags for resizable window and vertical synchro
+ SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
+ InitWindow(windowWidth, windowHeight, "raylib [core] example - window scale letterbox");
+ SetWindowMinSize(320, 240);
+
+ int gameScreenWidth = 640;
+ int gameScreenHeight = 480;
+
+ // Render texture initialization
+ RenderTexture2D target = LoadRenderTexture(gameScreenWidth, gameScreenHeight);
+ SetTextureFilter(target.texture, FILTER_BILINEAR); // Texture scale filter to use
+
+ Color colors[10] = { 0 };
+ for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while( !WindowShouldClose() ) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // Compute required framebuffer scaling
+ float scale = min((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight);
+
+ if (IsKeyPressed(KEY_SPACE))
+ {
+ // Recalculate random colors for the bars
+ for (int i = 0; i < 10; i++) colors[i] = (Color){ GetRandomValue(100, 250), GetRandomValue(50, 150), GetRandomValue(10, 100), 255 };
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+ ClearBackground(BLACK);
+
+ // Draw everything in the render texture
+ BeginTextureMode(target);
+
+ ClearBackground(RAYWHITE); // Clear render texture background color
+
+ for (int i = 0; i < 10; i++) DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i]);
+
+ DrawText("You can resize the window,\nand see the screen scaling!", 10, 25, 20, WHITE);
+
+ EndTextureMode();
+
+ // Draw RenderTexture2D to window, properly scaled
+ DrawTexturePro(target.texture, (Rectangle){ 0.0f, 0.0f, (float)target.texture.width, (float)-target.texture.height },
+ (Rectangle){ (GetScreenWidth() - ((float)gameScreenWidth*scale))*0.5, (GetScreenHeight() - ((float)gameScreenHeight*scale))*0.5,
+ (float)gameScreenWidth*scale, (float)gameScreenHeight*scale }, (Vector2){ 0, 0 }, 0.0f, WHITE);
+
+ EndDrawing();
+ //--------------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadRenderTexture(target); // Unload render texture
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/core/core_window_scale_letterbox.png b/examples/core/core_window_scale_letterbox.png
new file mode 100644
index 00000000..5acf2d7c
--- /dev/null
+++ b/examples/core/core_window_scale_letterbox.png
Binary files differ