fCubeMapC.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // ---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fCubeMapC.h"
  5. // ---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Coordinates"
  9. #pragma link "GLS.Objects"
  10. #pragma link "GLS.Scene"
  11. #pragma link "GLS.GeomObjects"
  12. #pragma link "GLS.SceneViewer"
  13. #pragma link "GLS.Texture"
  14. #pragma link "GLS.FileDDS"
  15. #pragma link "GLS.VectorFileObjects"
  16. #pragma resource "*.dfm"
  17. TForm1* Form1;
  18. // ---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}
  20. // ---------------------------------------------------------------------------
  21. void __fastcall TForm1::GLSceneViewer1BeforeRender(TObject* Sender)
  22. {
  23. // CubmapSupported = !GL_ARB_texture_cube_map;
  24. GLSceneViewer1->BeforeRender = NULL;
  25. }
  26. // ---------------------------------------------------------------------------
  27. void __fastcall TForm1::FormCreate(TObject* Sender)
  28. {
  29. // Our cube map images are here
  30. TFileName Path = GetCurrentAssetPath();
  31. SetCurrentDir(Path + "\\cubemap");
  32. }
  33. // ---------------------------------------------------------------------------
  34. void __fastcall TForm1::btnApplyClick(TObject* Sender)
  35. {
  36. // We need a CubeMapImage, which unlike the "regular Images" stores multiple images.
  37. Teapot1->Material->Texture->ImageClassName =
  38. __classid(TGLCubeMapImage)->ClassName();
  39. TGLCubeMapImage* Image =
  40. (TGLCubeMapImage*)Teapot1->Material->Texture->Image;
  41. // Load all 6 texture map components of the cube map
  42. // The 'PX', 'NX', etc. refer to 'positive X', 'negative X', etc.
  43. // and follow the RenderMan specs/conventions
  44. Image->Picture[CmtPX]->LoadFromFile("cm_left.jpg");
  45. Image->Picture[CmtNX]->LoadFromFile("cm_right.jpg");
  46. Image->Picture[CmtPY]->LoadFromFile("cm_top.jpg");
  47. Image->Picture[CmtNY]->LoadFromFile("cm_bottom.jpg");
  48. Image->Picture[CmtPZ]->LoadFromFile("cm_back.jpg");
  49. Image->Picture[CmtNZ]->LoadFromFile("cm_front.jpg");
  50. // Select reflection cube map environment mapping
  51. // This is the mode you'll most commonly use with cube maps, normal cube
  52. // map generation is also supported (used for diffuse environment lighting)
  53. Teapot1->Material->Texture->MappingMode = tmmCubeMapReflection;
  54. // That's all folks, let us see the thing!
  55. Teapot1->Material->Texture->Disabled = false;
  56. // apply .dds cubemaps to next objects
  57. DDStex(Plane1->Material->Texture, "skybox.dds");
  58. Plane1->Material->Texture->MappingMode = tmmEyeLinear;
  59. btnApply->Visible = false;
  60. }
  61. // ---------------------------------------------------------------------------
  62. void __fastcall TForm1::GLSceneViewer1MouseDown(
  63. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  64. {
  65. mx = X;
  66. my = Y;
  67. }
  68. // ---------------------------------------------------------------------------
  69. void __fastcall TForm1::GLSceneViewer1MouseMove(
  70. TObject* Sender, TShiftState Shift, int X, int Y)
  71. {
  72. if (Shift.Contains(ssLeft))
  73. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  74. else if (Shift.Contains(ssRight))
  75. GLCamera1->RotateTarget(my - Y, mx - X, 0);
  76. mx = X;
  77. my = Y;
  78. }
  79. // ---------------------------------------------------------------------------
  80. void __fastcall TForm1::FormMouseWheel(TObject* Sender, TShiftState Shift,
  81. int WheelDelta, TPoint &MousePos, bool &Handled)
  82. {
  83. GLCamera1->AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  84. }
  85. //---------------------------------------------------------------------------