2
0

Unit1.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include "Unit1.h"
  4. //---------------------------------------------------------------------------
  5. #pragma package(smart_init)
  6. #pragma classgroup "System.Classes.TPersistent"
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Coordinates"
  9. #pragma link "GLS.Scene"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma resource "*.dfm"
  12. TDataModule1 *DataModule1;
  13. //---------------------------------------------------------------------------
  14. __fastcall TDataModule1::TDataModule1(TComponent* Owner)
  15. : TDataModule(Owner)
  16. {
  17. }
  18. //---------------------------------------------------------------------------
  19. void TDataModule1::DataModuleCreate(TObject *Sender)
  20. {
  21. // When using SDL, the standard VCL message queue is no longer operational,
  22. // so you must have/make your own loop to prevent the application from
  23. // terminating immediately
  24. GLSDLViewer1->Render();
  25. while (GLSDLViewer1->Active())
  26. {
  27. // Message queue is not operational, but there may still be some messages
  28. Forms::Application->ProcessMessages();
  29. // Relinquish some of that CPU time
  30. SDL_Delay(1);
  31. // Slowly rotate the teapot
  32. Teapot1->RollAngle = 4*Frac(24*(Now()))*3600;
  33. }
  34. }
  35. //---------------------------------------------------------------------------
  36. void TDataModule1::GLSDLViewer1EventPollDone(TObject *Sender)
  37. {
  38. SetGLSceneMediaDir();
  39. TFileName PathCM = GetCurrentDir() + "\\Cubemaps";
  40. SetCurrentDir(PathCM);
  41. if (!firstPassDone)
  42. {
  43. // Loads a texture map for the teapot
  44. // (see materials/cubemap for details on that)
  45. //
  46. // The odd bit is that it must be done upon first render, otherwise
  47. // SDL OpenGL support has not been initialized and things like checking
  48. // an extension support (cube maps here) would fail...
  49. // Something less clunky will be introduced, someday...
  50. firstPassDone = true;
  51. GLSDLViewer1->Buffer->RenderingContext->Activate();
  52. try {
  53. if (!GL_ARB_texture_cube_map)
  54. ShowMessage("Your graphics board does not support cube maps");
  55. else
  56. {
  57. TGLTexture *tex = Teapot1->Material->Texture;
  58. tex->ImageClassName = __classid(TGLCubeMapImage)->ClassName();
  59. TGLCubeMapImage *img = (TGLCubeMapImage *) tex->Image;
  60. img->Picture[CmtPX]->LoadFromFile("cm_left.jpg");
  61. img->Picture[CmtNX]->LoadFromFile("cm_right.jpg");
  62. img->Picture[CmtPY]->LoadFromFile("cm_top.jpg");
  63. img->Picture[CmtNY]->LoadFromFile("cm_bottom.jpg");
  64. img->Picture[CmtPZ]->LoadFromFile("cm_back.jpg");
  65. img->Picture[CmtNZ]->LoadFromFile("cm_front.jpg");
  66. Teapot1->Material->Texture->MappingMode = tmmCubeMapReflection;
  67. Teapot1->Material->Texture->Disabled = false;
  68. }
  69. }
  70. __finally
  71. {
  72. GLSDLViewer1->Buffer->RenderingContext->Deactivate();
  73. }
  74. }
  75. GLSDLViewer1->Render();
  76. }
  77. //---------------------------------------------------------------------------
  78. void TDataModule1::GLSDLViewer1Resize(TObject *Sender)
  79. {
  80. // Zoom if SDL window gets smaller/bigger
  81. GLCamera1->SceneScale = GLSDLViewer1->Width/160;
  82. }
  83. //---------------------------------------------------------------------------