fDyncubeMapC.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fDyncubeMapC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SkyDome"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::GenerateCubeMap()
  24. {
  25. // Don't do anything if cube maps aren't supported
  26. /*
  27. if (!CubmapSupported) {
  28. if (!CubeMapWarnDone)
  29. ShowMessage("Your graphics hardware does not support cube maps...");
  30. CubeMapWarnDone = true;
  31. exit;
  32. }
  33. */
  34. // Here we generate the new cube map, from CubeMapCamera (a child of the
  35. // teapot in the scene hierarchy)
  36. // hide the teapot while rendering the cube map
  37. Teapot1->Visible = false;
  38. // render cube map to the teapot's texture
  39. GLMemoryViewer1->RenderCubeMapTextures(Teapot1->Material->Texture);
  40. // teapot visible again
  41. Teapot1->Material->Texture->Disabled = false;
  42. Teapot1->Visible = true;
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  46. const double newTime)
  47. {
  48. if (CBDynamic->Checked) {
  49. // make things move
  50. Teapot1->Position->Y = 2*Sin(newTime);
  51. Torus1->RollAngle = newTime*15;
  52. // generate the cube map
  53. GenerateCubeMap();
  54. }
  55. GLSceneViewer1->Invalidate();
  56. }
  57. //---------------------------------------------------------------------------
  58. // Standard issue mouse movements
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  61. TShiftState Shift, int X, int Y)
  62. {
  63. mx = X;
  64. my = Y;
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  68. int X, int Y)
  69. {
  70. if (Shift.Contains(ssLeft))
  71. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  72. else if (Shift.Contains(ssRight))
  73. GLCamera1->RotateTarget(my-Y, mx-X, 0);
  74. mx=X; my=Y;
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  78. TPoint &MousePos, bool &Handled)
  79. {
  80. GLCamera1->
  81. AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  85. {
  86. LabelFPS->Caption = GLSceneViewer1->FramesPerSecondText();
  87. GLSceneViewer1->ResetPerformanceMonitor();
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::GLSceneViewer1BeforeRender(TObject *Sender)
  91. {
  92. CubmapSupported = !GL_ARB_texture_cube_map;
  93. GLSceneViewer1->BeforeRender = NULL;
  94. }
  95. //---------------------------------------------------------------------------