Unit1.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.Material"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma resource "*.dfm"
  15. TForm1 *Form1;
  16. //---------------------------------------------------------------------------
  17. __fastcall TForm1::TForm1(TComponent* Owner)
  18. : TForm(Owner)
  19. {
  20. }
  21. //---------------------------------------------------------------------------
  22. void __fastcall TForm1::Button1Click(TObject *Sender)
  23. {
  24. int i;
  25. Graphics::TBitmap *bmp;
  26. // We generate a handful of bitmaps from scratch
  27. // you could also load them from a set of files, extract from an AVI etc.
  28. for (i = 0; i <= 9; i++) {
  29. bmp = new TBitmap;
  30. bmp->PixelFormat = pf24bit;
  31. bmp->Width = 60;
  32. bmp->Height = 60;
  33. bmp->Canvas->Font->Name = "Arial";
  34. bmp->Canvas->Font->Height = 56;
  35. bmp->Canvas->TextOutW(15, 5, i);
  36. GLMaterialLibrary1->AddTextureMaterial("IMG" + IntToStr(i), bmp);
  37. bmp->Free();
  38. }
  39. // Initialize our loop
  40. Cube1->Material->MaterialLibrary = GLMaterialLibrary1;
  41. Cube1->Material->LibMaterialName = "IMG0";
  42. GLMaterialLibrary1->Tag = 0;
  43. // GUI update
  44. CBAnimate->Enabled = true;
  45. Button1->Enabled = false;
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  49. const double newTime)
  50. {
  51. // cube turns slowly
  52. Cube1->Turn(deltaTime * 3);
  53. // cycle textures
  54. if (CBAnimate->Checked){
  55. // coutdown to next frame
  56. timeToNextFrame = timeToNextFrame-deltaTime;
  57. // if it's time for the next frame
  58. if(timeToNextFrame<0){
  59. // first, update frame counter (the Tag property in our sample)
  60. // (such a loop is a little overkill, yeah)
  61. while (timeToNextFrame<0){
  62. timeToNextFrame = timeToNextFrame + 0.2;
  63. GLMaterialLibrary1->Tag = (GLMaterialLibrary1->Tag+1)%10;
  64. }
  65. // then, we update the material reference
  66. Cube1->Material->LibMaterialName = "IMG" + IntToStr(GLMaterialLibrary1->Tag);
  67. }
  68. }
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
  72. {
  73. // stop animation
  74. CBAnimate->Checked = false;
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  78. {
  79. // standard FPS
  80. LabelFPS->Caption = Format("%.1f FPS", ARRAYOFCONST ((GLSceneViewer1->FramesPerSecond())));
  81. }
  82. //---------------------------------------------------------------------------