2009-01-28 16:18:34 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SFML - Simple and Fast Multimedia Library
|
2009-02-12 17:48:35 +00:00
|
|
|
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
2009-01-28 16:18:34 +00:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
// subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented;
|
|
|
|
// you must not claim that you wrote the original software.
|
|
|
|
// If you use this software in a product, an acknowledgment
|
|
|
|
// in the product documentation would be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such,
|
|
|
|
// and must not be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef SFML_RENDERTARGET_HPP
|
|
|
|
#define SFML_RENDERTARGET_HPP
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Headers
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-17 17:17:20 +00:00
|
|
|
#include <SFML/System/NonCopyable.hpp>
|
2009-01-28 16:18:34 +00:00
|
|
|
#include <SFML/Graphics/Color.hpp>
|
|
|
|
#include <SFML/Graphics/Rect.hpp>
|
2010-01-19 20:39:32 +00:00
|
|
|
#include <SFML/Graphics/Renderer.hpp>
|
2009-09-24 07:50:08 +00:00
|
|
|
#include <SFML/Graphics/View.hpp>
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace sf
|
|
|
|
{
|
|
|
|
class Drawable;
|
2009-11-03 09:04:40 +00:00
|
|
|
class Shader;
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Base class for all render targets (window, image, ...)
|
|
|
|
///
|
2009-01-28 16:18:34 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-17 17:17:20 +00:00
|
|
|
class SFML_API RenderTarget : NonCopyable
|
2009-01-28 16:18:34 +00:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Destructor
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual ~RenderTarget();
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Clear the entire target with a single color
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// This function is usually called once every frame,
|
|
|
|
/// to clear the previous contents of the target.
|
|
|
|
///
|
|
|
|
/// \param color Fill color to use to clear the render target
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-07-11 22:17:24 +00:00
|
|
|
void Clear(const Color& color = Color(0, 0, 0));
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Draw an object into the target
|
|
|
|
///
|
|
|
|
/// This function draws anything that inherits from the
|
|
|
|
/// sf::Drawable base class (sf::Sprite, sf::Shape, sf::Text,
|
|
|
|
/// or even your own derived classes).
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \param object Object to draw
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-11-03 09:04:40 +00:00
|
|
|
void Draw(const Drawable& object);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Draw an object into the target with a shader
|
2009-11-03 09:04:40 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// This function draws anything that inherits from the
|
|
|
|
/// sf::Drawable base class (sf::Sprite, sf::Shape, sf::Text,
|
|
|
|
/// or even your own derived classes).
|
|
|
|
/// The shader alters the way that the pixels are processed
|
|
|
|
/// right before being written to the render target.
|
|
|
|
///
|
|
|
|
/// \param object Object to draw
|
|
|
|
/// \param shader Shader to use for drawing the object
|
2009-11-03 09:04:40 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
void Draw(const Drawable& object, const Shader& shader);
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Return the width of the rendering region of the target
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
/// \return Width in pixels
|
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \see GetHeight
|
|
|
|
///
|
2009-01-28 16:18:34 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual unsigned int GetWidth() const = 0;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Return the height of the rendering region of the target
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
/// \return Height in pixels
|
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \see GetWidth
|
|
|
|
///
|
2009-01-28 16:18:34 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
virtual unsigned int GetHeight() const = 0;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Change the current active view
|
|
|
|
///
|
|
|
|
/// The new view will affect everything that is drawn, until
|
|
|
|
/// another view is activated.
|
|
|
|
/// The render target keeps its own copy of the view object,
|
|
|
|
/// so it is not necessary to keep the original one alive
|
|
|
|
/// as long as it is in use.
|
|
|
|
/// To restore the original view of the target, you can pass
|
|
|
|
/// the result of GetDefaultView() to this function.
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \param view New view to use
|
|
|
|
///
|
|
|
|
/// \see GetView, GetDefaultView
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-07-11 22:17:24 +00:00
|
|
|
void SetView(const View& view);
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Retrieve the view currently in use in the render target
|
|
|
|
///
|
|
|
|
/// \return The view object that is currently used
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \see SetView, GetDefaultView
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
const View& GetView() const;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Get the default view of the render target
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// The default view has the initial size of the render target,
|
|
|
|
/// and never changes after the target has been created.
|
|
|
|
///
|
|
|
|
/// \return The default view of the render target
|
|
|
|
///
|
|
|
|
/// \see SetView, GetView
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-12-31 16:43:24 +00:00
|
|
|
const View& GetDefaultView() const;
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Get the viewport of a view, applied to this render target
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// The viewport is defined in the view as a ratio, this function
|
|
|
|
/// simply applies this ratio to the current dimensions of the
|
|
|
|
/// render target to calculate the pixels rectangle that the viewport
|
|
|
|
/// actually covers in the target.
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \param view The view for which we want to compute the viewport
|
|
|
|
///
|
|
|
|
/// \return Viewport rectangle, expressed in pixels
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-09-24 07:50:08 +00:00
|
|
|
IntRect GetViewport(const View& view) const;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Convert a point from target coordinates to view coordinates
|
|
|
|
///
|
|
|
|
/// Initially, a unit of the 2D world matches a pixel of the
|
|
|
|
/// render target. But if you define a custom view, this
|
|
|
|
/// assertion is not true anymore, ie. a point located at
|
|
|
|
/// (10, 50) in your render target (for example a window) may
|
|
|
|
/// map to the point (150, 75) in your 2D world -- for example
|
|
|
|
/// if the view is translated by (140, 25).
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// For render windows, this function is typically used to find
|
|
|
|
/// which point (or object) is located below the mouse cursor.
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// This version uses the current view of the render target.
|
|
|
|
/// See the other overload to specify a custom view.
|
|
|
|
///
|
|
|
|
/// \param x X coordinate of the point to convert, relative to the render target
|
|
|
|
/// \param y Y coordinate of the point to convert, relative to the render target
|
|
|
|
///
|
|
|
|
/// \return The converted point, in "world" units
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-10 11:09:55 +00:00
|
|
|
Vector2f ConvertCoords(unsigned int x, unsigned int y) const;
|
2009-09-24 07:50:08 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Convert a point from target coordinates to view coordinates
|
|
|
|
///
|
|
|
|
/// Initially, a unit of the 2D world matches a pixel of the
|
|
|
|
/// render target. But if you define a custom view, this
|
|
|
|
/// assertion is not true anymore, ie. a point located at
|
|
|
|
/// (10, 50) in your render target (for example a window) may
|
|
|
|
/// map to the point (150, 75) in your 2D world -- for example
|
|
|
|
/// if the view is translated by (140, 25).
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// For render windows, this function is typically used to find
|
|
|
|
/// which point (or object) is located below the mouse cursor.
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// This version uses a custom view for calculations, see the other
|
|
|
|
/// overload of the function to use the current view of the render
|
|
|
|
/// target.
|
|
|
|
///
|
|
|
|
/// \param x X coordinate of the point to convert, relative to the render target
|
|
|
|
/// \param y Y coordinate of the point to convert, relative to the render target
|
|
|
|
/// \param view The view to use for converting the point
|
|
|
|
///
|
|
|
|
/// \return The converted point, in "world" units
|
2009-09-24 07:50:08 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-10 11:09:55 +00:00
|
|
|
Vector2f ConvertCoords(unsigned int x, unsigned int y, const View& view) const;
|
2009-01-28 16:18:34 +00:00
|
|
|
|
2010-01-19 20:39:32 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Save the current OpenGL render states and matrices
|
|
|
|
///
|
|
|
|
/// This function can be used when you mix SFML drawing
|
|
|
|
/// and direct OpenGL rendering. Combined with RestoreGLStates,
|
|
|
|
/// it ensures that:
|
|
|
|
/// \li SFML's internal states are not messed up by your OpenGL code
|
|
|
|
/// \li your OpenGL states are not modified by a call to a SFML function
|
|
|
|
///
|
|
|
|
/// More specifically, it must be used around code that
|
|
|
|
/// calls Draw functions. Example:
|
2010-05-13 11:00:29 +00:00
|
|
|
/// \code
|
2010-02-19 14:34:34 +00:00
|
|
|
/// // OpenGL code here...
|
|
|
|
/// window.SaveGLStates();
|
|
|
|
/// window.Draw(...);
|
|
|
|
/// window.Draw(...);
|
|
|
|
/// window.RestoreGLStates();
|
|
|
|
/// // OpenGL code here...
|
|
|
|
/// \endcode
|
|
|
|
///
|
|
|
|
/// Note that this function is quite expensive and should be
|
|
|
|
/// used wisely. It is provided for convenience, and the best
|
|
|
|
/// results will be achieved if you handle OpenGL states
|
|
|
|
/// yourself (because you really know which states have really
|
|
|
|
/// changed, and need to be saved / restored).
|
|
|
|
///
|
|
|
|
/// \see RestoreGLStates
|
2010-01-19 20:39:32 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
void SaveGLStates();
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Restore the previously saved OpenGL render states and matrices
|
|
|
|
///
|
|
|
|
/// See the description of SaveGLStates to get a detailed
|
|
|
|
/// description of these functions.
|
|
|
|
///
|
|
|
|
/// \see SaveGLStates
|
2010-01-19 20:39:32 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
void RestoreGLStates();
|
|
|
|
|
2009-01-28 16:18:34 +00:00
|
|
|
protected :
|
|
|
|
|
2010-01-19 20:39:32 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Default constructor
|
2010-01-19 20:39:32 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
RenderTarget();
|
|
|
|
|
2009-01-28 16:18:34 +00:00
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Performs the common initialization step after creation
|
|
|
|
///
|
|
|
|
/// The derived classes must call this function after the
|
|
|
|
/// target is created and ready for drawing.
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
void Initialize();
|
|
|
|
|
|
|
|
private :
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \brief Activate the target for rendering
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// This function must be implemented by derived classes to make
|
|
|
|
/// their OpenGL context current; it is called by the base class
|
|
|
|
/// everytime it's going to use OpenGL calls.
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
2010-02-19 14:34:34 +00:00
|
|
|
/// \param active True to make the target active, false to deactivate it
|
|
|
|
///
|
|
|
|
/// \return True if the function succeeded
|
2009-01-28 16:18:34 +00:00
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|
2009-07-11 22:17:24 +00:00
|
|
|
virtual bool Activate(bool active) = 0;
|
2009-01-28 16:18:34 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Member data
|
|
|
|
////////////////////////////////////////////////////////////
|
2010-01-19 20:39:32 +00:00
|
|
|
Renderer myRenderer; ///< Renderer that will process the rendering commands of the window
|
|
|
|
View myDefaultView; ///< Default view
|
|
|
|
View myCurrentView; ///< Current active view
|
|
|
|
bool myStatesSaved; ///< Are we between a SaveGLStates and a RestoreGLStates?
|
|
|
|
bool myViewHasChanged; ///< Has the current view changed?
|
2009-01-28 16:18:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sf
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SFML_RENDERTARGET_HPP
|
2010-02-19 14:34:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
/// \class sf::RenderTarget
|
|
|
|
///
|
|
|
|
/// sf::RenderTarget defines the common behaviour of all the
|
|
|
|
/// 2D render targets usable in the graphics module. It makes
|
|
|
|
/// it possible to draw 2D entities like sprites, shapes, text
|
|
|
|
/// without using any OpenGL command directly.
|
|
|
|
///
|
|
|
|
/// A sf::RenderTarget is also able to use views (sf::View),
|
|
|
|
/// which are a kind of 2D cameras. With views you can globally
|
|
|
|
/// scroll, rotate or zoom everything that is drawn,
|
|
|
|
/// without having to transform every single entity. See the
|
|
|
|
/// documentation of sf::View for more details and sample pieces of
|
|
|
|
/// code about this class.
|
|
|
|
///
|
|
|
|
/// On top of that, render targets are still able to render direct
|
|
|
|
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
|
|
|
/// and regular SFML drawing commands. When doing so, make sure that
|
|
|
|
/// OpenGL states are not messed up by calling the SaveGLStates /
|
|
|
|
/// RestoreGLStates functions.
|
|
|
|
///
|
|
|
|
/// \see sf::RenderWindow, sf::RenderImage, sf::View
|
|
|
|
///
|
|
|
|
////////////////////////////////////////////////////////////
|