Fixed RenderTarget::ConvertCoords returning wrong Y coordinates

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1410 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-02-17 17:17:20 +00:00
parent 47d019098c
commit 504804a06e
5 changed files with 21 additions and 11 deletions

View File

@ -28,7 +28,6 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/NonCopyable.hpp>
#include <SFML/Graphics/Image.hpp> #include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderTarget.hpp> #include <SFML/Graphics/RenderTarget.hpp>
@ -44,7 +43,7 @@ namespace priv
/// Target for 2D rendering into an image that can be reused /// Target for 2D rendering into an image that can be reused
/// in a sprite /// in a sprite
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class SFML_API RenderImage : public RenderTarget, NonCopyable class SFML_API RenderImage : public RenderTarget
{ {
public : public :

View File

@ -28,6 +28,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/NonCopyable.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Renderer.hpp> #include <SFML/Graphics/Renderer.hpp>
@ -42,7 +43,7 @@ class Shader;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Base class for all render targets (window, image, ...) /// Base class for all render targets (window, image, ...)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class SFML_API RenderTarget class SFML_API RenderTarget : NonCopyable
{ {
public : public :

View File

@ -63,10 +63,12 @@ public :
public : public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Default constructor /// \brief Construct the renderer with its owner render target
///
/// \param target Owner render target
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Renderer(); Renderer(RenderTarget& target);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor
@ -347,6 +349,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTarget& myTarget; ///< Reference to the render target owning this renderer
States myStatesStack[64]; ///< Stack of render states States myStatesStack[64]; ///< Stack of render states
States* myStates; ///< Current set of render states States* myStates; ///< Current set of render states
const Image* myTexture; ///< Current texture const Image* myTexture; ///< Current texture

View File

@ -29,6 +29,10 @@
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <iostream> #include <iostream>
#ifdef _MSC_VER
#pragma warning(disable : 4355) // "'this' : used in base member initializer list"
#endif
namespace sf namespace sf
{ {
@ -36,6 +40,7 @@ namespace sf
/// Default constructor /// Default constructor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTarget::RenderTarget() : RenderTarget::RenderTarget() :
myRenderer (*this),
myStatesSaved (false), myStatesSaved (false),
myViewHasChanged(false) myViewHasChanged(false)
{ {
@ -165,9 +170,9 @@ IntRect RenderTarget::GetViewport(const View& view) const
const FloatRect& viewport = view.GetViewport(); const FloatRect& viewport = view.GetViewport();
return IntRect(static_cast<int>(0.5f + width * viewport.Left), return IntRect(static_cast<int>(0.5f + width * viewport.Left),
static_cast<int>(0.5f + height * (1.f - viewport.Bottom)), static_cast<int>(0.5f + height * viewport.Top),
static_cast<int>(0.5f + width * viewport.Right), static_cast<int>(0.5f + width * viewport.Right),
static_cast<int>(0.5f + height * (1.f - viewport.Top))); static_cast<int>(0.5f + height * viewport.Bottom));
} }

View File

@ -26,6 +26,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Renderer.hpp> #include <SFML/Graphics/Renderer.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Image.hpp> #include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/Shader.hpp> #include <SFML/Graphics/Shader.hpp>
#include <SFML/Graphics/GLCheck.hpp> #include <SFML/Graphics/GLCheck.hpp>
@ -34,7 +35,8 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Renderer::Renderer() : Renderer::Renderer(RenderTarget& target) :
myTarget (target),
myTextureIsValid (false), myTextureIsValid (false),
myShaderIsValid (false), myShaderIsValid (false),
myBlendModeIsValid(false), myBlendModeIsValid(false),
@ -174,8 +176,8 @@ void Renderer::SetViewport(const IntRect& viewport)
(viewport.Top != myViewport.Top) || (viewport.Bottom != myViewport.Bottom) || (viewport.Top != myViewport.Top) || (viewport.Bottom != myViewport.Bottom) ||
!myViewportIsValid) !myViewportIsValid)
{ {
// Apply the new viewport // Apply the new viewport -- revert Y axis to match the OpenGL convention
GLCheck(glViewport(viewport.Left, viewport.Top, viewport.GetSize().x, viewport.GetSize().y)); GLCheck(glViewport(viewport.Left, myTarget.GetHeight() - viewport.Bottom, viewport.GetSize().x, viewport.GetSize().y));
// Store it // Store it
myViewport = viewport; myViewport = viewport;