Unit1.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLBaseClasses"
  9. #pragma link "GLBitmapFont"
  10. #pragma link "GLCadencer"
  11. #pragma link "GLCoordinates"
  12. #pragma link "GLCrossPlatform"
  13. #pragma link "GLCustomShader"
  14. #pragma link "GLFBORenderer"
  15. #pragma link "GLGeomObjects"
  16. #pragma link "GLHUDObjects"
  17. #pragma link "GLMaterial"
  18. #pragma link "GLObjects"
  19. #pragma link "GLScene"
  20. #pragma link "GLSimpleNavigation"
  21. #pragma link "GLSLShader"
  22. #pragma link "GLWin32Viewer"
  23. #pragma link "GLWindowsFont"
  24. #pragma link "GLMultisampleImage"
  25. #pragma resource "*.dfm"
  26. TForm1 *Form1;
  27. //---------------------------------------------------------------------------
  28. __fastcall TForm1::TForm1(TComponent* Owner)
  29. : TForm(Owner)
  30. {
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TForm1::FormCreate(TObject *Sender)
  34. {
  35. Width = Screen->Width;
  36. Height = Screen->Height;
  37. WindowState = wsMaximized;
  38. MainMaterialLibrary->TextureByName("MultisampledColor")->ImageClassName = "TGLMultisampleImage";
  39. ((TGLMultisampleImage *)(MainMaterialLibrary->TextureByName("MultisampledColor")->Image))->SamplesCount = 16;
  40. MainMaterialLibrary->TextureByName("Depth")->ImageClassName = "TGLMultisampleImage";
  41. ((TGLMultisampleImage *)(MainMaterialLibrary->TextureByName("Depth")->Image))->SamplesCount = 16;
  42. GLSLShader1->Enabled = true;
  43. GLHUDText1->Text = "F1/F2 - Multisampling and F3/F4 - Wireframe mode";
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TForm1::MainCadencerProgress(TObject *Sender, const double deltaTime,
  47. const double newTime)
  48. {
  49. if (IsKeyDown(VK_F2))
  50. {
  51. FBOContainer->Visible = false;
  52. GLScreenQuad->Visible = false;
  53. SceneObjects->Visible = true;
  54. }
  55. if (IsKeyDown(VK_F1))
  56. {
  57. FBOContainer->Visible = true;
  58. GLScreenQuad->Visible = true;
  59. SceneObjects->Visible = false;
  60. }
  61. if (IsKeyDown(VK_F3))
  62. {
  63. GLTorus1->Material->PolygonMode = pmLines;
  64. GLTorus2->Material->PolygonMode = pmLines;
  65. GLCone1->Material->PolygonMode = pmLines;
  66. }
  67. if (IsKeyDown(VK_F4))
  68. {
  69. GLTorus1->Material->PolygonMode = pmFill;
  70. GLTorus2->Material->PolygonMode = pmFill;
  71. GLCone1->Material->PolygonMode = pmFill;
  72. }
  73. MainViewer->Invalidate();
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TForm1::FormResize(TObject *Sender)
  77. {
  78. MultisampleFBO->Width = MainViewer->Width;
  79. MultisampleFBO->Height = MainViewer->Height;
  80. GLScreenQuad->Width = MainViewer->Width;
  81. GLScreenQuad->Height = MainViewer->Height;
  82. GLScreenQuad->Position->SetPoint(
  83. MainViewer->Width / 2,
  84. MainViewer->Height / 2, 0);
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TForm1::GLSLShader1Apply(TGLCustomGLSLShader *Shader)
  88. {
  89. Shader->Param["TexUnit0"]->AsTexture[0] =
  90. MainMaterialLibrary->TextureByName("MultisampledColor");
  91. Shader->Param["ViewerSize"]->AsVector2f =
  92. Vector2fMake(MainViewer->Width, MainViewer->Height);
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::MainViewerBeforeRender(TObject *Sender)
  96. {
  97. if (GL_EXT_framebuffer_multisample)
  98. {
  99. ShowMessage
  100. ("Sorry, your hardware do not support Multisampling");
  101. Close();
  102. }
  103. }
  104. //---------------------------------------------------------------------------