/extlibs/SFML/include/SFML/Graphics/RenderImage.hpp

https://bitbucket.org/hugoruscitti/pilascpp · C++ Header · 289 lines · 31 code · 24 blank · 234 comment · 0 complexity · 54af3b27d3aad99c0bf20bbe27cc043f MD5 · raw file

  1. ////////////////////////////////////////////////////////////
  2. //
  3. // SFML - Simple and Fast Multimedia Library
  4. // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
  5. //
  6. // This software is provided 'as-is', without any express or implied warranty.
  7. // In no event will the authors be held liable for any damages arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it freely,
  11. // subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented;
  14. // you must not claim that you wrote the original software.
  15. // If you use this software in a product, an acknowledgment
  16. // in the product documentation would be appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such,
  19. // and must not be misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //
  23. ////////////////////////////////////////////////////////////
  24. #ifndef SFML_RENDERIMAGE_HPP
  25. #define SFML_RENDERIMAGE_HPP
  26. ////////////////////////////////////////////////////////////
  27. // Headers
  28. ////////////////////////////////////////////////////////////
  29. #include <SFML/Graphics/Image.hpp>
  30. #include <SFML/Graphics/RenderTarget.hpp>
  31. namespace sf
  32. {
  33. namespace priv
  34. {
  35. class RenderImageImpl;
  36. }
  37. ////////////////////////////////////////////////////////////
  38. /// \brief Target for off-screen 2D rendering into an image
  39. ///
  40. ////////////////////////////////////////////////////////////
  41. class SFML_API RenderImage : public RenderTarget
  42. {
  43. public :
  44. ////////////////////////////////////////////////////////////
  45. /// \brief Default constructor
  46. ///
  47. /// Constructs an empty, invalid render-image. You must
  48. /// call Create to have a valid render-image.
  49. ///
  50. /// \see Create
  51. ///
  52. ////////////////////////////////////////////////////////////
  53. RenderImage();
  54. ////////////////////////////////////////////////////////////
  55. /// \brief Destructor
  56. ///
  57. ////////////////////////////////////////////////////////////
  58. virtual ~RenderImage();
  59. ////////////////////////////////////////////////////////////
  60. /// \brief Create the render-image
  61. ///
  62. /// Before calling this function, the render-image is in
  63. /// an invalid state, thus it is mandatory to call it before
  64. /// doing anything with the render-image.
  65. /// The last parameter, \a depthBuffer, is useful if you want
  66. /// to use the render-image for 3D OpenGL rendering that requires
  67. /// a depth-buffer. Otherwise it is unnecessary, and you should
  68. /// leave this parameter to false (which is its default value).
  69. ///
  70. /// \param width Width of the render-image
  71. /// \param height Height of the render-image
  72. /// \param depthBuffer Do you want this render-image to have a depth buffer?
  73. ///
  74. /// \return True if creation has been successful
  75. ///
  76. ////////////////////////////////////////////////////////////
  77. bool Create(unsigned int width, unsigned int height, bool depthBuffer = false);
  78. ////////////////////////////////////////////////////////////
  79. /// \brief Enable or disable image smoothing
  80. ///
  81. /// This function is similar to Image::SetSmooth.
  82. /// This parameter is enabled by default.
  83. ///
  84. /// \param smooth True to enable smoothing, false to disable it
  85. ///
  86. /// \see IsSmooth
  87. ///
  88. ////////////////////////////////////////////////////////////
  89. void SetSmooth(bool smooth);
  90. ////////////////////////////////////////////////////////////
  91. /// \brief Tell whether the smooth filtering is enabled or not
  92. ///
  93. /// \return True if image smoothing is enabled
  94. ///
  95. /// \see SetSmooth
  96. ///
  97. ////////////////////////////////////////////////////////////
  98. bool IsSmooth() const;
  99. ////////////////////////////////////////////////////////////
  100. /// \brief Activate of deactivate the render-image for rendering
  101. ///
  102. /// This function makes the render-image's context current for
  103. /// future OpenGL rendering operations (so you shouldn't care
  104. /// about it if you're not doing direct OpenGL stuff).
  105. /// Only one context can be current on a thread, so if you
  106. /// want to draw OpenGL geometry to another render target
  107. /// (like a RenderWindow) don't forget to activate it again.
  108. ///
  109. /// \param active True to activate, false to deactivate
  110. ///
  111. /// \return True if operation was successful, false otherwise
  112. ///
  113. ////////////////////////////////////////////////////////////
  114. bool SetActive(bool active = true);
  115. ////////////////////////////////////////////////////////////
  116. /// \brief Update the contents of the target image
  117. ///
  118. /// This function updates the target image with what
  119. /// has been drawn so far. Like for windows, calling this
  120. /// function is mandatory at the end of rendering. Not calling
  121. /// it may leave the image in an undefined state.
  122. ///
  123. ////////////////////////////////////////////////////////////
  124. void Display();
  125. ////////////////////////////////////////////////////////////
  126. /// \brief Return the width of the rendering region of the image
  127. ///
  128. /// The returned value is the size that you passed to
  129. /// the Create function.
  130. ///
  131. /// \return Width in pixels
  132. ///
  133. /// \return GetHeight
  134. ///
  135. ////////////////////////////////////////////////////////////
  136. virtual unsigned int GetWidth() const;
  137. ////////////////////////////////////////////////////////////
  138. /// \brief Return the height of the rendering region of the image
  139. ///
  140. /// The returned value is the size that you passed to
  141. /// the Create function.
  142. ///
  143. /// \return Height in pixels
  144. ///
  145. /// \return GetWidth
  146. ///
  147. ////////////////////////////////////////////////////////////
  148. virtual unsigned int GetHeight() const;
  149. ////////////////////////////////////////////////////////////
  150. /// \brief Get a read-only reference to the target image
  151. ///
  152. /// After drawing to the render-image and calling Display,
  153. /// you can retrieve the updated image using this function,
  154. /// and draw it using a sprite (for example).
  155. /// The internal sf::Image of a render-image is always the
  156. /// same instance, so that it is possible to call this function
  157. /// once and keep a reference to the image even after is it
  158. /// modified.
  159. ///
  160. /// \return Const reference to the image
  161. ///
  162. ////////////////////////////////////////////////////////////
  163. const Image& GetImage() const;
  164. ////////////////////////////////////////////////////////////
  165. /// \brief Check whether the system supports render images or not
  166. ///
  167. /// It is very important to always call this function before
  168. /// trying to use the RenderImage class, as the feature may not
  169. /// be supported on all platforms (especially very old ones).
  170. /// If this function returns false, then you won't be able
  171. /// to use the class at all.
  172. ///
  173. /// \return True if the RenderImage class can be used
  174. ///
  175. ////////////////////////////////////////////////////////////
  176. static bool IsAvailable();
  177. private :
  178. ////////////////////////////////////////////////////////////
  179. /// \brief Activate the targt efor rendering
  180. ///
  181. /// This function is called by the base class
  182. /// everytime it's going to use OpenGL calls.
  183. ///
  184. /// \param active True to make the target active, false to deactivate it
  185. ///
  186. /// \return True if the function succeeded
  187. ///
  188. ////////////////////////////////////////////////////////////
  189. virtual bool Activate(bool active);
  190. ////////////////////////////////////////////////////////////
  191. // Member data
  192. ////////////////////////////////////////////////////////////
  193. Image myImage; ///< Target image to draw on
  194. priv::RenderImageImpl* myRenderImage; ///< Platform / hardware specific implementation
  195. };
  196. } // namespace sf
  197. #endif // SFML_RENDERIMAGE_HPP
  198. ////////////////////////////////////////////////////////////
  199. /// \class sf::RenderImage
  200. /// \ingroup graphics
  201. ///
  202. /// sf::RenderImage is the little brother of sf::RenderWindow.
  203. /// It implements the same 2D drawing and OpenGL-related functions
  204. /// (see their base class sf::RenderTarget for more details),
  205. /// the difference is that the result is stored in an off-screen
  206. /// image rather than being show in a window.
  207. ///
  208. /// Rendering to an image can be useful in a variety of situations:
  209. /// \li precomputing a complex static image (like a level's background from multiple tiles)
  210. /// \li applying post-effects to the whole scene with shaders
  211. /// \li creating a sprite from a 3D object rendered with OpenGL
  212. /// \li etc.
  213. ///
  214. /// Usage example:
  215. ///
  216. /// \code
  217. /// // First of all: make sure that rendering to image is supported
  218. /// if (!sf::RenderImage::IsAvailable())
  219. /// return -1;
  220. ///
  221. /// // Create a new render-window
  222. /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
  223. ///
  224. /// // Create a new render-image
  225. /// sf::RenderImage image;
  226. /// if (!image.Create(500, 500))
  227. /// return -1
  228. ///
  229. /// // The main loop
  230. /// while (window.IsOpened())
  231. /// {
  232. /// // Event processing
  233. /// // ...
  234. ///
  235. /// // Clear the whole image with red color
  236. /// image.Clear(sf::Color::Red);
  237. ///
  238. /// // Draw stuff to the image
  239. /// image.Draw(sprite); // sprite is a sf::Sprite
  240. /// image.Draw(shape); // shape is a sf::Shape
  241. /// image.Draw(text); // text is a sf::Text
  242. ///
  243. /// // We're done drawing to the image
  244. /// image.Display();
  245. ///
  246. /// // Now we start rendering to the window, clear it first
  247. /// window.Clear();
  248. ///
  249. /// // Draw the image
  250. /// sf::Sprite sprite(image.GetImage());
  251. /// window.Draw(sprite);
  252. ///
  253. /// // End the current frame and display its contents on screen
  254. /// window.Display();
  255. /// }
  256. /// \endcode
  257. ///
  258. /// Like sf::RenderWindow, sf::RenderImage is still able to render direct
  259. /// OpenGL stuff. It is even possible to mix together OpenGL calls
  260. /// and regular SFML drawing commands. If you need a depth buffer for
  261. /// 3D rendering, don't forget to request it when calling RenderImage::Create.
  262. ///
  263. /// \see sf::RenderTarget, sf::RenderWindow, sf::View
  264. ///
  265. ////////////////////////////////////////////////////////////