Skip to content

Commit

Permalink
Merge pull request #3785 from tgjones/spritebatch-layerdepth
Browse files Browse the repository at this point in the history
Fix bug using SpriteBatch layerDepth on OpenGL
  • Loading branch information
tomspilman committed Apr 29, 2015
2 parents 2cb7992 + 5a53c87 commit 9d677e4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Build/Projects/MonoGame.Tests.definition
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@
</Content>
<Content Include="Assets\ReferenceImages\SpriteBatch\Draw_with_SpriteSortMode_Texture_.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\ReferenceImages\SpriteBatch\DrawWithLayerDepth.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\ReferenceImages\SpriteFont\Draw_with_SpriteEffects_FlipHorizontally_ FlipVertically_.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
4 changes: 1 addition & 3 deletions MonoGame.Framework/Graphics/SpriteBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ void Setup()
var vp = gd.Viewport;

Matrix projection;
#if PSM || DIRECTX
Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, -1, 0, out projection);
#else
#if !PSM && !DIRECTX
// GL requires a half pixel offset to match DX.
Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, 0, 1, out projection);
projection.M41 += -0.5f * projection.M11;
projection.M42 += -0.5f * projection.M22;
#endif
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Test/Framework/Visual/SpriteBatchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,26 @@ public void DrawWithCustomEffectAndTwoTextures()
};
Game.Run();
}

[Test]
public void DrawWithLayerDepth()
{
Game.DrawWith += (sender, e) =>
{
_spriteBatch.Begin();
_spriteBatch.Draw(
_texture, new Vector2(30, 30), null, Color.Red,
0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, -1.0f);
_spriteBatch.Draw(
_texture, new Vector2(40, 40), null, Color.Green,
0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
_spriteBatch.Draw(
_texture, new Vector2(50, 50), null, Color.Blue,
0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f);
_spriteBatch.End();
};

RunSingleFrameTest();
}
}
}
3 changes: 3 additions & 0 deletions Test/MonoGame.Tests.XNA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@
<Content Include="Assets\ReferenceImages\Shader\Shader__RainbowH__.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\ReferenceImages\SpriteBatch\DrawWithLayerDepth.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\ReferenceImages\SpriteBatch\Draw_normal.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

6 comments on commit 9d677e4

@mgbot
Copy link
Member

@mgbot mgbot commented on 9d677e4 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.4.0.450 is now running

@mgbot
Copy link
Member

@mgbot mgbot commented on 9d677e4 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.4.0.450 outcome was SUCCESS
Summary: Tests passed: 485, ignored: 6 Build time: 00:15:47

@mgbot
Copy link
Member

@mgbot mgbot commented on 9d677e4 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.4.0.453 is now running

@mgbot
Copy link
Member

@mgbot mgbot commented on 9d677e4 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.4.0.453 outcome was SUCCESS
Summary: Tests passed: 485, ignored: 6 Build time: 00:16:59

@mgbot
Copy link
Member

@mgbot mgbot commented on 9d677e4 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.5.0.1 is now running

@mgbot
Copy link
Member

@mgbot mgbot commented on 9d677e4 Apr 29, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.5.0.1 outcome was SUCCESS
Summary: Tests passed: 485, ignored: 6 Build time: 00:15:46

Please sign in to comment.