Unit1.cpp 3.9 KB

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