fMultiMaterialC.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fMultiMaterialC.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.Material"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma link "GLSL.MultiMaterialShader"
  15. #pragma link "GLSL.TextureShaders"
  16. #pragma resource "*.dfm"
  17. TForm1 *Form1;
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20. : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::FormCreate(TObject *Sender)
  25. {
  26. SetGLSceneMediaDir();
  27. // Add the specular pass
  28. // tmBlend for shiny background
  29. //Material->Texture->TextureMode = tmBlend;
  30. // tmModulate for shiny text
  31. GLMaterialLibrary1->AddTextureMaterial("specular","GLScene_alpha.bmp")->Material->Texture->TextureMode = tmModulate;
  32. GLMaterialLibrary1->AddTextureMaterial("specular","GLScene_alpha.bmp")->Material->BlendingMode = bmAdditive;
  33. GLMaterialLibrary1->AddTextureMaterial("specular","GLScene_alpha.bmp")->Texture2Name = "specular_tex2";
  34. GLMaterialLibrary1->AddTextureMaterial("specular_tex2","chrome_buckle.bmp")->Material->Texture->MappingMode = tmmCubeMapReflection;
  35. GLMaterialLibrary1->AddTextureMaterial("specular_tex2","chrome_buckle.bmp")->Material->Texture->ImageBrightness = 0.3;
  36. // GLMaterialLibrary2 is the source of the GLMultiMaterialShader
  37. // passes.
  38. // Pass 1 : Base texture
  39. GLMaterialLibrary2->AddTextureMaterial("Pass1","glscene.bmp");//}
  40. // Pass 2 : Add a bit of detail
  41. GLMaterialLibrary2->AddTextureMaterial("Pass2","detailmap.jpg")->Material->Texture->TextureMode=tmBlend;
  42. GLMaterialLibrary2->AddTextureMaterial("Pass2","detailmap.jpg")->Material->BlendingMode=bmAdditive;
  43. // Pass 3 : And a little specular reflection
  44. (new TGLLibMaterial(GLMaterialLibrary2->Materials))->Material->MaterialLibrary=GLMaterialLibrary1;
  45. (new TGLLibMaterial(GLMaterialLibrary2->Materials))->Material->LibMaterialName="specular";
  46. // This isn't limited to 3, try adding some more passes!
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  50. TShiftState Shift, int X, int Y)
  51. {
  52. mx=X;
  53. my=Y;
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  57. TPoint &MousePos, bool &Handled)
  58. {
  59. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta/120));
  60. Handled = true;
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  64. const double newTime)
  65. {
  66. GLCube1->Turn(deltaTime*100);
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  70. int X, int Y)
  71. {
  72. if (Shift.Contains(ssLeft))
  73. GLCamera1->MoveAroundTarget(my-Y,mx-X);
  74. mx=X;
  75. my=Y;
  76. }
  77. //---------------------------------------------------------------------------