fShaderComponentC.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "fShaderComponentC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLSL.CustomShader"
  12. #pragma link "GLS.GeomObjects"
  13. #pragma link "GLS.Graph"
  14. #pragma link "GLS.Material"
  15. #pragma link "GLS.Objects"
  16. #pragma link "GLS.Scene"
  17. #pragma link "GLS.SimpleNavigation"
  18. #pragma link "GLSL.Shader"
  19. #pragma link "GLS.VectorFileObjects"
  20. #pragma link "GLS.SceneViewer"
  21. #pragma link "GLS.FileSMD"
  22. #pragma link "GLS.FileMD2"
  23. #pragma link "GLS.File3DS"
  24. #pragma link "GLS.FileMS3D"
  25. #pragma resource "*.dfm"
  26. TForm1 *Form1;
  27. //---------------------------------------------------------------------------
  28. __fastcall TForm1::TForm1(TComponent* Owner)
  29. : TForm(Owner)
  30. {
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TForm1::FormCreate(TObject *Sender)
  34. {
  35. SetGLSceneMediaDir();
  36. //First load scripts from shader directory in project dir
  37. GLSLShader->LoadShaderPrograms("Shaders\\Shader.Vert","Shaders\\Shader.Frag");
  38. GLSLShader->Enabled = true;
  39. //Second load models from media directory
  40. Fighter->LoadFromFile("waste.md2"); //Fighter
  41. Fighter->SwitchToAnimation(0, true);
  42. Fighter->AnimationMode = aamLoop;
  43. Fighter->Scale->Scale(3);
  44. Teapot->LoadFromFile("Teapot.3ds"); //Teapot (no texture coordinates)
  45. Teapot->Scale->Scale(0.8);
  46. Sphere_big->LoadFromFile("Sphere_big.3DS"); //Sphere_big
  47. Sphere_big->Scale->Scale(70);
  48. Sphere_little->LoadFromFile("Sphere_little.3ds"); //Sphere_little
  49. Sphere_little->Scale->Scale(4);
  50. // Then load textures.
  51. MaterialLibrary->LibMaterialByName("Earth")->Material->Texture->Image->LoadFromFile("Earth.jpg");
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::ShadeEnabledCheckBoxClick(TObject *Sender)
  55. {
  56. GLSLShader->Enabled = ShadeEnabledCheckBox->Checked;
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::GLSLShaderApply(TGLCustomGLSLShader *Shader)
  60. {
  61. Shader->Param["DiffuseColor"]->AsVector4f = VectorMake(1, 1, 1, 1);
  62. Shader->Param["AmbientColor"]->AsVector4f = VectorMake(0.2, 0.2, 0.2, 1);
  63. Shader->Param["LightIntensity"]->AsVector1f = 1;
  64. Shader->SetTex("MainTexture", MaterialLibrary->LibMaterialByName("Earth")->Material->Texture);
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::GLSLShaderInitialize(TGLCustomGLSLShader *Shader)
  68. {
  69. // Do nothing.
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::GLSLShaderUnApply(TGLCustomGLSLShader *Shader, bool &ThereAreMorePasses)
  73. {
  74. // Do nothing.
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::CadencerProgress(TObject *Sender, const double deltaTime,
  78. const double newTime)
  79. {
  80. Viewer->Invalidate();
  81. if (PitchRollTurnCheckBox->Checked) {
  82. Sphere_big->Pitch(40 * deltaTime);
  83. Sphere_big->Turn(40 * deltaTime);
  84. Sphere_little->Roll(40 * deltaTime);
  85. }
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TForm1::LightCubeProgress(TObject *Sender, const double deltaTime,
  89. const double newTime)
  90. {
  91. if (LightMovingCheckBox->Checked)
  92. LightCube->MoveObjectAround(Camera->TargetObject, sin(newTime) * deltaTime * 10, deltaTime * 20);
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  96. {
  97. Cadencer->Enabled = false;
  98. }
  99. //---------------------------------------------------------------------------