fCubeMapC.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // apply .dds cubemaps to next objects
  45. DDStex(Teapot1->Material->Texture, "skybox.dds");
  46. // Select reflection cube map environment mapping
  47. // This is the mode you'll most commonly use with cube maps, normal cube
  48. // map generation is also supported (used for diffuse environment lighting)
  49. Teapot1->Material->Texture->MappingMode = tmmCubeMapReflection;
  50. // That's all folks, let us see the thing!
  51. Teapot1->Material->Texture->Disabled = false;
  52. // apply .dds cubemaps to next objects
  53. DDStex(Plane1->Material->Texture, "skybox.dds");
  54. Plane1->Material->Texture->MappingMode = tmmEyeLinear;
  55. btnApply->Visible = false;
  56. }
  57. // ---------------------------------------------------------------------------
  58. void __fastcall TForm1::GLSceneViewer1MouseDown(
  59. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  60. {
  61. mx = X;
  62. my = Y;
  63. }
  64. // ---------------------------------------------------------------------------
  65. void __fastcall TForm1::GLSceneViewer1MouseMove(
  66. TObject* Sender, TShiftState Shift, int X, int Y)
  67. {
  68. if (Shift.Contains(ssLeft))
  69. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  70. else if (Shift.Contains(ssRight))
  71. GLCamera1->RotateTarget(my - Y, mx - X, 0);
  72. mx = X;
  73. my = Y;
  74. }
  75. // ---------------------------------------------------------------------------
  76. void __fastcall TForm1::FormMouseWheel(TObject* Sender, TShiftState Shift,
  77. int WheelDelta, TPoint &MousePos, bool &Handled)
  78. {
  79. GLCamera1->AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  80. }
  81. //---------------------------------------------------------------------------