fTexAnimC.cpp 2.7 KB

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