core_scissor_test.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. InitWindow(screenWidth, screenHeight, "raylib [core] example - scissor test");
  24. Rectangle scissorArea = { 0, 0, 300, 300 };
  25. bool scissorMode = true;
  26. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  27. //--------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. if (IsKeyPressed(KEY_S)) scissorMode = !scissorMode;
  34. // Centre the scissor area around the mouse position
  35. scissorArea.x = GetMouseX() - scissorArea.width/2;
  36. scissorArea.y = GetMouseY() - scissorArea.height/2;
  37. //----------------------------------------------------------------------------------
  38. // Draw
  39. //----------------------------------------------------------------------------------
  40. BeginDrawing();
  41. ClearBackground(RAYWHITE);
  42. if (scissorMode) BeginScissorMode((int)scissorArea.x, (int)scissorArea.y, (int)scissorArea.width, (int)scissorArea.height);
  43. // Draw full screen rectangle and some text
  44. // NOTE: Only part defined by scissor area will be rendered
  45. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), RED);
  46. DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY);
  47. if (scissorMode) EndScissorMode();
  48. DrawRectangleLinesEx(scissorArea, 1, BLACK);
  49. DrawText("Press S to toggle scissor test", 10, 10, 20, BLACK);
  50. EndDrawing();
  51. //----------------------------------------------------------------------------------
  52. }
  53. // De-Initialization
  54. //--------------------------------------------------------------------------------------
  55. CloseWindow(); // Close window and OpenGL context
  56. //--------------------------------------------------------------------------------------
  57. return 0;
  58. }