384e459502d171908cf74f852b6c5093b98f39c1
[TDDC76_proj.git] /
1 ////////////////////////////////////////////////////////////
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 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
25 #ifndef SFML_RENDERTEXTURE_HPP
26 #define SFML_RENDERTEXTURE_HPP
27
28 ////////////////////////////////////////////////////////////
29 // Headers
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Graphics/Export.hpp>
32 #include <SFML/Graphics/Texture.hpp>
33 #include <SFML/Graphics/RenderTarget.hpp>
34
35
36 namespace sf
37 {
38 namespace priv
39 {
40 class RenderTextureImpl;
41 }
42
43 ////////////////////////////////////////////////////////////
44 /// \brief Target for off-screen 2D rendering into a texture
45 ///
46 ////////////////////////////////////////////////////////////
47 class SFML_GRAPHICS_API RenderTexture : public RenderTarget
48 {
49 public :
50
51 ////////////////////////////////////////////////////////////
52 /// \brief Default constructor
53 ///
54 /// Constructs an empty, invalid render-texture. You must
55 /// call create to have a valid render-texture.
56 ///
57 /// \see create
58 ///
59 ////////////////////////////////////////////////////////////
60 RenderTexture();
61
62 ////////////////////////////////////////////////////////////
63 /// \brief Destructor
64 ///
65 ////////////////////////////////////////////////////////////
66 virtual ~RenderTexture();
67
68 ////////////////////////////////////////////////////////////
69 /// \brief Create the render-texture
70 ///
71 /// Before calling this function, the render-texture is in
72 /// an invalid state, thus it is mandatory to call it before
73 /// doing anything with the render-texture.
74 /// The last parameter, \a depthBuffer, is useful if you want
75 /// to use the render-texture for 3D OpenGL rendering that requires
76 /// a depth-buffer. Otherwise it is unnecessary, and you should
77 /// leave this parameter to false (which is its default value).
78 ///
79 /// \param width Width of the render-texture
80 /// \param height Height of the render-texture
81 /// \param depthBuffer Do you want this render-texture to have a depth buffer?
82 ///
83 /// \return True if creation has been successful
84 ///
85 ////////////////////////////////////////////////////////////
86 bool create(unsigned int width, unsigned int height, bool depthBuffer = false);
87
88 ////////////////////////////////////////////////////////////
89 /// \brief Enable or disable texture smoothing
90 ///
91 /// This function is similar to Texture::setSmooth.
92 /// This parameter is disabled by default.
93 ///
94 /// \param smooth True to enable smoothing, false to disable it
95 ///
96 /// \see isSmooth
97 ///
98 ////////////////////////////////////////////////////////////
99 void setSmooth(bool smooth);
100
101 ////////////////////////////////////////////////////////////
102 /// \brief Tell whether the smooth filtering is enabled or not
103 ///
104 /// \return True if texture smoothing is enabled
105 ///
106 /// \see setSmooth
107 ///
108 ////////////////////////////////////////////////////////////
109 bool isSmooth() const;
110
111 ////////////////////////////////////////////////////////////
112 /// \brief Enable or disable texture repeating
113 ///
114 /// This function is similar to Texture::setRepeated.
115 /// This parameter is disabled by default.
116 ///
117 /// \param repeated True to enable repeating, false to disable it
118 ///
119 /// \see isRepeated
120 ///
121 ////////////////////////////////////////////////////////////
122 void setRepeated(bool repeated);
123
124 ////////////////////////////////////////////////////////////
125 /// \brief Tell whether the texture is repeated or not
126 ///
127 /// \return True if texture is repeated
128 ///
129 /// \see setRepeated
130 ///
131 ////////////////////////////////////////////////////////////
132 bool isRepeated() const;
133
134 ////////////////////////////////////////////////////////////
135 /// \brief Activate of deactivate the render-texture for rendering
136 ///
137 /// This function makes the render-texture's context current for
138 /// future OpenGL rendering operations (so you shouldn't care
139 /// about it if you're not doing direct OpenGL stuff).
140 /// Only one context can be current in a thread, so if you
141 /// want to draw OpenGL geometry to another render target
142 /// (like a RenderWindow) don't forget to activate it again.
143 ///
144 /// \param active True to activate, false to deactivate
145 ///
146 /// \return True if operation was successful, false otherwise
147 ///
148 ////////////////////////////////////////////////////////////
149 bool setActive(bool active = true);
150
151 ////////////////////////////////////////////////////////////
152 /// \brief Update the contents of the target texture
153 ///
154 /// This function updates the target texture with what
155 /// has been drawn so far. Like for windows, calling this
156 /// function is mandatory at the end of rendering. Not calling
157 /// it may leave the texture in an undefined state.
158 ///
159 ////////////////////////////////////////////////////////////
160 void display();
161
162 ////////////////////////////////////////////////////////////
163 /// \brief Return the size of the rendering region of the texture
164 ///
165 /// The returned value is the size that you passed to
166 /// the create function.
167 ///
168 /// \return Size in pixels
169 ///
170 ////////////////////////////////////////////////////////////
171 virtual Vector2u getSize() const;
172
173 ////////////////////////////////////////////////////////////
174 /// \brief Get a read-only reference to the target texture
175 ///
176 /// After drawing to the render-texture and calling Display,
177 /// you can retrieve the updated texture using this function,
178 /// and draw it using a sprite (for example).
179 /// The internal sf::Texture of a render-texture is always the
180 /// same instance, so that it is possible to call this function
181 /// once and keep a reference to the texture even after it is
182 /// modified.
183 ///
184 /// \return Const reference to the texture
185 ///
186 ////////////////////////////////////////////////////////////
187 const Texture& getTexture() const;
188
189 private :
190
191 ////////////////////////////////////////////////////////////
192 /// \brief Activate the target for rendering
193 ///
194 /// This function is called by the base class
195 /// everytime it's going to use OpenGL calls.
196 ///
197 /// \param active True to make the target active, false to deactivate it
198 ///
199 /// \return True if the function succeeded
200 ///
201 ////////////////////////////////////////////////////////////
202 virtual bool activate(bool active);
203
204 ////////////////////////////////////////////////////////////
205 // Member data
206 ////////////////////////////////////////////////////////////
207 priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
208 Texture m_texture; ///< Target texture to draw on
209 };
210
211 } // namespace sf
212
213
214 #endif // SFML_RENDERTEXTURE_HPP
215
216
217 ////////////////////////////////////////////////////////////
218 /// \class sf::RenderTexture
219 /// \ingroup graphics
220 ///
221 /// sf::RenderTexture is the little brother of sf::RenderWindow.
222 /// It implements the same 2D drawing and OpenGL-related functions
223 /// (see their base class sf::RenderTarget for more details),
224 /// the difference is that the result is stored in an off-screen
225 /// texture rather than being show in a window.
226 ///
227 /// Rendering to a texture can be useful in a variety of situations:
228 /// \li precomputing a complex static texture (like a level's background from multiple tiles)
229 /// \li applying post-effects to the whole scene with shaders
230 /// \li creating a sprite from a 3D object rendered with OpenGL
231 /// \li etc.
232 ///
233 /// Usage example:
234 ///
235 /// \code
236 /// // Create a new render-window
237 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
238 ///
239 /// // Create a new render-texture
240 /// sf::RenderTexture texture;
241 /// if (!texture.create(500, 500))
242 /// return -1;
243 ///
244 /// // The main loop
245 /// while (window.isOpen())
246 /// {
247 /// // Event processing
248 /// // ...
249 ///
250 /// // Clear the whole texture with red color
251 /// texture.clear(sf::Color::Red);
252 ///
253 /// // Draw stuff to the texture
254 /// texture.draw(sprite); // sprite is a sf::Sprite
255 /// texture.draw(shape); // shape is a sf::Shape
256 /// texture.draw(text); // text is a sf::Text
257 ///
258 /// // We're done drawing to the texture
259 /// texture.display();
260 ///
261 /// // Now we start rendering to the window, clear it first
262 /// window.clear();
263 ///
264 /// // Draw the texture
265 /// sf::Sprite sprite(texture.getTexture());
266 /// window.draw(sprite);
267 ///
268 /// // End the current frame and display its contents on screen
269 /// window.display();
270 /// }
271 /// \endcode
272 ///
273 /// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
274 /// OpenGL stuff. It is even possible to mix together OpenGL calls
275 /// and regular SFML drawing commands. If you need a depth buffer for
276 /// 3D rendering, don't forget to request it when calling RenderTexture::create.
277 ///
278 /// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
279 ///
280 ////////////////////////////////////////////////////////////