0
votes

I'm working with Monogame and I'm trying to do something incredibly simple, draw a square on the screen. The most basic thing I can do essentially. The only code I've added to the template is the following:

spriteBatch.Begin();

spriteBatch.Draw(
    new Texture2D(GraphicsDevice, 100, 100),
    new Vector2(100, 100),
    Color.Red
);

spriteBatch.End();

Here are a handful of examples of what I see when I run the program.

The image changes every frame and eventually just displays a flickering static. This clearly isn't an issue with how I've written my code, so it must either be an issue with Monogame, an issue with my installation of Monogame, or an issue with my video card/drivers. I'm using an Nvidia Geforce GTX 570 with the most up to date drivers.

Any thoughts on how/if this might be fixed?

1

1 Answers

2
votes

This clearly isn't an issue with how I've written my code

I disagree. This is very clearly an issue:

spriteBatch.Draw(
    new Texture2D(GraphicsDevice, 100, 100),
    new Vector2(100, 100),
    Color.Red
);

You're initializing a brand-new 100x100 texture every single frame and then not putting any data inside of it. Don't do either of those things! You're chewing through tons of video memory for no reason, and your textures are full of whatever garbage already happened to be living in the space where they get allocated.

Create a single texture and fill it with valid data:

var nullTexture = new Texture2D(GraphicsDevice, 1, 1);
nullTexture.SetData(new [] { Color.White });