1/*******************************************************************************************
2*
3* raylib [core] example - Scissor test
4*
5* This example has been created using raylib 2.5 (www.raylib.com)
6* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7*
8* Example contributed by Chris Dill (@MysteriousSpace) and reviewed by Ramon Santamaria (@raysan5)
9*
10* Copyright (c) 2019 Chris Dill (@MysteriousSpace)
11*
12********************************************************************************************/
13
14#include "raylib.h"
15
16int main(void)
17{
18 // Initialization
19 //--------------------------------------------------------------------------------------
20 const int screenWidth = 800;
21 const int screenHeight = 450;
22
23 InitWindow(screenWidth, screenHeight, "raylib [core] example - scissor test");
24
25 Rectangle scissorArea = { 0, 0, 300, 300 };
26 bool scissorMode = true;
27
28 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
29 //--------------------------------------------------------------------------------------
30
31 // Main game loop
32 while (!WindowShouldClose()) // Detect window close button or ESC key
33 {
34 // Update
35 //----------------------------------------------------------------------------------
36 if (IsKeyPressed(KEY_S)) scissorMode = !scissorMode;
37
38 // Centre the scissor area around the mouse position
39 scissorArea.x = GetMouseX() - scissorArea.width/2;
40 scissorArea.y = GetMouseY() - scissorArea.height/2;
41 //----------------------------------------------------------------------------------
42
43 // Draw
44 //----------------------------------------------------------------------------------
45 BeginDrawing();
46
47 ClearBackground(RAYWHITE);
48
49 if (scissorMode) BeginScissorMode(scissorArea.x, scissorArea.y, scissorArea.width, scissorArea.height);
50
51 // Draw full screen rectangle and some text
52 // NOTE: Only part defined by scissor area will be rendered
53 DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
54 DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY);
55
56 if (scissorMode) EndScissorMode();
57
58 DrawRectangleLinesEx(scissorArea, 1, BLACK);
59 DrawText("Press S to toggle scissor test", 10, 10, 20, BLACK);
60
61 EndDrawing();
62 //----------------------------------------------------------------------------------
63 }
64
65 // De-Initialization
66 //--------------------------------------------------------------------------------------
67 CloseWindow(); // Close window and OpenGL context
68 //--------------------------------------------------------------------------------------
69
70 return 0;
71}
72