Unit1.cpp 3.6 KB

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