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.

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