fShaderCompC.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "fShaderCompC.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. TFileName Path = GetCurrentAssetPath();
  36. //First load scripts from shader asset directory
  37. SetCurrentDir(Path + "\\shader");
  38. GLSLShader->LoadShaderPrograms("shader.vert","shader.frag");
  39. GLSLShader->Enabled = true;
  40. //Second load static models
  41. SetCurrentDir(Path + "\\model");
  42. Teapot->LoadFromFile("Teapot.3ds"); //Teapot has no texture coordinates
  43. Teapot->Scale->Scale(0.8);
  44. Sphere_big->LoadFromFile("Sphere_big.3DS"); //Sphere_big
  45. Sphere_big->Scale->Scale(70);
  46. Sphere_little->LoadFromFile("Sphere.3ds"); //Sphere_little
  47. Sphere_little->Scale->Scale(4);
  48. //Third loading dynamic models with skeletal animation
  49. SetCurrentDir(Path + "\\modelext");
  50. Fighter->LoadFromFile("waste.md2"); //Fighter
  51. Fighter->SwitchToAnimation(0, true);
  52. Fighter->AnimationMode = aamLoop;
  53. Fighter->Scale->Scale(3);
  54. // Then load textures.
  55. SetCurrentDir(Path + "\\map");
  56. MaterialLibrary->LibMaterialByName("Earth")->Material->Texture->Image->LoadFromFile("earth.jpg");
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::ShadeEnabledCheckBoxClick(TObject *Sender)
  60. {
  61. GLSLShader->Enabled = ShadeEnabledCheckBox->Checked;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::GLSLShaderApply(TGLCustomGLSLShader *Shader)
  65. {
  66. Shader->Param["DiffuseColor"]->AsVector4f = VectorMake(1, 1, 1, 1);
  67. Shader->Param["AmbientColor"]->AsVector4f = VectorMake(0.2, 0.2, 0.2, 1);
  68. Shader->Param["LightIntensity"]->AsVector1f = 1;
  69. Shader->SetTex("MainTexture", MaterialLibrary->LibMaterialByName("Earth")->Material->Texture);
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::GLSLShaderInitialize(TGLCustomGLSLShader *Shader)
  73. {
  74. // Do nothing.
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::GLSLShaderUnApply(TGLCustomGLSLShader *Shader, bool &ThereAreMorePasses)
  78. {
  79. // Do nothing.
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TForm1::CadencerProgress(TObject *Sender, const double deltaTime,
  83. const double newTime)
  84. {
  85. Viewer->Invalidate();
  86. if (PitchRollTurnCheckBox->Checked) {
  87. Sphere_big->Pitch(40 * deltaTime);
  88. Sphere_big->Turn(40 * deltaTime);
  89. Sphere_little->Roll(40 * deltaTime);
  90. }
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TForm1::LightCubeProgress(TObject *Sender, const double deltaTime,
  94. const double newTime)
  95. {
  96. if (LightMovingCheckBox->Checked)
  97. LightCube->MoveObjectAround(Camera->TargetObject, sin(newTime) * deltaTime * 10, deltaTime * 20);
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  101. {
  102. Cadencer->Enabled = false;
  103. }
  104. //---------------------------------------------------------------------------