Load Texture

May 13, 2009 at 2:28 AM


As i load a texture from a directory any such as d:\textures

and not from content?


May 13, 2009 at 4:04 AM

On the PC, XNA lets you do this by using Texture2D.FromFile().
This requires the GraphicsDevice, which you can get by calling the 'BeginGetGraphicsDevice()' method in DrawState. (Pass in 'None' as the argument).

Oct 5, 2009 at 7:44 PM

Small trick ;)

public static GraphicsDevice GetGraphicsDevice(Application app)
   Type appType = app.GetType().BaseType;
   return (GraphicsDevice)appType.GetField("graphics", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(app);

Oct 5, 2009 at 11:51 PM

Well. Be careful with that.

The idea being BeginGetGraphicsDevice / EndGetGraphicsDevice is that internal xen code knows when you might be trying to change things. Xen keeps track of what it thinks the graphics state is, so it can optimise out redundant state changes. While doing this for creating textures should be OK, doing anything with state will probably not be OK.

Also, in the content load methods, you have access to the DrawState, which can give you the graphics device. This is the most likely place you will need it for loading textures.

Oct 6, 2009 at 4:15 AM

I use it only for loading texture from file :)