Skip to main content
GameDev.net gamedev.net
🔒 Locked

XNA Small Solid Texture2D

Started by Daichi May 9, 2008 at 9:10 PM 3 replies 3.1k views
Original Post
Daichi
Daichi
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.
R3DLIN3
R3DLIN3
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
NickGravelyn
NickGravelyn
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);
Daichi
Daichi
It seems to be TextureUsage now, but yeah. Thank you that did the trick. :D
NickGravelyn
NickGravelyn
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.