Unit1.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLWin32Viewer"
  8. #pragma link "GLAVIRecorder"
  9. #pragma link "GLCadencer"
  10. #pragma link "GLAsyncTimer"
  11. #pragma link "GLObjects"
  12. #pragma link "GLScene"
  13. #pragma link "GLAVIRecorder"
  14. #pragma link "GLKeyboard"
  15. #pragma link "GLBaseClasses"
  16. #pragma link "GLCoordinates"
  17. #pragma link "GLCrossPlatform"
  18. #pragma resource "*.dfm"
  19. TForm1 *Form1;
  20. bool UserAbort;
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm1::TForm1(TComponent * Owner):TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::TrackBarChange(TObject * Sender)
  27. {
  28. int t = TrackBar->Position;
  29. // the "sun" spins slowly
  30. Cube1->TurnAngle = (float)t / 4;
  31. // "earth" rotates around the sun and spins
  32. DummyCube1->TurnAngle = (float)-t;
  33. Cube2->TurnAngle = (float)t *2;
  34. // "moon" rotates around earth and spins
  35. DummyCube2->RollAngle = (float)3 *t;
  36. Cube3->TurnAngle = (float)4 *t;
  37. // update FPS count
  38. StaticText1->Caption =
  39. IntToStr(Trunc(GLSceneViewer1->FramesPerSecond())) + " FPS";
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TForm1::FormResize(TObject * Sender)
  43. {
  44. GLSceneViewer1->ResetPerformanceMonitor();
  45. AVIRecorder1->Width = GLSceneViewer1->Width;
  46. AVIRecorder1->Height = GLSceneViewer1->Height;
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TForm1::Button1Click(TObject * Sender)
  50. {
  51. if(!AVIRecorder1->CreateAVIFile(0))
  52. return;
  53. // if AVIRecorder1.filename is empty, a dialog box will appear asking
  54. // for the filename. CreateAVIFile() will return a bool
  55. // indicating if user presses "cancel" in the dialog box.
  56. String SavedCap = Caption;
  57. Caption = "Press ESC to abort";
  58. UserAbort = false;
  59. StaticText1->Visible = false; // the FPS shown is not correct now,
  60. // so just hide it for the time being.
  61. int i = 0;
  62. Button1->Enabled = false;
  63. TrackBar->Enabled = false;
  64. try
  65. {
  66. while((i < 360) && !UserAbort)
  67. {
  68. TrackBar->Position = i;
  69. TrackBarChange(this);
  70. AVIRecorder1->AddAVIFrame();
  71. // you might want to update your progress bar here.
  72. Application->ProcessMessages(); // so that our app. is not freezed,
  73. // and will accept user abort.
  74. i++;
  75. }
  76. }
  77. __finally
  78. {
  79. AVIRecorder1->CloseAVIFile(UserAbort); // if UserAbort, CloseAVIFile will
  80. // also delete the unfinished file.
  81. Caption = SavedCap;
  82. StaticText1->Visible = true;
  83. Button1->Enabled = true;
  84. TrackBar->Enabled = true;
  85. }
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TForm1::AVIRecorder1PostProcessEvent(TObject * Sender,
  89. TBitmap * frame)
  90. {
  91. // PostProcess event is used to add a "watermark"
  92. // that will be in the AVI, but isn't visible on-screen
  93. TCanvas *c = frame->Canvas;
  94. c->Font->Color = clAqua;
  95. c->Font->Name = "Courrier New";
  96. c->Font->Size = 24;
  97. c->Font->Style = (c->Font->Style << fsBold);
  98. c->Brush->Style = bsClear;
  99. String s;
  100. s.printf("GLScene %.3d", TrackBar->Position);
  101. c->TextOut(20, 20, s);
  102. }
  103. //---------------------------------------------------------------------------
  104. void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
  105. {
  106. UserAbort = IsKeyDown(VK_ESCAPE);
  107. }
  108. //---------------------------------------------------------------------------