fCubeMapC.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 resource "*.dfm"
  15. TForm1 *Form1;
  16. // ---------------------------------------------------------------------------
  17. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
  18. }
  19. // ---------------------------------------------------------------------------
  20. void __fastcall TForm1::GLSceneViewer1BeforeRender(TObject *Sender) {
  21. // CubmapSupported = !GL_ARB_texture_cube_map;
  22. GLSceneViewer1->BeforeRender = NULL;
  23. }
  24. // ---------------------------------------------------------------------------
  25. void __fastcall TForm1::Button1Click(TObject *Sender) {
  26. // Cube map warning message
  27. // If you don't check and turn off cube maps yourself in your apps when
  28. // cube maps aren't supported, GLScene will just turn off texturing
  29. // (ie. no error generated, just a different output)
  30. /*
  31. if (!CubmapSupported)
  32. {
  33. ShowMessage("Your graphics board does not support cube maps...");
  34. exit;
  35. }
  36. */
  37. // Our cube map images are here
  38. SetGLSceneMediaDir();
  39. // We need a CubeMapImage, which unlike the "regular Images" stores
  40. // multiple images.
  41. // with Teapot1->Material->Texture->
  42. Teapot1->Material->Texture->ImageClassName =
  43. __classid(TGLCubeMapImage)->ClassName();
  44. TGLCubeMapImage *Image =
  45. (TGLCubeMapImage*) Teapot1->Material->Texture->Image;
  46. // Load all 6 texture map components of the cube map
  47. // The 'PX', 'NX', etc. refer to 'positive X', 'negative X', etc.
  48. // and follow the RenderMan specs/conventions
  49. Image->Picture[CmtPX]->LoadFromFile("Cubemaps\\cm_left.jpg");
  50. Image->Picture[CmtNX]->LoadFromFile("Cubemaps\\cm_right.jpg");
  51. Image->Picture[CmtPY]->LoadFromFile("Cubemaps\\cm_top.jpg");
  52. Image->Picture[CmtNY]->LoadFromFile("Cubemaps\\cm_bottom.jpg");
  53. Image->Picture[CmtPZ]->LoadFromFile("Cubemaps\\cm_back.jpg");
  54. Image->Picture[CmtNZ]->LoadFromFile("Cubemaps\\cm_front.jpg");
  55. // Select reflection cube map environment mapping
  56. // This is the mode you'll most commonly use with cube maps, normal cube
  57. // map generation is also supported (used for diffuse environment lighting)
  58. Teapot1->Material->Texture->MappingMode = tmmCubeMapReflection;
  59. // That's all folks, let us see the thing!
  60. Teapot1->Material->Texture->Disabled = false;
  61. Button1->Visible = false;
  62. }
  63. // ---------------------------------------------------------------------------
  64. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender,
  65. TMouseButton Button, TShiftState Shift, int X, int Y) {
  66. mx = X;
  67. my = Y;
  68. }
  69. // ---------------------------------------------------------------------------
  70. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender,
  71. TShiftState Shift, int X, int Y) {
  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. GLCamera1->AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  83. }
  84. // ---------------------------------------------------------------------------