fCubeMapC.cpp 3.6 KB

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