Unit1.cpp 2.9 KB

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