shapes_lines_bezier.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - Cubic-bezier lines
  4. *
  5. * This example has been created using raylib 1.7 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2017 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. Vector2 start = { 0, 0 };
  21. Vector2 end = { 0, 0 };
  22. //----------------------------------------------------------------------------------
  23. // Module Functions Declaration
  24. //----------------------------------------------------------------------------------
  25. void UpdateDrawFrame(void); // Update and Draw one frame
  26. //----------------------------------------------------------------------------------
  27. // Main Enry Point
  28. //----------------------------------------------------------------------------------
  29. int main()
  30. {
  31. // Initialization
  32. //--------------------------------------------------------------------------------------
  33. SetConfigFlags(FLAG_MSAA_4X_HINT);
  34. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines");
  35. end = (Vector2){ screenWidth, screenHeight };
  36. #if defined(PLATFORM_WEB)
  37. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  38. #else
  39. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  40. //--------------------------------------------------------------------------------------
  41. // Main game loop
  42. while (!WindowShouldClose()) // Detect window close button or ESC key
  43. {
  44. UpdateDrawFrame();
  45. }
  46. #endif
  47. // De-Initialization
  48. //--------------------------------------------------------------------------------------
  49. CloseWindow(); // Close window and OpenGL context
  50. //--------------------------------------------------------------------------------------
  51. return 0;
  52. }
  53. //----------------------------------------------------------------------------------
  54. // Module Functions Definition
  55. //----------------------------------------------------------------------------------
  56. void UpdateDrawFrame(void)
  57. {
  58. // Update
  59. //----------------------------------------------------------------------------------
  60. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) start = GetMousePosition();
  61. else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) end = GetMousePosition();
  62. //----------------------------------------------------------------------------------
  63. // Draw
  64. //----------------------------------------------------------------------------------
  65. BeginDrawing();
  66. ClearBackground(RAYWHITE);
  67. DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY);
  68. DrawLineBezier(start, end, 2.0f, RED);
  69. EndDrawing();
  70. //----------------------------------------------------------------------------------
  71. }