Unit1.cpp 3.4 KB

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