From 504804a06eb1b6fc5461006493cc3ec221cd36bc Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 17 Feb 2010 17:17:20 +0000 Subject: [PATCH] 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 --- include/SFML/Graphics/RenderImage.hpp | 3 +-- include/SFML/Graphics/RenderTarget.hpp | 3 ++- include/SFML/Graphics/Renderer.hpp | 7 +++++-- src/SFML/Graphics/RenderTarget.cpp | 11 ++++++++--- src/SFML/Graphics/Renderer.cpp | 8 +++++--- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/SFML/Graphics/RenderImage.hpp b/include/SFML/Graphics/RenderImage.hpp index 344df174..1224c7a0 100644 --- a/include/SFML/Graphics/RenderImage.hpp +++ b/include/SFML/Graphics/RenderImage.hpp @@ -28,7 +28,6 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include #include #include @@ -44,7 +43,7 @@ namespace priv /// Target for 2D rendering into an image that can be reused /// in a sprite //////////////////////////////////////////////////////////// -class SFML_API RenderImage : public RenderTarget, NonCopyable +class SFML_API RenderImage : public RenderTarget { public : diff --git a/include/SFML/Graphics/RenderTarget.hpp b/include/SFML/Graphics/RenderTarget.hpp index bb938629..9c6092af 100644 --- a/include/SFML/Graphics/RenderTarget.hpp +++ b/include/SFML/Graphics/RenderTarget.hpp @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include #include #include #include @@ -42,7 +43,7 @@ class Shader; //////////////////////////////////////////////////////////// /// Base class for all render targets (window, image, ...) //////////////////////////////////////////////////////////// -class SFML_API RenderTarget +class SFML_API RenderTarget : NonCopyable { public : diff --git a/include/SFML/Graphics/Renderer.hpp b/include/SFML/Graphics/Renderer.hpp index b703fe99..2e3cb858 100644 --- a/include/SFML/Graphics/Renderer.hpp +++ b/include/SFML/Graphics/Renderer.hpp @@ -63,10 +63,12 @@ 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 @@ -347,6 +349,7 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// + RenderTarget& myTarget; ///< Reference to the render target owning this renderer States myStatesStack[64]; ///< Stack of render states States* myStates; ///< Current set of render states const Image* myTexture; ///< Current texture diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 041625b1..17404232 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -29,6 +29,10 @@ #include #include +#ifdef _MSC_VER + #pragma warning(disable : 4355) // "'this' : used in base member initializer list" +#endif + namespace sf { @@ -36,6 +40,7 @@ namespace sf /// Default constructor //////////////////////////////////////////////////////////// RenderTarget::RenderTarget() : +myRenderer (*this), myStatesSaved (false), myViewHasChanged(false) { @@ -165,9 +170,9 @@ IntRect RenderTarget::GetViewport(const View& view) const const FloatRect& viewport = view.GetViewport(); return IntRect(static_cast(0.5f + width * viewport.Left), - static_cast(0.5f + height * (1.f - viewport.Bottom)), + static_cast(0.5f + height * viewport.Top), static_cast(0.5f + width * viewport.Right), - static_cast(0.5f + height * (1.f - viewport.Top))); + static_cast(0.5f + height * viewport.Bottom)); } @@ -191,7 +196,7 @@ Vector2f RenderTarget::ConvertCoords(unsigned int x, unsigned int y, const View& Vector2f coords; IntRect viewport = GetViewport(view); coords.x = -1.f + 2.f * (static_cast(x) - viewport.Left) / viewport.GetSize().x; - coords.y = 1.f - 2.f * (static_cast(y) - viewport.Top) / viewport.GetSize().y; + coords.y = 1.f - 2.f * (static_cast(y) - viewport.Top) / viewport.GetSize().y; // Then transform by the inverse of the view matrix return view.GetInverseMatrix().Transform(coords); diff --git a/src/SFML/Graphics/Renderer.cpp b/src/SFML/Graphics/Renderer.cpp index b82fd793..45292331 100644 --- a/src/SFML/Graphics/Renderer.cpp +++ b/src/SFML/Graphics/Renderer.cpp @@ -26,6 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -34,7 +35,8 @@ namespace sf { //////////////////////////////////////////////////////////// -Renderer::Renderer() : +Renderer::Renderer(RenderTarget& target) : +myTarget (target), myTextureIsValid (false), myShaderIsValid (false), myBlendModeIsValid(false), @@ -174,8 +176,8 @@ void Renderer::SetViewport(const IntRect& viewport) (viewport.Top != myViewport.Top) || (viewport.Bottom != myViewport.Bottom) || !myViewportIsValid) { - // Apply the new viewport - GLCheck(glViewport(viewport.Left, viewport.Top, viewport.GetSize().x, viewport.GetSize().y)); + // Apply the new viewport -- revert Y axis to match the OpenGL convention + GLCheck(glViewport(viewport.Left, myTarget.GetHeight() - viewport.Bottom, viewport.GetSize().x, viewport.GetSize().y)); // Store it myViewport = viewport;