Unit1.cpp 4.1 KB

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