fFullscreen.pas 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. unit fFullscreen;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. Vcl.Graphics,
  8. Vcl.Forms,
  9. Vcl.Controls,
  10. GLS.Scene,
  11. GLS.Objects,
  12. GLS.GeomObjects,
  13. GLS.Canvas,
  14. GLS.Coordinates,
  15. GLS.BaseClasses,
  16. GLS.FullScreenViewer;
  17. type
  18. TDataModuleFS = class(TDataModule)
  19. GLScene1: TGLScene;
  20. GLCamera1: TGLCamera;
  21. GLLightSource1: TGLLightSource;
  22. Teapot1: TGLTeapot;
  23. GLFullScreenViewer1: TGLFullScreenViewer;
  24. DCBlueLight: TGLDummyCube;
  25. GLLightSource2: TGLLightSource;
  26. procedure DataModuleCreate(Sender: TObject);
  27. procedure GLFullScreenViewer1KeyPress(Sender: TObject; var Key: Char);
  28. procedure GLFullScreenViewer1PostRender(Sender: TObject);
  29. private
  30. public
  31. firstPassDone : Boolean;
  32. end;
  33. var
  34. DataModuleFS: TDataModuleFS;
  35. implementation
  36. {$R *.dfm}
  37. procedure TDataModuleFS.DataModuleCreate(Sender: TObject);
  38. begin
  39. // Adjusts Zoom to size (might have been modified in the IDE, by you, user!)
  40. GLCamera1.SceneScale:=GLFullScreenViewer1.Width/160;
  41. // Start fullscreen mode, no cursor
  42. GLFullScreenViewer1.Cursor:=crNone;
  43. GLFullScreenViewer1.Active:=True;
  44. while GLFullScreenViewer1.Active do begin
  45. // Message queue is not operational, but there may still be some messages
  46. Application.ProcessMessages;
  47. // Relinquish some of that CPU time
  48. Sleep(1);
  49. // Slowly rotate the teapot and the blue light
  50. Teapot1.TurnAngle:=4*Frac(Now*24)*3600;
  51. DCBlueLight.RollAngle:=32*Frac(Now*24)*3600;
  52. end;
  53. end;
  54. procedure TDataModuleFS.GLFullScreenViewer1PostRender(Sender: TObject);
  55. var
  56. glc : TGLCanvas;
  57. x, y : Integer;
  58. begin
  59. glc:=TGLCanvas.Create(GLFullScreenViewer1.Width, GLFullScreenViewer1.Height);
  60. with glc do begin
  61. x:=Mouse.CursorPos.X;
  62. y:=Mouse.CursorPos.Y;
  63. PenColor:=clYellow;
  64. // Alpha-transparency antialiasing:
  65. // we render the ellipse twice, the first pass with a very transparent
  66. // wide pen, and a second time with a thinner pen.
  67. PenAlpha:=0.4;
  68. PenWidth:=3;
  69. Ellipse(x, y, 16, 16);
  70. PenAlpha:=0.75;
  71. PenWidth:=2;
  72. Ellipse(x, y, 16, 16);
  73. // Complete the reticle
  74. PenAlpha:=0.3;
  75. PenWidth:=2;
  76. Line(x-32, y, x+32, y);
  77. Line(x, y-32, x, y+32);
  78. end;
  79. glc.Free;
  80. end;
  81. procedure TDataModuleFS.GLFullScreenViewer1KeyPress(Sender: TObject;
  82. var Key: Char);
  83. begin
  84. // ESC leaves fullscreen mode
  85. if Key=#27 then begin
  86. GLFullScreenViewer1.Active:=False;
  87. Key:=#0;
  88. end;
  89. end;
  90. end.