2
0

Unit1.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Material"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLSL.ProjectedTextures"
  15. #pragma link "GLS.VectorFileObjects"
  16. #pragma link "GLS.SceneViewer"
  17. #pragma link "GLFileLMTS"
  18. #pragma link "GLS.FileTGA"
  19. #pragma resource "*.dfm"
  20. TForm1 *Form1;
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm1::TForm1(TComponent* Owner)
  23. : TForm(Owner)
  24. {
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  28. const double newTime)
  29. {
  30. int I;
  31. for (I = 1; I < GLSLProjectedTextures1->Emitters->Count - 1; I++)
  32. GLSLProjectedTextures1->Emitters->Items[I]->Emitter->Turn(deltaTime * (I + 1) * 10);
  33. GLSceneViewer1->Invalidate();
  34. GLArrowLine1->Position->Y = GLArrowLine1->Position->Y + sdir * deltaTime;
  35. if (GLArrowLine1->Position->Y > 20)
  36. {
  37. GLArrowLine1->Position->Y = 20;
  38. sdir = -10;
  39. }
  40. if (GLArrowLine1->Position->Y < 10)
  41. {
  42. GLArrowLine1->Position->Y = 10;
  43. sdir = 10;
  44. }
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::GLCamera1CustomPerspective(const TRectangle &viewport, int width,
  48. int height, int DPI, float &viewPortRadius)
  49. {
  50. * CurrentGLContext()->PipelineTransformation->ProjectionMatrix =
  51. CreatePerspectiveMatrix((float)GLCamera1->GetFieldOfView(Width)/2, (float)Width / Height,
  52. GLCamera1->NearPlaneBias, GLCamera1->DepthOfView);
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  56. int X, int Y)
  57. {
  58. if (Shift.Contains(ssLeft))
  59. {
  60. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  61. mx = X;
  62. my = Y;
  63. }
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  67. TPoint &MousePos, bool &Handled)
  68. {
  69. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  73. TShiftState Shift, int X, int Y)
  74. {
  75. mx = X;
  76. my = Y;
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  80. {
  81. Caption = "GLSL Projected Texture " +GLSceneViewer1->FramesPerSecondText();
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::FormCreate(TObject *Sender)
  85. {
  86. int I;
  87. Randomize;
  88. sdir = -10;
  89. GLCamera1->CameraStyle = csCustom;
  90. SetGLSceneMediaDir();
  91. GLSLProjectedTextures1->Material->Texture->Image->LoadFromFile("flare1.bmp");
  92. GLSLProjectedTextures1->Material->Texture->Disabled = false;
  93. GLSLProjectedTextures1->Material->Texture->TextureWrap = twNone;
  94. GLSLProjectedTextures1->Material->Texture->MinFilter = miLinear;
  95. GLSLProjectedTextures1->Material->Texture->MagFilter = maLinear;
  96. GLSLProjectedTextures1->UseLightmaps = true;
  97. GLCube1->Material->Texture->Image->LoadFromFile("ashwood.jpg");
  98. GLCube1->Material->Texture->Disabled = false;
  99. GLFreeForm1->LoadFromFile("groundtest.lmts");
  100. GLFreeForm1->ObjectStyle = GLFreeForm1->ObjectStyle << osDirectDraw;
  101. for (I = 0; I < GLMaterialLibrary1->Materials->Count - 1; I++)
  102. GLMaterialLibrary1->Materials->Items[I]->Material->MaterialOptions =
  103. GLMaterialLibrary1->Materials->Items[I]->Material->MaterialOptions << moNoLighting;
  104. }
  105. //---------------------------------------------------------------------------