demo15.pas 2.9 KB

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