|
|
|||
File indexing completed on 2026-06-02 08:58:14
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_RENDERWINDOW_HPP 0026 #define SFML_RENDERWINDOW_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Graphics/Export.hpp> 0032 #include <SFML/Graphics/RenderTarget.hpp> 0033 #include <SFML/Graphics/Image.hpp> 0034 #include <SFML/Window/Window.hpp> 0035 #include <string> 0036 0037 0038 namespace sf 0039 { 0040 //////////////////////////////////////////////////////////// 0041 /// \brief Window that can serve as a target for 2D drawing 0042 /// 0043 //////////////////////////////////////////////////////////// 0044 class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget 0045 { 0046 public: 0047 0048 //////////////////////////////////////////////////////////// 0049 /// \brief Default constructor 0050 /// 0051 /// This constructor doesn't actually create the window, 0052 /// use the other constructors or call create() to do so. 0053 /// 0054 //////////////////////////////////////////////////////////// 0055 RenderWindow(); 0056 0057 //////////////////////////////////////////////////////////// 0058 /// \brief Construct a new window 0059 /// 0060 /// This constructor creates the window with the size and pixel 0061 /// depth defined in \a mode. An optional style can be passed to 0062 /// customize the look and behavior of the window (borders, 0063 /// title bar, resizable, closable, ...). 0064 /// 0065 /// The fourth parameter is an optional structure specifying 0066 /// advanced OpenGL context settings such as antialiasing, 0067 /// depth-buffer bits, etc. You shouldn't care about these 0068 /// parameters for a regular usage of the graphics module. 0069 /// 0070 /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) 0071 /// \param title Title of the window 0072 /// \param style %Window style, a bitwise OR combination of sf::Style enumerators 0073 /// \param settings Additional settings for the underlying OpenGL context 0074 /// 0075 //////////////////////////////////////////////////////////// 0076 RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings()); 0077 0078 //////////////////////////////////////////////////////////// 0079 /// \brief Construct the window from an existing control 0080 /// 0081 /// Use this constructor if you want to create an SFML 0082 /// rendering area into an already existing control. 0083 /// 0084 /// The second parameter is an optional structure specifying 0085 /// advanced OpenGL context settings such as antialiasing, 0086 /// depth-buffer bits, etc. You shouldn't care about these 0087 /// parameters for a regular usage of the graphics module. 0088 /// 0089 /// \param handle Platform-specific handle of the control (\a HWND on 0090 /// Windows, \a %Window on Linux/FreeBSD, \a NSWindow on OS X) 0091 /// \param settings Additional settings for the underlying OpenGL context 0092 /// 0093 //////////////////////////////////////////////////////////// 0094 explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings()); 0095 0096 //////////////////////////////////////////////////////////// 0097 /// \brief Destructor 0098 /// 0099 /// Closes the window and frees all the resources attached to it. 0100 /// 0101 //////////////////////////////////////////////////////////// 0102 virtual ~RenderWindow(); 0103 0104 //////////////////////////////////////////////////////////// 0105 /// \brief Get the size of the rendering region of the window 0106 /// 0107 /// The size doesn't include the titlebar and borders 0108 /// of the window. 0109 /// 0110 /// \return Size in pixels 0111 /// 0112 //////////////////////////////////////////////////////////// 0113 virtual Vector2u getSize() const; 0114 0115 0116 //////////////////////////////////////////////////////////// 0117 /// \brief Tell if the window will use sRGB encoding when drawing on it 0118 /// 0119 /// You can request sRGB encoding for a window by having the sRgbCapable flag set in the ContextSettings 0120 /// 0121 /// \return True if the window use sRGB encoding, false otherwise 0122 /// 0123 //////////////////////////////////////////////////////////// 0124 virtual bool isSrgb() const; 0125 0126 //////////////////////////////////////////////////////////// 0127 /// \brief Activate or deactivate the window as the current target 0128 /// for OpenGL rendering 0129 /// 0130 /// A window is active only on the current thread, if you want to 0131 /// make it active on another thread you have to deactivate it 0132 /// on the previous thread first if it was active. 0133 /// Only one window can be active on a thread at a time, thus 0134 /// the window previously active (if any) automatically gets deactivated. 0135 /// This is not to be confused with requestFocus(). 0136 /// 0137 /// \param active True to activate, false to deactivate 0138 /// 0139 /// \return True if operation was successful, false otherwise 0140 /// 0141 //////////////////////////////////////////////////////////// 0142 bool setActive(bool active = true); 0143 0144 //////////////////////////////////////////////////////////// 0145 /// \brief Copy the current contents of the window to an image 0146 /// 0147 /// \deprecated 0148 /// Use a sf::Texture and its sf::Texture::update(const Window&) 0149 /// function and copy its contents into an sf::Image instead. 0150 /// \code 0151 /// sf::Vector2u windowSize = window.getSize(); 0152 /// sf::Texture texture; 0153 /// texture.create(windowSize.x, windowSize.y); 0154 /// texture.update(window); 0155 /// sf::Image screenshot = texture.copyToImage(); 0156 /// \endcode 0157 /// 0158 /// This is a slow operation, whose main purpose is to make 0159 /// screenshots of the application. If you want to update an 0160 /// image with the contents of the window and then use it for 0161 /// drawing, you should rather use a sf::Texture and its 0162 /// update(Window&) function. 0163 /// You can also draw things directly to a texture with the 0164 /// sf::RenderTexture class. 0165 /// 0166 /// \return Image containing the captured contents 0167 /// 0168 //////////////////////////////////////////////////////////// 0169 SFML_DEPRECATED Image capture() const; 0170 0171 protected: 0172 0173 //////////////////////////////////////////////////////////// 0174 /// \brief Function called after the window has been created 0175 /// 0176 /// This function is called so that derived classes can 0177 /// perform their own specific initialization as soon as 0178 /// the window is created. 0179 /// 0180 //////////////////////////////////////////////////////////// 0181 virtual void onCreate(); 0182 0183 //////////////////////////////////////////////////////////// 0184 /// \brief Function called after the window has been resized 0185 /// 0186 /// This function is called so that derived classes can 0187 /// perform custom actions when the size of the window changes. 0188 /// 0189 //////////////////////////////////////////////////////////// 0190 virtual void onResize(); 0191 0192 private: 0193 0194 //////////////////////////////////////////////////////////// 0195 // Member data 0196 //////////////////////////////////////////////////////////// 0197 unsigned int m_defaultFrameBuffer; //!< Framebuffer to bind when targeting this window 0198 }; 0199 0200 } // namespace sf 0201 0202 0203 #endif // SFML_RENDERWINDOW_HPP 0204 0205 0206 //////////////////////////////////////////////////////////// 0207 /// \class sf::RenderWindow 0208 /// \ingroup graphics 0209 /// 0210 /// sf::RenderWindow is the main class of the Graphics module. 0211 /// It defines an OS window that can be painted using the other 0212 /// classes of the graphics module. 0213 /// 0214 /// sf::RenderWindow is derived from sf::Window, thus it inherits 0215 /// all its features: events, window management, OpenGL rendering, 0216 /// etc. See the documentation of sf::Window for a more complete 0217 /// description of all these features, as well as code examples. 0218 /// 0219 /// On top of that, sf::RenderWindow adds more features related to 0220 /// 2D drawing with the graphics module (see its base class 0221 /// sf::RenderTarget for more details). 0222 /// Here is a typical rendering and event loop with a sf::RenderWindow: 0223 /// 0224 /// \code 0225 /// // Declare and create a new render-window 0226 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window"); 0227 /// 0228 /// // Limit the framerate to 60 frames per second (this step is optional) 0229 /// window.setFramerateLimit(60); 0230 /// 0231 /// // The main loop - ends as soon as the window is closed 0232 /// while (window.isOpen()) 0233 /// { 0234 /// // Event processing 0235 /// sf::Event event; 0236 /// while (window.pollEvent(event)) 0237 /// { 0238 /// // Request for closing the window 0239 /// if (event.type == sf::Event::Closed) 0240 /// window.close(); 0241 /// } 0242 /// 0243 /// // Clear the whole window before rendering a new frame 0244 /// window.clear(); 0245 /// 0246 /// // Draw some graphical entities 0247 /// window.draw(sprite); 0248 /// window.draw(circle); 0249 /// window.draw(text); 0250 /// 0251 /// // End the current frame and display its contents on screen 0252 /// window.display(); 0253 /// } 0254 /// \endcode 0255 /// 0256 /// Like sf::Window, sf::RenderWindow is still able to render direct 0257 /// OpenGL stuff. It is even possible to mix together OpenGL calls 0258 /// and regular SFML drawing commands. 0259 /// 0260 /// \code 0261 /// // Create the render window 0262 /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL"); 0263 /// 0264 /// // Create a sprite and a text to display 0265 /// sf::Sprite sprite; 0266 /// sf::Text text; 0267 /// ... 0268 /// 0269 /// // Perform OpenGL initializations 0270 /// glMatrixMode(GL_PROJECTION); 0271 /// ... 0272 /// 0273 /// // Start the rendering loop 0274 /// while (window.isOpen()) 0275 /// { 0276 /// // Process events 0277 /// ... 0278 /// 0279 /// // Draw a background sprite 0280 /// window.pushGLStates(); 0281 /// window.draw(sprite); 0282 /// window.popGLStates(); 0283 /// 0284 /// // Draw a 3D object using OpenGL 0285 /// glBegin(GL_QUADS); 0286 /// glVertex3f(...); 0287 /// ... 0288 /// glEnd(); 0289 /// 0290 /// // Draw text on top of the 3D object 0291 /// window.pushGLStates(); 0292 /// window.draw(text); 0293 /// window.popGLStates(); 0294 /// 0295 /// // Finally, display the rendered frame on screen 0296 /// window.display(); 0297 /// } 0298 /// \endcode 0299 /// 0300 /// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View 0301 /// 0302 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|