Looking at your code, what your trying to do is draw a texture dynamically and then display that on the GraphicsDevice correct?
This is how I do that :
/// <summary>
/// Base class for dynamically generated backgrounds
/// </summary>
class Background : Texture2D
{
public Background( GraphicsDevice device, int width, int height )
: base( device, width, height, 1, TextureUsage.None, SurfaceFormat.Color )
{
}
}
class GradientBackground : Background
{
public GradientBackground( GraphicsDevice graphicsDevice, int width, int height, Color startColor, Color endColor, int steps )
: base( graphicsDevice, width, height )
{
if ( steps > height || steps < 0 )
throw new ArgumentOutOfRangeException( "steps", "Must be in the range of [ 0, height ]." );
Color[] data = new Color[ width * height ];
int rowsPerStep = width / steps;
int currentPixel = 0;
for ( int i = 0; i < steps; i++ )
{
byte red = (byte)( startColor.R + ( endColor.R - startColor.R / steps * i ) );
byte green = (byte)( startColor.G + ( endColor.G - startColor.G / steps * i ) );
byte blue = (byte)( startColor.B + ( endColor.B - startColor.B / steps * i ) );
Color pixelColor = new Color( red, green, blue );
for ( int row = 0; row < rowsPerStep; row++ )
for ( int pixel = 0; pixel < height; pixel++ )
{
data[ currentPixel++ ] = pixelColor;
}
}
SetData( data );
}
}
And if you wanted to update it during you update method you could do that too.