fProjectTextureC.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fProjectTextureC.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 "GLS.FileLMTS"
  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::FormCreate(TObject *Sender)
  28. {
  29. int I;
  30. Randomize;
  31. sdir = -10;
  32. GLCamera1->CameraStyle = csCustom;
  33. TFileName Path = GetCurrentAssetPath();
  34. SetCurrentDir(Path + "\\texture");
  35. GLSLProjectedTextures1->Material->Texture->Image->LoadFromFile("flare1.bmp");
  36. GLSLProjectedTextures1->Material->Texture->Disabled = false;
  37. GLSLProjectedTextures1->Material->Texture->TextureWrap = twNone;
  38. GLSLProjectedTextures1->Material->Texture->MinFilter = miLinear;
  39. GLSLProjectedTextures1->Material->Texture->MagFilter = maLinear;
  40. GLSLProjectedTextures1->UseLightmaps = true;
  41. GLCube1->Material->Texture->Image->LoadFromFile("ashwood.jpg");
  42. GLCube1->Material->Texture->Disabled = false;
  43. GLFreeForm1->LoadFromFile("groundtest.lmts"); // persistent image
  44. GLFreeForm1->ObjectStyle = GLFreeForm1->ObjectStyle << osDirectDraw;
  45. for (I = 0; I < GLMaterialLibrary1->Materials->Count - 1; I++)
  46. GLMaterialLibrary1->Materials->Items[I]->Material->MaterialOptions =
  47. GLMaterialLibrary1->Materials->Items[I]->Material->MaterialOptions << moNoLighting;
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  51. const double newTime)
  52. {
  53. int I;
  54. for (I = 1; I < GLSLProjectedTextures1->Emitters->Count - 1; I++)
  55. GLSLProjectedTextures1->Emitters->Items[I]->Emitter->Turn(deltaTime * (I + 1) * 10);
  56. GLSceneViewer1->Invalidate();
  57. GLArrowLine1->Position->Y = GLArrowLine1->Position->Y + sdir * deltaTime;
  58. if (GLArrowLine1->Position->Y > 20)
  59. {
  60. GLArrowLine1->Position->Y = 20;
  61. sdir = -10;
  62. }
  63. if (GLArrowLine1->Position->Y < 10)
  64. {
  65. GLArrowLine1->Position->Y = 10;
  66. sdir = 10;
  67. }
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::GLCamera1CustomPerspective(const TRectangle &viewport, int width,
  71. int height, int DPI, float &viewPortRadius)
  72. {
  73. * CurrentGLContext()->PipelineTransformation->ProjectionMatrix =
  74. CreatePerspectiveMatrix((float)GLCamera1->GetFieldOfView(Width)/2, (float)Width / Height,
  75. GLCamera1->NearPlaneBias, GLCamera1->DepthOfView);
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  79. int X, int Y)
  80. {
  81. if (Shift.Contains(ssLeft))
  82. {
  83. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  84. mx = X;
  85. my = Y;
  86. }
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  90. TPoint &MousePos, bool &Handled)
  91. {
  92. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  96. TShiftState Shift, int X, int Y)
  97. {
  98. mx = X;
  99. my = Y;
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  103. {
  104. Caption = "GLSL Projected Texture " +GLSceneViewer1->FramesPerSecondText();
  105. }
  106. //---------------------------------------------------------------------------