Unit1.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.GeomObjects"
  12. #pragma link "GLS.HUDObjects"
  13. #pragma link "GLS.Objects"
  14. #pragma link "GLS.Scene"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma resource "*.dfm"
  17. TForm1 *Form1;
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20. : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::FormCreate(TObject *Sender)
  25. {
  26. Frames = 5;
  27. HUD->Material->FrontProperties->Diffuse->Alpha = 1.0 - (float)1.00/Frames;
  28. }
  29. //---------------------------------------------------------------------------
  30. void __fastcall TForm1::GLSceneViewerPostRender(TObject *Sender)
  31. {
  32. // render is done, we transfer it to our hud plane so it can be used
  33. // in the next frame
  34. GLSceneViewer->Buffer->CopyToTexture(HUD->Material->Texture);
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::FormResize(TObject *Sender)
  38. {
  39. int w, h;
  40. // Here we resize our texture and plane to follow window dimension changes
  41. // Note that we have to stick to power of two texture dimensions if we don't
  42. // want performance to drop dramatically, this implies we can waste 3/4
  43. // of our texture memory... (f.i. a 513x513 window will require and use
  44. // a 1024x1024 texture)
  45. w = RoundUpToPowerOf2(GLSceneViewer->Width);
  46. h = RoundUpToPowerOf2(GLSceneViewer->Height);
  47. HUD->Material->Texture->DestroyHandles();
  48. /*
  49. HUD->Material->Texture->Image->Width = w;
  50. HUD->Material->Texture->Image->Height = h;
  51. */
  52. HUD->Position->X = w*0.5;
  53. HUD->Position->Y = GLSceneViewer->Height - h*0.5;
  54. HUD->Width = w;
  55. HUD->Height = h;
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  59. const double newTime)
  60. {
  61. // make things move
  62. Cube->TurnAngle = newTime*90;
  63. DummyCube->PitchAngle = newTime*60;
  64. Dodecahedron->RollAngle = newTime*15;
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
  68. {
  69. // turn on/off VSync, this has an obvious impact on framerate,
  70. // which in turns impacts the motion blur look
  71. if ((IsKeyDown('s') || IsKeyDown('S'))
  72. || (IsKeyDown('v') || IsKeyDown('V')))
  73. if (GLSceneViewer->VSync == vsmNoSync)
  74. GLSceneViewer->VSync = vsmSync;
  75. else
  76. GLSceneViewer->VSync = vsmNoSync;
  77. // change the number of motion blur frames, and adjust
  78. // the transparency of the plane accordingly
  79. if (Key == VK_UP) Frames++;
  80. if ((Key == VK_DOWN) && (Frames>0)) Frames--;
  81. if (Frames == 0)
  82. HUD->Visible = false;
  83. else
  84. {
  85. HUD->Visible = true;
  86. HUD->Material->FrontProperties->Diffuse->Alpha = 1 - (float)1/(1+Frames);
  87. }
  88. }
  89. // standard issue camera movement
  90. //---------------------------------------------------------------------------
  91. void __fastcall TForm1::GLSceneViewerMouseDown(TObject *Sender, TMouseButton Button,
  92. TShiftState Shift, int X, int Y)
  93. {
  94. mx = X; my = Y;
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TForm1::GLSceneViewerMouseMove(TObject *Sender, TShiftState Shift,
  98. int X, int Y)
  99. {
  100. if (Shift.Contains(ssLeft))
  101. Camera->MoveAroundTarget(my-Y, mx-X);
  102. mx = X; my = Y;
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  106. {
  107. // const String cVSync[vsmSync][vsmNoSync] = {"VSync ON", "VSync OFF"};
  108. Panel1->Caption = Format("Motion Blur on %d Frames %f FPS",
  109. ARRAYOFCONST ((Frames, GLSceneViewer->FramesPerSecond())));
  110. GLSceneViewer->ResetPerformanceMonitor();
  111. }
  112. //---------------------------------------------------------------------------