Unit1.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "GLCadencer"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLGeomObjects"
  12. #pragma link "GLObjects"
  13. #pragma link "GLScene"
  14. #pragma link "GLSkydome"
  15. #pragma link "GLTeapot"
  16. #pragma link "GLWin32Viewer"
  17. #pragma resource "*.dfm"
  18. TForm1 *Form1;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::GenerateCubeMap()
  26. {
  27. // Don't do anything if cube maps aren't supported
  28. if (!CubmapSupported) {
  29. if (!CubeMapWarnDone)
  30. ShowMessage("Your graphics hardware does not support cube maps...");
  31. CubeMapWarnDone = true;
  32. exit;
  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. //---------------------------------------------------------------------------