main_raylib.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <raylib.h>
  3. #include "ffmpeg.h"
  4. #define WIDTH 800
  5. #define HEIGHT 600
  6. #define FPS 30
  7. #define DURATION 10
  8. int main(void)
  9. {
  10. int ffmpeg = ffmpeg_start_rendering(WIDTH, HEIGHT, FPS);
  11. InitWindow(WIDTH, HEIGHT, "FFmpeg");
  12. SetTargetFPS(FPS);
  13. RenderTexture2D screen = LoadRenderTexture(WIDTH, HEIGHT);
  14. float x = WIDTH/2;
  15. float y = HEIGHT/2;
  16. float r = HEIGHT/8;
  17. float dx = 200;
  18. float dy = 200;
  19. float dt = 1.0f/FPS;
  20. for (size_t i = 0; i < FPS*DURATION && !WindowShouldClose(); ++i) {
  21. float nx = x + dx*dt;
  22. if (0 < nx - r && nx + r < WIDTH) {
  23. x = nx;
  24. } else {
  25. dx = -dx;
  26. }
  27. float ny = y + dy*dt;
  28. if (0 < ny - r && ny + r < HEIGHT) {
  29. y = ny;
  30. } else {
  31. dy = -dy;
  32. }
  33. BeginDrawing();
  34. BeginTextureMode(screen);
  35. ClearBackground(GetColor(0x181818FF));
  36. DrawCircle(x, y, r, GetColor(0xFF0000FF));
  37. EndTextureMode();
  38. ClearBackground(GetColor(0x181818FF));
  39. DrawTexture(screen.texture, 0, 0, WHITE);
  40. EndDrawing();
  41. Image image = LoadImageFromTexture(screen.texture);
  42. ffmpeg_send_frame_flipped(ffmpeg, image.data, WIDTH, HEIGHT);
  43. UnloadImage(image);
  44. }
  45. UnloadRenderTexture(screen);
  46. CloseWindow();
  47. ffmpeg_end_rendering(ffmpeg);
  48. printf("Done rendering the video!\n");
  49. return 0;
  50. }