You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.7 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
  4. *
  5. * Example originally created with raylib 1.0, last time updated with raylib 4.0
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2014-2022 Ramon Santamaria (@raysan5)
  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 [shapes] example - basic shapes drawing");
  24. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  25. //--------------------------------------------------------------------------------------
  26. // Main game loop
  27. while (!WindowShouldClose()) // Detect window close button or ESC key
  28. {
  29. // Update
  30. //----------------------------------------------------------------------------------
  31. // TODO: Update your variables here
  32. //----------------------------------------------------------------------------------
  33. // Draw
  34. //----------------------------------------------------------------------------------
  35. BeginDrawing();
  36. ClearBackground(RAYWHITE);
  37. DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
  38. // Circle shapes and lines
  39. DrawCircle(screenWidth/5, 120, 35, DARKBLUE);
  40. DrawCircleGradient(screenWidth/5, 220, 60, GREEN, SKYBLUE);
  41. DrawCircleLines(screenWidth/5, 340, 80, DARKBLUE);
  42. // Rectangle shapes and ines
  43. DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
  44. DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
  45. DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines
  46. // Triangle shapes and lines
  47. DrawTriangle((Vector2){screenWidth/4.0f *3.0f, 80.0f},
  48. (Vector2){screenWidth/4.0f *3.0f - 60.0f, 150.0f},
  49. (Vector2){screenWidth/4.0f *3.0f + 60.0f, 150.0f}, VIOLET);
  50. DrawTriangleLines((Vector2){screenWidth/4.0f*3.0f, 160.0f},
  51. (Vector2){screenWidth/4.0f*3.0f - 20.0f, 230.0f},
  52. (Vector2){screenWidth/4.0f*3.0f + 20.0f, 230.0f}, DARKBLUE);
  53. // Polygon shapes and lines
  54. DrawPoly((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, BROWN);
  55. DrawPolyLinesEx((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, 6, BEIGE);
  56. // NOTE: We draw all LINES based shapes together to optimize internal drawing,
  57. // this way, all LINES are rendered in a single draw pass
  58. DrawLine(18, 42, screenWidth - 18, 42, BLACK);
  59. EndDrawing();
  60. //----------------------------------------------------------------------------------
  61. }
  62. // De-Initialization
  63. //--------------------------------------------------------------------------------------
  64. CloseWindow(); // Close window and OpenGL context
  65. //--------------------------------------------------------------------------------------
  66. return 0;
  67. }