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.

88 lines
3.9 KiB

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