Fixed bug with texture coordinates in RenderImage after the sf::Rect modification

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1508 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-04-10 12:05:53 +00:00
parent 1e6161c750
commit 4c2899876e
2 changed files with 16 additions and 14 deletions

View File

@ -572,10 +572,10 @@ FloatRect Image::GetTexCoords(const IntRect& rect) const
if (myPixelsFlipped)
{
return FloatRect(rect.Left / width,
rect.Height / height,
rect.Width / width,
rect.Top / height);
return FloatRect( rect.Left / width,
(rect.Top + rect.Height) / height,
rect.Width / width,
-rect.Height / height);
}
else
{

View File

@ -188,23 +188,25 @@ void Sprite::Render(RenderTarget&, Renderer& renderer) const
// Check if the image is valid, and calculate the texture coordinates
FloatRect coords;
if (myImage)
{
coords = myImage->GetTexCoords(mySubRect);
if (myIsFlippedX) coords.Width = -coords.Width;
if (myIsFlippedY) coords.Height = -coords.Height;
}
// Compute the texture coordinates
float left = coords.Left;
float top = coords.Top;
float right = coords.Left + coords.Width;
float bottom = coords.Top + coords.Height;
if (myIsFlippedX) std::swap(left, right);
if (myIsFlippedY) std::swap(top, bottom);
// Bind the texture
renderer.SetTexture(myImage);
// Draw the sprite's geometry
float right = coords.Left + coords.Width;
float bottom = coords.Top + coords.Height;
renderer.Begin(Renderer::TriangleStrip);
renderer.AddVertex(0, 0, coords.Left, coords.Top);
renderer.AddVertex(width, 0, right, coords.Top);
renderer.AddVertex(0, height, coords.Left, bottom);
renderer.AddVertex(width, height, right, bottom);
renderer.AddVertex(0, 0, left, top);
renderer.AddVertex(width, 0, right, top);
renderer.AddVertex(0, height, left, bottom);
renderer.AddVertex(width, height, right, bottom);
renderer.End();
}