CHAPTER 3 ■ WORKING WITH 2D IMAGES/TEXTURES IN XNA 3.0
209
Color[] textureColors = new Color[textureWidth* textureHeight];
int i = 0;
for (int ver = 0; ver < textureHeight; ver++)
for (int hor=0; hor<textureWidth; hor++)
{
textureColors[i++] = new
➥
Color(new Vector4((float)hor / (float)textureWidth, ➥
0, (float)ver / (float)textureHeight, 1));
}
Texture2D newTexture = new Texture2D(device, textureWidth, ➥
textureHeight, 1, ResourceUsage.None, SurfaceFormat.Color);
newTexture.SetData<Color>(textureColors);
return newTexture;
}
The preceding method should be called from the LoadContent method, because it requires
the device to be instantiated:
protected override void LoadContent()
{
device = graphics.GraphicsDevice;
spriteBatch = new SpriteBatch(GraphicsDevice); ...