fGLInfosD.pas 8.2 KB

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