Jump to content
  • Advertisement
Sign in to follow this  
Daichi

XNA Small Solid Texture2D

This topic is 3693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!