core_scissor_test.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Scissor test
  4. *
  5. * Example complexity rating: [★☆☆☆] 1/4
  6. *
  7. * Example originally created with raylib 2.5, last time updated with raylib 3.0
  8. *
  9. * Example contributed by Chris Dill (@MysteriousSpace) and reviewed by Ramon Santamaria (@raysan5)
  10. *
  11. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  12. * BSD-like license that allows static linking with closed source software
  13. *
  14. * Copyright (c) 2019-2025 Chris Dill (@MysteriousSpace)
  15. *
  16. ********************************************************************************************/
  17. #include "raylib.h"
  18. //------------------------------------------------------------------------------------
  19. // Program main entry point
  20. //------------------------------------------------------------------------------------
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [core] example - scissor test");
  28. Rectangle scissorArea = { 0, 0, 300, 300 };
  29. bool scissorMode = true;
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. if (IsKeyPressed(KEY_S)) scissorMode = !scissorMode;
  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. // Draw
  43. //----------------------------------------------------------------------------------
  44. BeginDrawing();
  45. ClearBackground(RAYWHITE);
  46. if (scissorMode) BeginScissorMode((int)scissorArea.x, (int)scissorArea.y, (int)scissorArea.width, (int)scissorArea.height);
  47. // Draw full screen rectangle and some text
  48. // NOTE: Only part defined by scissor area will be rendered
  49. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
  50. DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY);
  51. if (scissorMode) EndScissorMode();
  52. DrawRectangleLinesEx(scissorArea, 1, BLACK);
  53. DrawText("Press S to toggle scissor test", 10, 10, 20, BLACK);
  54. EndDrawing();
  55. //----------------------------------------------------------------------------------
  56. }
  57. // De-Initialization
  58. //--------------------------------------------------------------------------------------
  59. CloseWindow(); // Close window and OpenGL context
  60. //--------------------------------------------------------------------------------------
  61. return 0;
  62. }