00001 #region File Description
00002
00003
00004
00005 #endregion
00006
00007 namespace NewGamePhysics.Utilities
00008 {
00009 using System;
00010 using Microsoft.Xna.Framework;
00011 using Microsoft.Xna.Framework.Graphics;
00012
00016 public class TextureHelpers
00017 {
00024 public static Texture2D CreateColorTexture(GraphicsDevice graphicsDevice)
00025 {
00026 return Create(graphicsDevice, 1, 1, new Color());
00027 }
00028
00036 public static Texture2D Create(GraphicsDevice graphicsDevice, Color color)
00037 {
00038 return Create(graphicsDevice, 1, 1, color);
00039 }
00040
00050 public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color)
00051 {
00052
00053 Texture2D texture = new Texture2D(
00054 graphicsDevice,
00055 width,
00056 height,
00057 1,
00058 TextureUsage.None,
00059 SurfaceFormat.Color);
00060
00061
00062 Color[] colors = new Color[width * height];
00063 for (int i = 0; i < colors.Length; i++)
00064 {
00065 colors[i] = new Color(color.ToVector3());
00066 }
00067
00068
00069 texture.SetData(colors);
00070
00071 return texture;
00072 }
00073
00079 public static Color[] TextureToColors(Texture2D texture)
00080 {
00081 Color[] color1D = new Color[texture.Width * texture.Height];
00082 texture.GetData(color1D);
00083 return color1D;
00084 }
00085
00091 public static Color[,] TextureToColorArray(Texture2D texture)
00092 {
00093
00094 Color[] color1D = TextureToColors(texture);
00095
00096
00097 Color[,] color2D = new Color[texture.Width, texture.Height];
00098
00099
00100 int x=0;
00101 int y=0;
00102 foreach (Color color in color1D)
00103 {
00104 color2D[x, y] = color;
00105 x++;
00106 if (x > texture.Width)
00107 {
00108 y++;
00109 x = 0;
00110 }
00111 }
00112
00113 return color2D;
00114 }
00115 }
00116 }