1 ////////////////////////////////////////////////////////////
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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.
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:
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.
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
21 // 3. This notice may not be removed or altered from any source distribution.
23 ////////////////////////////////////////////////////////////
25 #ifndef SFML_RENDERWINDOW_HPP
26 #define SFML_RENDERWINDOW_HPP
28 ////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Graphics/Export.hpp>
32 #include <SFML/Graphics/RenderTarget.hpp>
33 #include <SFML/Graphics/Image.hpp>
34 #include <SFML/Window/Window.hpp>
40 ////////////////////////////////////////////////////////////
41 /// \brief Window that can serve as a target for 2D drawing
43 ////////////////////////////////////////////////////////////
44 class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
48 ////////////////////////////////////////////////////////////
49 /// \brief Default constructor
51 /// This constructor doesn't actually create the window,
52 /// use the other constructors or call "create" to do so.
54 ////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////
58 /// \brief Construct a new window
60 /// This constructor creates the window with the size and pixel
61 /// depth defined in \a mode. An optional style can be passed to
62 /// customize the look and behaviour of the window (borders,
63 /// title bar, resizable, closable, ...).
65 /// The fourth parameter is an optional structure specifying
66 /// advanced OpenGL context settings such as antialiasing,
67 /// depth-buffer bits, etc. You shouldn't care about these
68 /// parameters for a regular usage of the graphics module.
70 /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
71 /// \param title Title of the window
72 /// \param style Window style
73 /// \param settings Additional settings for the underlying OpenGL context
75 ////////////////////////////////////////////////////////////
76 RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
78 ////////////////////////////////////////////////////////////
79 /// \brief Construct the window from an existing control
81 /// Use this constructor if you want to create an SFML
82 /// rendering area into an already existing control.
84 /// The fourth parameter is an optional structure specifying
85 /// advanced OpenGL context settings such as antialiasing,
86 /// depth-buffer bits, etc. You shouldn't care about these
87 /// parameters for a regular usage of the graphics module.
89 /// \param handle Platform-specific handle of the control
90 /// \param settings Additional settings for the underlying OpenGL context
92 ////////////////////////////////////////////////////////////
93 explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
95 ////////////////////////////////////////////////////////////
98 /// Closes the window and free all the resources attached to it.
100 ////////////////////////////////////////////////////////////
101 virtual ~RenderWindow();
103 ////////////////////////////////////////////////////////////
104 /// \brief Get the size of the rendering region of the window
106 /// The size doesn't include the titlebar and borders
109 /// \return Size in pixels
111 ////////////////////////////////////////////////////////////
112 virtual Vector2u getSize() const;
114 ////////////////////////////////////////////////////////////
115 /// \brief Copy the current contents of the window to an image
117 /// This is a slow operation, whose main purpose is to make
118 /// screenshots of the application. If you want to update an
119 /// image with the contents of the window and then use it for
120 /// drawing, you should rather use a sf::Texture and its
121 /// update(Window&) function.
122 /// You can also draw things directly to a texture with the
123 /// sf::RenderTexture class.
125 /// \return Image containing the captured contents
127 ////////////////////////////////////////////////////////////
128 Image capture() const;
132 ////////////////////////////////////////////////////////////
133 /// \brief Function called after the window has been created
135 /// This function is called so that derived classes can
136 /// perform their own specific initialization as soon as
137 /// the window is created.
139 ////////////////////////////////////////////////////////////
140 virtual void onCreate();
142 ////////////////////////////////////////////////////////////
143 /// \brief Function called after the window has been resized
145 /// This function is called so that derived classes can
146 /// perform custom actions when the size of the window changes.
148 ////////////////////////////////////////////////////////////
149 virtual void onResize();
153 ////////////////////////////////////////////////////////////
154 /// \brief Activate the target for rendering
156 /// \param active True to make the target active, false to deactivate it
158 /// \return True if the function succeeded
160 ////////////////////////////////////////////////////////////
161 virtual bool activate(bool active);
167 #endif // SFML_RENDERWINDOW_HPP
170 ////////////////////////////////////////////////////////////
171 /// \class sf::RenderWindow
172 /// \ingroup graphics
174 /// sf::RenderWindow is the main class of the Graphics module.
175 /// It defines an OS window that can be painted using the other
176 /// classes of the graphics module.
178 /// sf::RenderWindow is derived from sf::Window, thus it inherits
179 /// all its features: events, window management, OpenGL rendering,
180 /// etc. See the documentation of sf::Window for a more complete
181 /// description of all these features, as well as code examples.
183 /// On top of that, sf::RenderWindow adds more features related to
184 /// 2D drawing with the graphics module (see its base class
185 /// sf::RenderTarget for more details).
186 /// Here is a typical rendering and event loop with a sf::RenderWindow:
189 /// // Declare and create a new render-window
190 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
192 /// // Limit the framerate to 60 frames per second (this step is optional)
193 /// window.setFramerateLimit(60);
195 /// // The main loop - ends as soon as the window is closed
196 /// while (window.isOpen())
198 /// // Event processing
200 /// while (window.pollEvent(event))
202 /// // Request for closing the window
203 /// if (event.type == sf::Event::Closed)
207 /// // Clear the whole window before rendering a new frame
210 /// // Draw some graphical entities
211 /// window.draw(sprite);
212 /// window.draw(circle);
213 /// window.draw(text);
215 /// // End the current frame and display its contents on screen
216 /// window.display();
220 /// Like sf::Window, sf::RenderWindow is still able to render direct
221 /// OpenGL stuff. It is even possible to mix together OpenGL calls
222 /// and regular SFML drawing commands.
225 /// // Create the render window
226 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
228 /// // Create a sprite and a text to display
229 /// sf::Sprite sprite;
233 /// // Perform OpenGL initializations
234 /// glMatrixMode(GL_PROJECTION);
237 /// // Start the rendering loop
238 /// while (window.isOpen())
240 /// // Process events
243 /// // Draw a background sprite
244 /// window.pushGLStates();
245 /// window.draw(sprite);
246 /// window.popGLStates();
248 /// // Draw a 3D object using OpenGL
249 /// glBegin(GL_QUADS);
254 /// // Draw text on top of the 3D object
255 /// window.pushGLStates();
256 /// window.draw(text);
257 /// window.popGLStates();
259 /// // Finally, display the rendered frame on screen
260 /// window.display();
264 /// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
266 ////////////////////////////////////////////////////////////