Unit1.cpp 4.3 KB

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