MultipleViewports.h 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. namespace Urho3D
  6. {
  7. class Node;
  8. class Scene;
  9. }
  10. /// Multiple viewports example.
  11. /// This sample demonstrates:
  12. /// - Setting up two viewports with two separate cameras
  13. /// - Adding post processing effects to a viewport's render path and toggling them
  14. class MultipleViewports : public Sample
  15. {
  16. URHO3D_OBJECT(MultipleViewports, Sample);
  17. public:
  18. /// Construct.
  19. explicit MultipleViewports(Context* context);
  20. /// Setup after engine initialization and before running the main loop.
  21. void Start() override;
  22. protected:
  23. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  24. String GetScreenJoystickPatchString() const override { return
  25. "<patch>"
  26. " <add sel=\"/element\">"
  27. " <element type=\"Button\">"
  28. " <attribute name=\"Name\" value=\"Button3\" />"
  29. " <attribute name=\"Position\" value=\"-120 -120\" />"
  30. " <attribute name=\"Size\" value=\"96 96\" />"
  31. " <attribute name=\"Horiz Alignment\" value=\"Right\" />"
  32. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />"
  33. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />"
  34. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />"
  35. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />"
  36. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />"
  37. " <element type=\"Text\">"
  38. " <attribute name=\"Name\" value=\"Label\" />"
  39. " <attribute name=\"Horiz Alignment\" value=\"Center\" />"
  40. " <attribute name=\"Vert Alignment\" value=\"Center\" />"
  41. " <attribute name=\"Color\" value=\"0 0 0 1\" />"
  42. " <attribute name=\"Text\" value=\"FXAA\" />"
  43. " </element>"
  44. " <element type=\"Text\">"
  45. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  46. " <attribute name=\"Text\" value=\"F\" />"
  47. " </element>"
  48. " </element>"
  49. " </add>"
  50. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  51. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Bloom</replace>"
  52. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  53. " <element type=\"Text\">"
  54. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  55. " <attribute name=\"Text\" value=\"B\" />"
  56. " </element>"
  57. " </add>"
  58. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  59. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>"
  60. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  61. " <element type=\"Text\">"
  62. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  63. " <attribute name=\"Text\" value=\"SPACE\" />"
  64. " </element>"
  65. " </add>"
  66. "</patch>";
  67. }
  68. private:
  69. /// Construct the scene content.
  70. void CreateScene();
  71. /// Construct an instruction text to the UI.
  72. void CreateInstructions();
  73. /// Set up viewports.
  74. void SetupViewports();
  75. /// Subscribe to application-wide logic update and post-render update events.
  76. void SubscribeToEvents();
  77. /// Read input and moves the camera.
  78. void MoveCamera(float timeStep);
  79. /// Handle the logic update event.
  80. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  81. /// Handle the post-render update event.
  82. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  83. /// Rear-facing camera scene node.
  84. SharedPtr<Node> rearCameraNode_;
  85. /// Flag for drawing debug geometry.
  86. bool drawDebug_;
  87. };