2
0

Unit1.cpp 3.6 KB

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