core_scissor_test.c 3.1 KB

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