fBmpfont.pas 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. unit fBmpfont;
  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.ExtCtrls,
  12. GLS.Scene,
  13. GLS.VectorTypes,
  14. GLS.HUDObjects,
  15. GLS.Objects,
  16. GLS.Cadencer,
  17. GLS.BitmapFont,
  18. GLS.GeomObjects,
  19. GLS.Coordinates,
  20. GLS.BaseClasses,
  21. GLS.Utils,
  22. GLS.SceneViewer;
  23. type
  24. TFormBmpFont = class(TForm)
  25. GLScene1: TGLScene;
  26. GLSceneViewer1: TGLSceneViewer;
  27. BitmapFont1: TGLBitmapFont;
  28. GLLightSource1: TGLLightSource;
  29. GLCamera1: TGLCamera;
  30. HUDText1: TGLHUDText;
  31. GLCadencer1: TGLCadencer;
  32. Timer1: TTimer;
  33. HUDText2: TGLHUDText;
  34. HUDText3: TGLHUDText;
  35. Teapot1: TGLTeapot;
  36. HUDTextFPS: TGLHUDText;
  37. procedure GLCadencer1Progress(Sender: TObject;
  38. const deltaTime, newTime: Double);
  39. procedure Timer1Timer(Sender: TObject);
  40. procedure FormCreate(Sender: TObject);
  41. procedure GLSceneViewer1Click(Sender: TObject);
  42. private
  43. public
  44. end;
  45. var
  46. FormBmpFont: TFormBmpFont;
  47. implementation
  48. {$R *.DFM}
  49. procedure TFormBmpFont.FormCreate(Sender: TObject);
  50. begin
  51. // Load the font bitmap from media dir
  52. SetGLSceneMediaDir();
  53. BitmapFont1.Glyphs.LoadFromFile('darkgold_font.bmp');
  54. // sorry, couldn't resist...
  55. {$IFDEF WIN32}
  56. HUDText1.Text := 'Hello WIN 32!'#13#10#13#10 + 'This is me, '#13#10 +
  57. 'the HUD Text.'#13#10#13#10 + 'Bitmap Fonts!';
  58. {$ENDIF}
  59. {$IFDEF WIN64}
  60. HUDText1.Text := 'Hello WIN 64!'#13#10#13#10 + 'This is me, '#13#10 +
  61. 'the HUD Text.'#13#10#13#10 + 'Bitmap Fonts!';
  62. {$ENDIF}
  63. end;
  64. procedure TFormBmpFont.GLCadencer1Progress(Sender: TObject;
  65. const deltaTime, newTime: Double);
  66. begin
  67. // make things move a little
  68. HUDText2.Rotation := HUDText2.Rotation + 15 * deltaTime;
  69. HUDText3.Scale.X := 0.5 * sin(newTime) + 1;
  70. HUDText3.Scale.Y := 0.5 * cos(newTime) + 1;
  71. GLSceneViewer1.Invalidate;
  72. end;
  73. procedure TFormBmpFont.Timer1Timer(Sender: TObject);
  74. begin
  75. FormatSettings.DecimalSeparator := ',';
  76. HUDTextFPS.Text := FloatToStr(-2.01);
  77. HUDTextFPS.Text := Format('%.1f FPS', [GLSceneViewer1.FramesPerSecond]);
  78. GLSceneViewer1.ResetPerformanceMonitor;
  79. end;
  80. procedure TFormBmpFont.GLSceneViewer1Click(Sender: TObject);
  81. begin
  82. Teapot1.Visible := not Teapot1.Visible;
  83. end;
  84. end.