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

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

View File

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