XNA Small Solid Texture2D
So, with XNA.
Anyway to go about making a small solid Texture2D without loading an image?
Like generate a 2x2 white image to use for drawing rectangles or whatever.
Off the top of my head you could use a render target for a spritebatch drawing nothing but a solid fill color then resolve the render target into a texture. I'm sure there is a better way to do this but that will work
First you just create a texture using the constructor (http://msdn.microsoft.com/en-us/library/bb195755.aspx). Then you can use SetData to set some pixels to it (http://msdn.microsoft.com/en-us/library/bb198834.aspx).
So basically like this:
So basically like this:
Texture2D texture = new Texture2D( graphicsDevice, 2, 2, 0, ResourceUsage.None, SurfaceFormat.Color);Color[] pixels = new Color[4];for (int i = 0; i < pixels.Length; i++) pixels = Color.White;texture.SetData(pixels);
Quote:Original post by Daichi
It seems to be TextureUsage now, but yeah. Thank you that did the trick. :D
Oops. I'm embarrassed now. I accidentally pulled up the 1.0 Refresh docs. I guess it was a little late last night. :)
Glad you got it working, though.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement