fMultiMaterialC.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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) : TForm(Owner) {}
  20. //---------------------------------------------------------------------------
  21. void __fastcall TForm1::FormCreate(TObject* Sender)
  22. {
  23. TGLLibMaterial* LibMat;
  24. TFileName Path = GetCurrentAssetPath() + "\\texture";
  25. SetCurrentDir(Path);
  26. // GLMatLib1 is the source of the first image
  27. // Add the specular material using tmModulate for shiny text
  28. GLMatLib1->AddTextureMaterial("specular", "glscene_alpha.bmp");
  29. GLMatLib1->Materials->GetLibMaterialByName("specular")->Material->Texture->TextureMode = tmModulate;
  30. // use TextureMode := tmBlend; for shiny background
  31. GLMatLib1->Materials->GetLibMaterialByName("specular")->Material->BlendingMode = bmAdditive;
  32. GLMatLib1->Materials->GetLibMaterialByName("specular")->Texture2Name = "specular_tex2";
  33. GLMatLib1->AddTextureMaterial("specular_tex2", "rainbow.bmp");
  34. GLMatLib1->Materials->GetLibMaterialByName("specular_tex2")->Material->Texture->MappingMode = tmmCubeMapReflection;
  35. GLMatLib1->Materials->GetLibMaterialByName("specular_tex2")->Material->Texture->ImageBrightness = 0.3;
  36. // GLMatLib2 is the source of the GLMultiMaterialShader passes.
  37. // Pass 1: Base texture
  38. GLMatLib2->AddTextureMaterial("Pass1", "glscene.bmp"); // or use glscene_delphi.bmp
  39. // Pass 2: Add a bit of detail
  40. GLMatLib2->AddTextureMaterial("Pass2", "detailmap.jpg");
  41. GLMatLib2->Materials->GetLibMaterialByName("Pass2")->Material->Texture->TextureMode = tmBlend;
  42. GLMatLib2->Materials->GetLibMaterialByName("Pass2")->Material->BlendingMode = bmAdditive;
  43. // Pass 3 : And a little specular reflection
  44. LibMat = new TGLLibMaterial(GLMatLib2->Materials);
  45. LibMat->Material->MaterialLibrary = GLMatLib1;
  46. LibMat->Material->LibMaterialName = "specular";
  47. // This isn't limited to 3, try adding some more passes!
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::GLSceneViewer1MouseDown(
  51. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  52. {
  53. mx = X;
  54. my = Y;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::FormMouseWheel(TObject* Sender, TShiftState Shift,
  58. int WheelDelta, TPoint &MousePos, bool &Handled)
  59. {
  60. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  61. Handled = true;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::GLCadencer1Progress(
  65. TObject* Sender, const double deltaTime, const double newTime)
  66. {
  67. GLCube1->Turn(deltaTime * 10);
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::GLSceneViewer1MouseMove(
  71. TObject* Sender, TShiftState Shift, int X, int Y)
  72. {
  73. if (Shift.Contains(ssLeft))
  74. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  75. mx = X;
  76. my = Y;
  77. }
  78. //---------------------------------------------------------------------------