demo15.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. program demo15;
  2. {$I zglCustomConfig.cfg}
  3. uses
  4. {$IFDEF USE_ZENGL_STATIC}
  5. zgl_main,
  6. zgl_screen,
  7. zgl_window,
  8. zgl_timers,
  9. zgl_keyboard,
  10. zgl_mouse,
  11. zgl_textures,
  12. zgl_textures_png,
  13. zgl_font,
  14. zgl_text,
  15. zgl_primitives_2d,
  16. zgl_sprite_2d,
  17. zgl_video,
  18. zgl_video_theora,
  19. zgl_utils
  20. {$ELSE}
  21. zglHeader
  22. {$ENDIF}
  23. ;
  24. var
  25. dirRes : UTF8String {$IFNDEF MACOSX} = '../data/' {$ENDIF};
  26. fntMain : zglPFont;
  27. video : zglPVideoStream;
  28. videoSeek : Boolean;
  29. procedure Init;
  30. begin
  31. fntMain := font_LoadFromFile( dirRes + 'font.zfi' );
  32. // EN: Open the video file.
  33. // RU: Открыть видео файл.
  34. video := video_OpenFile( dirRes + 'video.ogv' );
  35. end;
  36. procedure Draw;
  37. begin
  38. if Assigned( video ) Then
  39. begin
  40. // EN: Rendering the current video frame in the center of screen using parameters of it from video.Info.
  41. // RU: Рендеринг текущего кадра видео в центре экрана используя параметры из video.Info.
  42. ssprite2d_Draw( video.Texture, ( 800 - video.Info.Width ) / 2, ( 600 - video.Info.Height ) / 2, video.Info.Width, video.Info.Height, 0 );
  43. // EN: Rendering of progress bar.
  44. // RU: Рендеринг полосы прогресса.
  45. pr2d_Rect( 0, 600 - 100, 800, 20, $00FF00, 255 );
  46. pr2d_Rect( 0, 600 - 100, ( 800 / video.Info.Duration ) * video.Time, 20, $00FF00, 155, PR2D_FILL );
  47. text_Draw( fntMain, 0, 0, 'FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) ) );
  48. text_Draw( fntMain, 0, 20, 'Frame: ' + u_IntToStr( video.Frame ) );
  49. text_Draw( fntMain, 100, 0, 'Duration: ' + u_FloatToStr( video.Info.Duration / 1000 ) );
  50. text_Draw( fntMain, 100, 20, 'Frames: ' + u_IntToStr( video.Info.Frames ) );
  51. text_Draw( fntMain, 230, 0, 'Time: ' + u_FloatToStr( video.Time / 1000 ) );
  52. end;
  53. end;
  54. procedure Timer;
  55. begin
  56. if key_Press( K_ESCAPE ) Then zgl_Exit();
  57. // EN: If left mouse button is down on progress bar, then seek the video.
  58. // RU: Если зажата левая кнопка мыши над полосой прогресса - перемещаться по видео.
  59. if mouse_Down( M_BLEFT ) and ( mouse_Y() > 500 ) and ( mouse_Y() < 520 ) Then
  60. begin
  61. videoSeek := TRUE;
  62. video_Seek( video, ( mouse_X() / 800 ) * video.Info.Duration );
  63. end else
  64. videoSeek := FALSE;
  65. key_ClearState();
  66. mouse_ClearState();
  67. end;
  68. procedure Update( dt : Double );
  69. begin
  70. if not videoSeek Then
  71. video_Update( video, dt, TRUE );
  72. end;
  73. Begin
  74. {$IFNDEF USE_ZENGL_STATIC}
  75. if not zglLoad( libZenGL ) Then exit;
  76. {$ENDIF}
  77. randomize();
  78. timer_Add( @Timer, 16 );
  79. zgl_Reg( SYS_LOAD, @Init );
  80. zgl_Reg( SYS_DRAW, @Draw );
  81. zgl_Reg( SYS_UPDATE, @Update );
  82. wnd_SetCaption( '15 - Video' );
  83. wnd_ShowCursor( TRUE );
  84. scr_SetOptions( 800, 600, REFRESH_MAXIMUM, FALSE, FALSE );
  85. zgl_Init();
  86. End.