2
0

fProcCloudsC.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fProcCloudsC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "Vcl.Dialogs"
  8. #pragma link "GLS.Texture"
  9. #pragma link "GLS.ProcTextures"
  10. #pragma link "GLS.BaseClasses"
  11. #pragma link "GLS.Cadencer"
  12. #pragma link "GLS.Coordinates"
  13. #pragma link "GLS.Objects"
  14. #pragma link "GLS.Scene"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma resource "*.dfm"
  17. TFormCloudsC *FormCloudsC;
  18. TextFile outfile;
  19. //---------------------------------------------------------------------------
  20. __fastcall TFormCloudsC::TFormCloudsC(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TFormCloudsC::FormCreate(TObject *Sender)
  26. {
  27. CBFormat->ItemIndex = 3;
  28. CBCompression->ItemIndex = 0;
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TFormCloudsC::CBFormatChange(TObject *Sender)
  32. {
  33. byte aPERM[255];
  34. String s;
  35. int i;
  36. // adjust settings from selection and reload the texture map
  37. if (UseCloudFileCB->Checked and (FileExists(CloudFileUsedEdit->Text)))
  38. {
  39. /*
  40. try {
  41. AssignFile(outfile, CloudFileUsedEdit->Text);
  42. Reset(outfile);
  43. Readln(outfile, s);
  44. for (i = 0; 255; i++)
  45. {
  46. Readln(outfile, s);
  47. aPERM[i] = StrToInt(s);
  48. }
  49. }
  50. __finally
  51. {
  52. CloseFile(outfile);
  53. }
  54. }
  55. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->SetPermFromData(aPERM);
  56. */
  57. }
  58. else
  59. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->SetPermToDefault();
  60. Plane->Material->Texture->TextureFormat = TGLTextureFormat(Integer(tfRGB) + CBFormat->ItemIndex);
  61. Plane->Material->Texture->Compression = TGLTextureCompression(Integer(tcNone) +
  62. CBCompression->ItemIndex);
  63. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->MinCut = SpinEdit1->Value;
  64. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->NoiseSharpness = SpinEdit2->Value / 100;
  65. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->Height = StrToInt(CloudImageSizeUsedEdit->Text);
  66. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->Width = StrToInt(CloudImageSizeUsedEdit->Text);
  67. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->NoiseRandSeed =
  68. StrToInt(CloudRandomSeedUsedEdit->Text);
  69. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->Seamless = CheckBox2->Checked;
  70. if (RBDefault->Checked)
  71. {
  72. Plane->Width = 50;
  73. Plane->Height = 50;
  74. }
  75. else if (RBDouble->Checked)
  76. {
  77. Plane->Width = 100;
  78. Plane->Height = 100;
  79. }
  80. else
  81. {
  82. Plane->Width = 400;
  83. Plane->Height = 400;
  84. };
  85. newSelection = true;
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TFormCloudsC::GLCadencer1TotalProgress(TObject *Sender, const double DeltaTime,
  89. const double NewTime)
  90. {
  91. if (CheckBox1->Checked)
  92. ((TGLProcTextureNoise*)(Plane->Material->Texture->Image))->
  93. NoiseAnimate(DeltaTime);
  94. }
  95. //---------------------------------------------------------------------------
  96. void __fastcall TFormCloudsC::TrackBar1Change(TObject *Sender)
  97. {
  98. Plane->XTiles = TrackBar1->Position;
  99. Plane->YTiles = TrackBar1->Position;
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TFormCloudsC::Timer1Timer(TObject *Sender)
  103. {
  104. LabelFPS->Caption = GLSceneViewer1->FramesPerSecondText();
  105. GLSceneViewer1->ResetPerformanceMonitor();
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TFormCloudsC::GLSceneViewer1AfterRender(TObject *Sender)
  109. {
  110. int rgb;
  111. // update compression stats, only the 1st time after a new selection
  112. if (newSelection)
  113. rgb = Plane->Material->Texture->Image->Width *
  114. Plane->Material->Texture->Image->Height * 4;
  115. LARGB32->Caption = Format("RGBA 32bits would require %d kB",
  116. (rgb / 1024));
  117. LAUsedMemory->Caption = Format("Required memory : %d kB",
  118. ARRAYOFCONST((Plane->Material->Texture->TextureImageRequiredMemory() / 1024)));
  119. LACompression->Caption = Format("Compression ratio : %d %%",
  120. (100 - 100 * Plane->Material->Texture->TextureImageRequiredMemory() / rgb));
  121. newSelection = false;
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TFormCloudsC::CloudFileOpenBtnClick(TObject *Sender)
  125. {
  126. OpenDialog1->Filter = "Cloud base (*.clb)|*.clb";
  127. OpenDialog1->InitialDir = ExtractFilePath(ParamStr(0));
  128. OpenDialog1->FileName = "*.clb";
  129. if (OpenDialog1->Execute())
  130. CloudFileUsedEdit->Text = OpenDialog1->FileName;
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TFormCloudsC::MakeAndSaveCloudNoiseFileClick(TObject *Sender)
  134. {
  135. int i;
  136. /*
  137. void RandomPerm();
  138. int Id, Count, More, Less, Again;
  139. {
  140. MakeAndSaveCloudNoiseFile->Caption = IntToStr(0);
  141. Application->ProcessMessages();
  142. for (Id = 0; 255; Id++)
  143. {
  144. aPERM[Id] = Random(256);
  145. // Label61->Caption = IntToStr(Id);
  146. // Application->ProcessMessages();
  147. }
  148. Count = 0;
  149. do
  150. Again = 0;
  151. Less = Random(256);
  152. for (Id = 0; Count; Id++)
  153. {
  154. More = aPERM[Id];
  155. if (Less == More)
  156. Again++;
  157. }
  158. Label61->Caption = IntToStr(Again);
  159. // these can be removed.. just for debugging
  160. Application->ProcessMessages();
  161. if (Again == 0)
  162. {
  163. aPERM[Count + 1] = Less;
  164. Count++;
  165. MakeAndSaveCloudNoiseFile->Caption = IntToStr(Less) + "," +
  166. IntToStr(Count);
  167. Application->ProcessMessages();
  168. }
  169. while (Count != 255);
  170. }
  171. {
  172. SaveDialog1->Filter = "Cloud base (*.clb)|*.clb";
  173. SaveDialog1->InitialDir = ExtractFilePath(ParamStr(0));
  174. SaveDialog1->DefaultExt = "rnd";
  175. SaveDialog1->Filename = ".clb";
  176. if (SaveDialog1->Execute())
  177. {
  178. if (UpperCase(ExtractFileExt(SaveDialog1->Filename) == ".CLB")
  179. {
  180. Application->ProcessMessages();
  181. Randomize();
  182. RandomPerm();
  183. try
  184. AssignFile(outfile, SaveDialog1->Filename);
  185. // File selected in dialog box
  186. Rewrite(outfile);
  187. Writeln(outfile, "Cloud Base V2.0");
  188. for (i = 0; 255; i++)
  189. Writeln(outfile, IntToStr(aPERM[i]));
  190. finally
  191. CloseFile(outfile);
  192. }
  193. Label61->Caption = "Done";
  194. MakeAndSaveCloudNoiseFile->Caption = "";
  195. }
  196. }
  197. */
  198. }
  199. //---------------------------------------------------------------------------