XNA Small Solid Texture2D

Started by
3 comments, last by NickGravelyn 15 years, 11 months ago
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.
Advertisement
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:

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);
It seems to be TextureUsage now, but yeah. Thank you that did the trick. :D
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