Ok i haven’t done any shader stuff with spritebatch in monogame so i basically wanted to give it a shot. I used yesterdays build, created a default fx using the pipeline tool, added a image and a sprite font, dropped in the basic code i thought used to work in 4.0 but, Im getting nothing drawing. The background is cleared but text and image disappear…
What am i missing here ?
` public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont myfont;
Effect myeffect;
Texture2D tpic01;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
myfont = Content.Load<SpriteFont>("MyFont");
myeffect = Content.Load<Effect>("MyEffects");
tpic01 = Content.Load<Texture2D>("tpic01");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
//spriteBatch.Begin();
// drop in my effect and text and image disappear.
spriteBatch.Begin(0, BlendState.NonPremultiplied, null, null, null, myeffect);
spriteBatch.Draw(tpic01, new Rectangle(100, 100, 300, 300), Color.White);
spriteBatch.DrawString(myfont, "hello", new Vector2(20, 20), Color.AntiqueWhite);
spriteBatch.End();
base.Draw(gameTime);
}
}
, the basic stuff the pipeline tool outputs for a fx file it shouldn’t change anything
`
SV_POSITION POSITION
VS_SHADERMODEL vs_3_0
PS_SHADERMODEL ps_3_0
Edit: lol never mind doh, i just realized why there is a effect and spriteeffect option in the pipeline tool menu i thought that was some sort of bug didn’t realize one was for spriteBatch and the other for 3d drawing.
Ya i do want to be able to alter the vertices using the shader, Ill give what you posted below a shot.
This is the one for spritebatch has the sampler state set up.
If you also want to do stuff in the vertex shader you need to set the matrix like in SpriteEffect for it to work. SpriteBatch doesn’t do this because it expects the effect to handle it.
var projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1);
really weird i cant tell whats going on if its getting the matrix or not.
Just having the line in the shader that takes the matrix is causing nothing to draw
This won’t work because the matrix you pass in spriteBatch.Begin is applied in the vertex shader of SpriteEffect. Since you use your own vertex shader, this doesn’t do anything. Instead you should set the matrix in your effect so it does what the SpriteEffect vertex shader normally does.