I switched my Project from XNA 4 to MonoGame 2.5.1. The port went somewhat unproblematic but I am stumpled across a problem i can’t resolve. For your interest, the code worked on XNA:
When I am drawing a spritebatch with a basicEffect I get an ArgumentNullException on calling the End() method. This is the simplified draw call
// polyEffTest is defined somewhere else, not in the draw function
polyEffTest = new PolygonBasicEffect(gd);
// the simplified draw call
sbTest.Begin(
SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
SamplerState.LinearClamp,
DepthStencilState.Default,
GraphicsDevice.RasterizerState,
polyEffTest,
Matrix.CreateTranslation(offX, offY, 0f)
);
// draw something [...]
sbTest.End() // <- End-call causes Exception
when I replace polyEffTest with NULL in sbTest.Begin I won’t get the ArgumentNullException but nothing gets drawed either (obvious). So I guess it has to do something with the BasicEffect.
at OpenTK.Graphics.ES11.GL.GetError () [0x00000] in <filename unknown>:0 at OpenTK.Graphics.ES11.ErrorHelper.ResetErrors () [0x00000] in <filename unknown>:0 at OpenTK.Graphics.ES11.ErrorHelper..ctor (IGraphicsContext context) [0x00000] in <filename unknown>:0 at OpenTK.Graphics.ES11.GL.Viewport (Int32 x, Int32 y, Int32 width, Int32 height) [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.Graphics.GLStateManager.Viewport (Rectangle viewport) [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.Graphics.BasicEffect.Apply () [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.Graphics.SpriteBatch.End () [0x00000] in <filename unknown>:0 at Hello.Game1.Draw (Microsoft.Xna.Framework.GameTime gameTime) [0x00058] in /home/mereddyn/projects/c#/Hello/Hello/Game1.cs:97 at Microsoft.Xna.Framework.Game.DoDraw (Microsoft.Xna.Framework.GameTime gameTime) [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.GameWindow.OnRenderFrame (System.Object sender, OpenTK.FrameEventArgs e) [0x00000] in <filename unknown>:0 at OpenTK.GameWindow.OnRenderFrame (OpenTK.FrameEventArgs e) [0x00000] in <filename unknown>:0 at OpenTK.GameWindow.OnRenderFrameInternal (OpenTK.FrameEventArgs e) [0x00000] in <filename unknown>:0 at OpenTK.GameWindow.RaiseRenderFrame (System.Diagnostics.Stopwatch render_watch, System.Double& next_render, OpenTK.FrameEventArgs render_args) [0x00000] in <filename unknown>:0 at OpenTK.GameWindow.DispatchUpdateAndRenderFrame (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 at OpenTK.GameWindow.Run (Double updates_per_second, Double frames_per_second) [0x00000] in <filename unknown>:0 at OpenTK.GameWindow.Run (Double updateRate) [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.GameWindow.Run (Double updateRate) [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.LinuxGamePlatform.RunLoop () [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.Game.Run (GameRunBehavior runBehavior) [0x00000] in <filename unknown>:0 at Microsoft.Xna.Framework.Game.Run () [0x00000] in <filename unknown>:0 at Hello.Program.Main () [0x00010] in /home/mereddyn/projects/c#/Hello/Hello/Program.cs:20
I am using MonoGame 2.5.1 on Ubuntu 14.04 with MonoDevelop. The polyEffTest is defined like that:
public class PolygonBasicEffect : BasicEffect
{
public PolygonBasicEffect(GraphicsDevice graphicsDevice)
: base(graphicsDevice)
{
this.VertexColorEnabled = true;
this.TextureEnabled = true;
this.Projection = Matrix.CreateOrthographicOffCenter(
0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1
);
}
public PolygonBasicEffect(BasicEffect effect)
: base(effect)
{
}
public BasicEffect Clone()
{
return new PolygonBasicEffect(this);
}
}
Even if I am calling the End call imediatly after the Begin i get the Exception. I even get the exception if I am replacing polyEffTest with a new BasicEffect()
I was testing this on a different machine. I downloaded the same MonoVersion to a Windows 7 System and tried it with VisualStudio. There the code worked. I even tried to enable unsafe code, it still does not work.