fGLInfosD.pas 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. unit fGLInfosD;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. Winapi.OpenGLext,
  6. Winapi.Windows,
  7. Winapi.Messages,
  8. System.SysUtils,
  9. System.Variants,
  10. System.Classes,
  11. Vcl.Graphics,
  12. Vcl.Controls,
  13. Vcl.Forms,
  14. Vcl.Dialogs,
  15. Vcl.ExtCtrls,
  16. Stage.TextureFormat,
  17. Stage.VectorGeometry,
  18. Stage.Keyboard,
  19. Stage.VectorTypes,
  20. Stage.Utils,
  21. GLS.BaseClasses,
  22. GLS.Scene,
  23. GLS.SceneViewer,
  24. GLS.OpenGLAdapter,
  25. GLS.Context,
  26. GLS.Material,
  27. GLS.Cadencer,
  28. GLS.BitmapFont,
  29. GLS.WindowsFont,
  30. GLS.HUDObjects,
  31. GLS.Coordinates,
  32. GLS.Objects,
  33. GLS.RenderContextInfo,
  34. GLSL.PostShaders,
  35. GLSL.CustomShader,
  36. GLSL.Shader,
  37. GLS.XCollection,
  38. GLS.SoundManager,
  39. GLS.Sounds.BASS,
  40. GLS.FileWAV,
  41. GLS.FileMP3,
  42. GLS.Sounds.FMOD,
  43. GLS.Canvas,
  44. GLS.SpaceText,
  45. GLSL.AsmShader,
  46. GLSL.PhongShader;
  47. type
  48. TMainForm = class(TForm)
  49. SoundLibrary: TGLSoundLibrary;
  50. FMODPlayer: TGLSMFMOD;
  51. Viewer: TGLSceneViewer;
  52. Scene: TGLScene;
  53. Cadencer: TGLCadencer;
  54. MaterialLibrary: TGLMaterialLibrary;
  55. DCCameras: TGLDummyCube;
  56. Camera1: TGLCamera;
  57. DriverInfo: TGLDummyCube;
  58. HUDText_Vendor: TGLResolutionIndependantHUDText;
  59. WindowsBitmapFont: TGLWindowsBitmapFont;
  60. HUDText_Renderer: TGLResolutionIndependantHUDText;
  61. HUDText_Version: TGLResolutionIndependantHUDText;
  62. HUDText_ExtVersion: TGLResolutionIndependantHUDText;
  63. HUDText_GLSLVersion: TGLResolutionIndependantHUDText;
  64. HUDText_NBExt: TGLResolutionIndependantHUDText;
  65. Background: TGLDummyCube;
  66. GLSLShader1: TGLSLShader;
  67. Timer1: TTimer;
  68. HUDText_Counter: TGLResolutionIndependantHUDText;
  69. ForeGround: TGLDummyCube;
  70. HUDLogo: TGLHUDSprite;
  71. HUDExtensions: TGLDirectOpenGL;
  72. Extra: TGLDummyCube;
  73. HUDHelp: TGLResolutionIndependantHUDText;
  74. GLSpaceText1: TGLSpaceText;
  75. GLPhongShader1: TGLPhongShader;
  76. GLLightSource1: TGLLightSource;
  77. WindowsBitmapFont2: TGLWindowsBitmapFont;
  78. GLPlane1: TGLPlane;
  79. SphereSound: TGLSphere;
  80. procedure FormShow(Sender: TObject);
  81. procedure GLSLShader1Apply(Shader: TGLCustomGLSLShader);
  82. procedure CadencerProgress(Sender: TObject; const deltaTime, newTime: Double);
  83. procedure Timer1Timer(Sender: TObject);
  84. procedure FormResize(Sender: TObject);
  85. procedure HUDExtensionsRender(Sender: TObject; var rci: TGLRenderContextInfo);
  86. procedure GLSpaceText1Progress(Sender: TObject; const deltaTime, newTime: Double);
  87. procedure FormCreate(Sender: TObject);
  88. private
  89. procedure HandleKeys(const deltaTime: Double);
  90. public
  91. Path: TFileName;
  92. VendorName: String;
  93. RendererName: String;
  94. RendererVersion: String;
  95. ExtensionVersion: String;
  96. GLSLVersion: String;
  97. NBExtensions: String;
  98. ExtensionsList: TStrings;
  99. StartLine, MaxLines: Integer;
  100. end;
  101. var
  102. MainForm: TMainForm;
  103. implementation
  104. {$R *.dfm}
  105. //====================================================
  106. procedure TMainForm.FormCreate(Sender: TObject);
  107. begin
  108. // Path := ExtractFilePath(ParamStr(0)) + '\audio';
  109. Path := GetCurrentAssetPath() + '\audio';
  110. SetCurrentDir(Path);
  111. SoundLibrary.Samples.AddFile('intro.mp3', 'Music');
  112. if FMODPlayer <> ActiveSoundManager then
  113. begin
  114. // shut down current one, and activate the new one
  115. if ActiveSoundManager <> nil then
  116. ActiveSoundManager.Active := False;
  117. if FMODPlayer <> nil then
  118. FMODPlayer.Active := True;
  119. // restart sound
  120. GetOrCreateSoundEmitter(SphereSound).Playing := True;
  121. end;
  122. end;
  123. //-------------------------------------------------
  124. procedure TMainForm.FormShow(Sender: TObject);
  125. Var
  126. ExtStr: String;
  127. i: Integer;
  128. dc: HDC;
  129. begin
  130. HUDLogo.Position.X := Viewer.Width - 150;
  131. HUDLogo.Position.Y := Viewer.Height - 100;
  132. Viewer.Buffer.RenderingContext.Activate;
  133. try
  134. with Viewer.Buffer do
  135. begin
  136. VendorName := String(GL.GetString(GL_VENDOR));
  137. RendererName := String(GL.GetString(GL_RENDERER));
  138. RendererVersion := String(GL.GetString(GL_VERSION));
  139. ExtensionVersion := String(GL.GetString(GL_SHADING_LANGUAGE_VERSION_ARB));
  140. GLSLVersion := '#' + IntToStr(GL_VERSION);
  141. ExtensionsList := TStringList.Create;
  142. ExtStr := String(GL.GetString(GL_EXTENSIONS));
  143. ExtensionsList.Clear;
  144. while Length(ExtStr) > 0 do
  145. begin
  146. i := Pos(' ', ExtStr);
  147. if i = 0 then
  148. i := 255;
  149. ExtensionsList.Add(Copy(ExtStr, 1, i - 1));
  150. Delete(ExtStr, 1, i);
  151. end;
  152. // Include WGL extensions
  153. if GL.W_ARB_extensions_string then
  154. begin
  155. dc := wglGetCurrentDC();
  156. ExtStr := String(GL.WGetExtensionsStringARB(dc));
  157. while Length(ExtStr) > 0 do
  158. begin
  159. i := Pos(' ', ExtStr);
  160. if i = 0 then
  161. i := 255;
  162. ExtensionsList.Add(Copy(ExtStr, 1, i - 1));
  163. Delete(ExtStr, 1, i);
  164. end;
  165. end;
  166. NBExtensions := IntToStr(ExtensionsList.Count);
  167. end;
  168. finally
  169. HUDText_Vendor.Text := 'Vendor : ' + VendorName;
  170. HUDText_Renderer.Text := 'Renderer : ' + RendererName;
  171. HUDText_Version.Text := 'Renderer Version : ' + RendererVersion;
  172. HUDText_ExtVersion.Text := 'OPENGL Version : ' + ExtensionVersion;
  173. HUDText_GLSLVersion.Text := 'GLSL Version : ' + GLSLVersion;
  174. HUDText_NBExt.Text := 'Extensions supported : ' + NBExtensions;
  175. end;
  176. MaxLines := round(((Viewer.Height - 30) - (Viewer.Height / 3)) / 12);
  177. StartLine := 0;
  178. Viewer.Invalidate;
  179. end;
  180. //---------------------------------------------------------
  181. procedure TMainForm.FormResize(Sender: TObject);
  182. begin
  183. HUDLogo.Position.X := Viewer.Width - 150;
  184. HUDLogo.Position.Y := Viewer.Height - 100;
  185. MaxLines := round(((Viewer.Height - 30) - (Viewer.Height / 3)) / 12);
  186. end;
  187. //-------------------------------------------------------
  188. procedure TMainForm.HandleKeys(const deltaTime: Double);
  189. begin
  190. if IsKeyDown(VK_UP) then
  191. begin
  192. if StartLine > 0 then
  193. StartLine := StartLine - 1;
  194. end
  195. else if IsKeyDown(VK_DOWN) then
  196. begin
  197. if StartLine < (ExtensionsList.Count - 1 - MaxLines) then
  198. StartLine := StartLine + 1;
  199. end;
  200. if IsKeyDown(VK_SPACE) then
  201. begin
  202. if FMODPlayer.Sources.Items[0].Pause then
  203. FMODPlayer.Sources.Items[0].Pause := False
  204. else
  205. FMODPlayer.Sources.Items[0].Pause := True;
  206. end;
  207. if IsKeyDown(VK_ESCAPE) then
  208. begin
  209. Application.Terminate;
  210. end
  211. end;
  212. procedure TMainForm.CadencerProgress(Sender: TObject; const deltaTime, newTime: Double);
  213. begin
  214. HandleKeys(deltaTime);
  215. Viewer.Invalidate;
  216. end;
  217. procedure TMainForm.GLSLShader1Apply(Shader: TGLCustomGLSLShader);
  218. begin
  219. with Shader do
  220. begin
  221. param['resolution'].AsVector2f := Vector2fMake(Viewer.Width, Viewer.Height);
  222. param['time'].AsVector1f := Cadencer.CurrentTime;
  223. end;
  224. end;
  225. procedure TMainForm.GLSpaceText1Progress(Sender: TObject; const deltaTime, newTime: Double);
  226. begin
  227. GLSpaceText1.TurnAngle := 15 * newTime;
  228. end;
  229. procedure TMainForm.HUDExtensionsRender(Sender: TObject; var rci: TGLRenderContextInfo);
  230. var
  231. i, X, ys, Y: Integer;
  232. Canvas: TGLCanvas;
  233. r: TRect;
  234. Color: TColor;
  235. ext: string;
  236. begin
  237. ys := round(Viewer.Height / 3) - 20;
  238. Canvas := TGLCanvas.Create(Viewer.Width, Viewer.Height);
  239. with Canvas do
  240. begin
  241. PenWidth := 2;
  242. PenColor := $00333333;
  243. PenAlpha := 0.7;
  244. r := Rect(10, ys, Viewer.Width - 10, Viewer.Height - 30);
  245. FillRect(r.Left, r.Top, r.Right, r.Bottom);
  246. for i := 0 to MaxLines do
  247. begin
  248. Color := clWhite;
  249. X := 15;
  250. Y := ys + (12 * i);
  251. ext := ExtensionsList.Strings[StartLine + i];
  252. if Pos('EXT', ext) > 0 then
  253. Color := clSkyBlue;
  254. if Pos('ARB', ext) > 0 then
  255. Color := clYellow;
  256. if Pos('NV', ext) > 0 then
  257. Color := clMoneyGreen;
  258. if Pos('WGL', ext) > 0 then
  259. Color := clAqua;
  260. WindowsBitmapFont2.Font.Size := 8;
  261. WindowsBitmapFont2.TextOut(rci, X, Y, ext, Color);
  262. end;
  263. end;
  264. Canvas.Free;
  265. end;
  266. procedure TMainForm.Timer1Timer(Sender: TObject);
  267. var
  268. ManagerName: String;
  269. begin
  270. // some stats
  271. ManagerName := 'FMOD';
  272. if ActiveSoundManager <> nil then
  273. HUDText_Counter.Text := Format('%.2f FPS, %s CPU use : %.2f%%',
  274. [Viewer.FramesPerSecond, ManagerName, ActiveSoundManager.CPUUsagePercent])
  275. else
  276. HUDText_Counter.Text := Format('%.2f FPS', [Viewer.FramesPerSecond]);
  277. Viewer.ResetPerformanceMonitor;
  278. end;
  279. end.