12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /*******************************************************************************************
- *
- * raylib [core] example - Scissor test
- *
- * Example originally created with raylib 2.5, last time updated with raylib 3.0
- *
- * Example contributed by Chris Dill (@MysteriousSpace) and reviewed by Ramon Santamaria (@raysan5)
- *
- * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
- * BSD-like license that allows static linking with closed source software
- *
- * Copyright (c) 2019-2024 Chris Dill (@MysteriousSpace)
- *
- ********************************************************************************************/
- #include "raylib.h"
- //------------------------------------------------------------------------------------
- // Program main entry point
- //------------------------------------------------------------------------------------
- int main(void)
- {
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = 800;
- const int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib [core] example - scissor test");
- Rectangle scissorArea = { 0, 0, 300, 300 };
- bool scissorMode = true;
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //--------------------------------------------------------------------------------------
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- // Update
- //----------------------------------------------------------------------------------
- if (IsKeyPressed(KEY_S)) scissorMode = !scissorMode;
- // Centre the scissor area around the mouse position
- scissorArea.x = GetMouseX() - scissorArea.width/2;
- scissorArea.y = GetMouseY() - scissorArea.height/2;
- //----------------------------------------------------------------------------------
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
- ClearBackground(RAYWHITE);
- if (scissorMode) BeginScissorMode((int)scissorArea.x, (int)scissorArea.y, (int)scissorArea.width, (int)scissorArea.height);
- // Draw full screen rectangle and some text
- // NOTE: Only part defined by scissor area will be rendered
- DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
- DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY);
- if (scissorMode) EndScissorMode();
- DrawRectangleLinesEx(scissorArea, 1, BLACK);
- DrawText("Press S to toggle scissor test", 10, 10, 20, BLACK);
- EndDrawing();
- //----------------------------------------------------------------------------------
- }
- // De-Initialization
- //--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
- return 0;
- }
|