fProcCloudsD.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. unit fProcCloudsD;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. Vcl.Graphics,
  8. Vcl.Controls,
  9. Vcl.Forms,
  10. Vcl.Dialogs,
  11. Vcl.StdCtrls,
  12. Vcl.ExtCtrls,
  13. Vcl.Samples.Spin,
  14. Vcl.ComCtrls,
  15. Vcl.Buttons,
  16. Vcl.Imaging.Jpeg,
  17. GLS.Scene,
  18. GLS.Objects,
  19. GLS.Texture,
  20. GLS.HUDObjects,
  21. GLS.Cadencer,
  22. GLS.SceneViewer,
  23. GLS.ProcTextures,
  24. Scenario.TextureFormat,
  25. GLS.Coordinates,
  26. GLS.BaseClasses;
  27. type
  28. TFormClouds = class(TForm)
  29. GLSceneViewer1: TGLSceneViewer;
  30. GLScene1: TGLScene;
  31. Camera: TGLCamera;
  32. Panel1: TPanel;
  33. CBFormat: TComboBox;
  34. Label2: TLabel;
  35. Label3: TLabel;
  36. CBCompression: TComboBox;
  37. Label5: TLabel;
  38. RBDefault: TRadioButton;
  39. RBDouble: TRadioButton;
  40. LAUsedMemory: TLabel;
  41. RBQuad: TRadioButton;
  42. LARGB32: TLabel;
  43. LACompression: TLabel;
  44. GLCadencer1: TGLCadencer;
  45. CheckBox1: TCheckBox;
  46. Label4: TLabel;
  47. SpinEdit1: TSpinEdit;
  48. SpinEdit2: TSpinEdit;
  49. Label6: TLabel;
  50. CheckBox2: TCheckBox;
  51. Plane: TGLPlane;
  52. TrackBar1: TTrackBar;
  53. Timer1: TTimer;
  54. CloudRandomSeedUsedEdit: TEdit;
  55. CloudImageSizeUsedEdit: TEdit;
  56. UseCloudFileCB: TCheckBox;
  57. CloudFileOpenBtn: TSpeedButton;
  58. CloudFileUsedEdit: TEdit;
  59. MakeAndSaveCloudNoiseFile: TSpeedButton;
  60. Label61: TLabel;
  61. OpenDialog1: TOpenDialog;
  62. SaveDialog1: TSaveDialog;
  63. LabelFPS: TLabel;
  64. procedure GLSceneViewer1AfterRender(Sender: TObject);
  65. procedure CBFormatChange(Sender: TObject);
  66. procedure GLCadencer1Progress(Sender: TObject;
  67. const deltaTime, newTime: Double);
  68. procedure TrackBar1Change(Sender: TObject);
  69. procedure Timer1Timer(Sender: TObject);
  70. procedure FormCreate(Sender: TObject);
  71. procedure CloudFileOpenBtnClick(Sender: TObject);
  72. procedure MakeAndSaveCloudNoiseFileClick(Sender: TObject);
  73. private
  74. public
  75. newSelection: Boolean;
  76. end;
  77. var
  78. FormClouds: TFormClouds;
  79. aPERM: array [0 .. 255] of Byte;
  80. outfile: TextFile;
  81. implementation
  82. {$R *.DFM}
  83. procedure TFormClouds.FormCreate(Sender: TObject);
  84. begin
  85. CBFormat.ItemIndex := 3;
  86. CBCompression.ItemIndex := 0;
  87. CBFormatChange(Sender);
  88. end;
  89. procedure TFormClouds.GLCadencer1Progress(Sender: TObject;
  90. const deltaTime, newTime: Double);
  91. begin
  92. if CheckBox1.Checked then
  93. TGLProcTextureNoise(Plane.Material.Texture.Image)
  94. .NoiseAnimate(deltaTime);
  95. end;
  96. procedure TFormClouds.TrackBar1Change(Sender: TObject);
  97. begin
  98. Plane.XTiles := TrackBar1.Position;
  99. Plane.YTiles := TrackBar1.Position;
  100. // EnvColor clrLightBlue TextureMode Blend
  101. end;
  102. procedure TFormClouds.Timer1Timer(Sender: TObject);
  103. begin
  104. LabelFPS.Caption := GLSceneViewer1.FramesPerSecondText();
  105. GLSceneViewer1.ResetPerformanceMonitor();
  106. end;
  107. procedure TFormClouds.GLSceneViewer1AfterRender(Sender: TObject);
  108. var
  109. rgb: Integer;
  110. begin
  111. // update compression stats, only the 1st time after a new selection
  112. if newSelection then
  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 div 1024]);
  117. LAUsedMemory.Caption := Format('Required memory : %d kB',
  118. [Plane.Material.Texture.TextureImageRequiredMemory() div 1024]);
  119. LACompression.Caption := Format('Compression ratio : %d %%',
  120. [100 - 100 * Plane.Material.Texture.TextureImageRequiredMemory() div rgb]);
  121. newSelection := False;
  122. end;
  123. //----------------------------------------------------------------------
  124. procedure TFormClouds.CBFormatChange(Sender: TObject);
  125. var
  126. s: String;
  127. i: Integer;
  128. begin
  129. // adjust settings from selection and reload the texture map
  130. if (UseCloudFileCB.Checked and (FileExists(CloudFileUsedEdit.Text))) then
  131. begin
  132. try
  133. AssignFile(outfile, CloudFileUsedEdit.Text);
  134. // File selected in dialog box
  135. Reset(outfile);
  136. Readln(outfile, s);
  137. for i := 0 to 255 do
  138. begin
  139. Readln(outfile, s);
  140. aPERM[i] := strtoint(s);
  141. end;
  142. finally
  143. CloseFile(outfile);
  144. end;
  145. TGLProcTextureNoise(Plane.Material.Texture.Image).SetPermFromData(aPERM);
  146. end
  147. else
  148. TGLProcTextureNoise(Plane.Material.Texture.Image).SetPermToDefault;
  149. Plane.Material.Texture.TextureFormat := TGLTextureFormat(Integer(tfRGB) + CBFormat.ItemIndex);
  150. Plane.Material.Texture.Compression := TGLTextureCompression(Integer(tcNone) +
  151. CBCompression.ItemIndex);
  152. TGLProcTextureNoise(Plane.Material.Texture.Image).MinCut := SpinEdit1.Value;
  153. TGLProcTextureNoise(Plane.Material.Texture.Image).NoiseSharpness := SpinEdit2.Value / 100;
  154. TGLProcTextureNoise(Plane.Material.Texture.Image).Height := strtoint(CloudImageSizeUsedEdit.Text);
  155. TGLProcTextureNoise(Plane.Material.Texture.Image).Width := strtoint(CloudImageSizeUsedEdit.Text);
  156. TGLProcTextureNoise(Plane.Material.Texture.Image).NoiseRandSeed :=
  157. strtoint(CloudRandomSeedUsedEdit.Text);;
  158. TGLProcTextureNoise(Plane.Material.Texture.Image).Seamless := CheckBox2.Checked;
  159. if RBDefault.Checked then
  160. begin
  161. Plane.Width := 50;
  162. Plane.Height := 50;
  163. end
  164. else if RBDouble.Checked then
  165. begin
  166. Plane.Width := 100;
  167. Plane.Height := 100;
  168. end
  169. else
  170. begin
  171. Plane.Width := 400;
  172. Plane.Height := 400;
  173. end;
  174. newSelection := True;
  175. end;
  176. procedure TFormClouds.CloudFileOpenBtnClick(Sender: TObject);
  177. begin
  178. OpenDialog1.Filter := 'Cloud base (*.clb)|*.clb';
  179. OpenDialog1.InitialDir := ExtractFilePath(ParamStr(0));
  180. OpenDialog1.FileName := '*.clb';
  181. if OpenDialog1.Execute() then
  182. CloudFileUsedEdit.Text := OpenDialog1.FileName;
  183. end;
  184. procedure TFormClouds.MakeAndSaveCloudNoiseFileClick(Sender: TObject);
  185. var
  186. i: Integer;
  187. (*sub*)procedure RandomPerm;
  188. var
  189. Id, Count, More, Less, Again: Integer;
  190. begin
  191. MakeAndSaveCloudNoiseFile.Caption := IntToStr(0);
  192. Application.ProcessMessages;
  193. for Id := 0 to 255 do
  194. begin
  195. aPERM[Id] := Random(256);
  196. // Label61.Caption:= IntToStr(Id);
  197. // Application.ProcessMessages;
  198. end;
  199. Count := 0;
  200. repeat
  201. again := 0;
  202. Less := Random(256);
  203. for Id := 0 to Count do
  204. begin
  205. More := aPERM[Id];
  206. If (Less = More) then
  207. Inc(Again);
  208. end;
  209. Label61.Caption := IntToStr(again);
  210. // these can be removed.. just for debugging
  211. Application.ProcessMessages;
  212. if (again = 0) then
  213. begin
  214. aPERM[Count + 1] := Less;
  215. Inc(Count);
  216. MakeAndSaveCloudNoiseFile.Caption := IntToStr(Less) + ',' +
  217. IntToStr(Count);
  218. Application.ProcessMessages;
  219. end;
  220. until Count = 255
  221. end;
  222. begin
  223. SaveDialog1.Filter := 'Cloud base (*.clb)|*.clb';
  224. SaveDialog1.InitialDir := ExtractFilePath(ParamStr(0));
  225. SaveDialog1.DefaultExt := 'rnd';
  226. SaveDialog1.Filename := '*.clb';
  227. if (SaveDialog1.Execute()) then
  228. begin
  229. if UpperCase(ExtractFileExt(SaveDialog1.Filename)) = '.CLB' then
  230. begin
  231. Application.ProcessMessages;
  232. Randomize();
  233. RandomPerm();
  234. try
  235. AssignFile(outfile, SaveDialog1.Filename);
  236. // File selected in dialog box
  237. Rewrite(outfile);
  238. Writeln(outfile, 'Cloud Base V1.0');
  239. for i := 0 to 255 do
  240. Writeln(outfile, IntToStr(aPERM[i]));
  241. finally
  242. CloseFile(outfile);
  243. end;
  244. Label61.Caption := 'Done';
  245. MakeAndSaveCloudNoiseFile.Caption := '';
  246. end;
  247. end;
  248. end;
  249. end.