fTexFormatC.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <System.SysUtils.hpp>
  4. #pragma hdrstop
  5. #include "fTexFormatC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.HUDObjects"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma resource "*.dfm"
  15. TFormFormats* FormFormats;
  16. //---------------------------------------------------------------------------
  17. __fastcall TFormFormats::TFormFormats(TComponent* Owner) : TForm(Owner) {}
  18. //---------------------------------------------------------------------------
  19. void __fastcall TFormFormats::FormCreate(TObject* Sender)
  20. {
  21. TSearchRec sr;
  22. int i;
  23. PathToData = GetCurrentAssetPath();
  24. SetCurrentDir(PathToData + "\\texture");
  25. // collect JPeg textures from the demos' media directory
  26. i = FindFirst("*.jpg", faAnyFile, sr);
  27. while (i == 0) {
  28. CBImage->Items->Add(sr.Name);
  29. i = FindNext(sr);
  30. }
  31. FindClose(sr);
  32. // default selection
  33. CBFormat->ItemIndex = 0;
  34. CBCompression->ItemIndex = 0;
  35. CBImage->ItemIndex = 0;
  36. CBImageChange(Sender);
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TFormFormats::CBImageChange(TObject* Sender)
  40. {
  41. // adjust settings from selection and reload the texture map
  42. HUDSprite1->Material->Texture->TextureFormat =
  43. TGLTextureFormat((int)tfRGB + CBFormat->ItemIndex);
  44. HUDSprite1->Material->Texture->Compression =
  45. TGLTextureCompression((int)tcNone + CBCompression->ItemIndex);
  46. HUDSprite1->Material->Texture->Image->LoadFromFile(CBImage->Text);
  47. LAPicSize->Caption = IntToStr(HUDSprite1->Material->Texture->Image->Width) +
  48. " x " +
  49. IntToStr(HUDSprite1->Material->Texture->Image->Height);
  50. if (RBDefault->Checked) {
  51. HUDSprite1->Width = HUDSprite1->Material->Texture->Image->Width;
  52. HUDSprite1->Height = HUDSprite1->Material->Texture->Image->Height;
  53. } else {
  54. if (RBDouble->Checked) {
  55. HUDSprite1->Width = HUDSprite1->Material->Texture->Image->Width * 2;
  56. HUDSprite1->Height =
  57. HUDSprite1->Material->Texture->Image->Height * 2;
  58. } else {
  59. HUDSprite1->Width = HUDSprite1->Material->Texture->Image->Width * 4;
  60. HUDSprite1->Height =
  61. HUDSprite1->Material->Texture->Image->Height * 4;
  62. }
  63. }
  64. FormResize(Sender);
  65. newSelection = true;
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TFormFormats::FormResize(TObject* Sender)
  69. {
  70. // re-center the HUDSprite
  71. HUDSprite1->Position->X = GLSceneViewer1->Width / 2;
  72. HUDSprite1->Position->Y = GLSceneViewer1->Height / 2;
  73. GLSceneViewer1->Invalidate();
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TFormFormats::GLSceneViewer1AfterRender(TObject* Sender)
  77. {
  78. int rgb;
  79. // update compression stats, only the 1st time after a new selection
  80. if (newSelection) {
  81. rgb = HUDSprite1->Material->Texture->Image->Width *
  82. HUDSprite1->Material->Texture->Image->Height * 4;
  83. LARGB32->Caption = Format(
  84. "RGBA 32bits would require %d kB", ARRAYOFCONST((rgb / 1024)));
  85. LAUsedMemory->Caption = Format("Required memory : %d kB",
  86. ARRAYOFCONST(
  87. (HUDSprite1->Material->Texture->TextureImageRequiredMemory() /
  88. 1024)));
  89. LACompression->Caption = Format("Compression ratio : %d %%",
  90. ARRAYOFCONST((100 - 100 *
  91. HUDSprite1->Material->Texture
  92. ->TextureImageRequiredMemory() /
  93. rgb)));
  94. newSelection = false;
  95. }
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TFormFormats::RBDefaultClick(TObject* Sender)
  99. {
  100. CBImageChange(Sender);
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TFormFormats::RBDoubleClick(TObject* Sender)
  104. {
  105. CBImageChange(Sender);
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TFormFormats::RBQuadClick(TObject* Sender)
  109. {
  110. CBImageChange(Sender);
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TFormFormats::CBCompressionChange(TObject* Sender)
  114. {
  115. CBImageChange(Sender);
  116. }
  117. //---------------------------------------------------------------------------
  118. void __fastcall TFormFormats::CBFormatChange(TObject* Sender)
  119. {
  120. CBImageChange(Sender);
  121. }
  122. //---------------------------------------------------------------------------