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:
parent
47d019098c
commit
504804a06e
@ -28,7 +28,6 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
|
||||
@ -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 :
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/Renderer.hpp>
|
||||
@ -42,7 +43,7 @@ class Shader;
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Base class for all render targets (window, image, ...)
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API RenderTarget
|
||||
class SFML_API RenderTarget : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
|
@ -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
|
||||
|
@ -29,6 +29,10 @@
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#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<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 + height * (1.f - viewport.Top)));
|
||||
static_cast<int>(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<int>(x) - viewport.Left) / viewport.GetSize().x;
|
||||
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.Top) / viewport.GetSize().y;
|
||||
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.Top) / viewport.GetSize().y;
|
||||
|
||||
// Then transform by the inverse of the view matrix
|
||||
return view.GetInverseMatrix().Transform(coords);
|
||||
|
@ -26,6 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Renderer.hpp>
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
#include <SFML/Graphics/GLCheck.hpp>
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user