Beginners_-_TakeScreenshot.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "raylib.h"
  2. int main(void)
  3. {
  4. // Initialization
  5. //--------------------------------------------------------------------------------------
  6. const int screenWidth = 800;
  7. const int screenHeight = 450;
  8. InitWindow(screenWidth, screenHeight, "raylib example.");
  9. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  10. //--------------------------------------------------------------------------------------
  11. // Main game loop
  12. while (!WindowShouldClose()) // Detect window close button or ESC key
  13. {
  14. // Update
  15. //----------------------------------------------------------------------------------
  16. if(IsKeyPressed(KEY_S)){
  17. TakeScreenshot("screenshot.png");
  18. // Be sure to not place this function inside a loop where
  19. // it saves a screenshot every frame!
  20. }
  21. //----------------------------------------------------------------------------------
  22. // Draw
  23. //----------------------------------------------------------------------------------
  24. BeginDrawing();
  25. ClearBackground(RAYWHITE);
  26. DrawText("Press key 's' to take a screenshot..",200,200,20,GRAY);
  27. EndDrawing();
  28. //----------------------------------------------------------------------------------
  29. }
  30. // De-Initialization
  31. //--------------------------------------------------------------------------------------
  32. CloseWindow(); // Close window and OpenGL context
  33. //--------------------------------------------------------------------------------------
  34. return 0;
  35. }