John.Doe
Well, if you implement your own IGraphicsDeviceService and use the correct path and correct path format, it works. But writing a tool that works with the ContentPipeline is kind of a pain. There are some other threads in the forum discussing what would be neccessary to convert a standard Texture into one that the content pipeline can read. In short: The VSE the textures and models and so forth are converted to a special format for the contentpipeline, one can mimic this by creating a VS project file on the fly and calling msbuild to execute the conversion before loading the file. The result is instead of a texture "black.tga" a "black.xnb" - for this example taken from the Spacewar starter kit (just create one and compile it, then add the texture from the debug folder to your Gameless project).
Then you need a IGraphicsDeviceService
class SimpleGraphicsDeviceService : IGraphicsDeviceService, IGraphicsDeviceManager
{
private GraphicsDevice graphicsDevice;
private System.Windows.Forms.Control renderControl;
public SimpleGraphicsDeviceService(System.Windows.Forms.Control renderControl)
{
this.renderControl = renderControl;
}
#region IGraphicsDeviceService Members
public event EventHandler DeviceCreated;
public event EventHandler DeviceDisposing;
public event EventHandler DeviceReset;
public event EventHandler DeviceResetting;
public GraphicsDevice GraphicsDevice
{
get { return this.graphicsDevice; }
}
#endregion
#region IGraphicsDeviceManager Members
public bool BeginDraw()
{
//throw new Exception("The method or operation is not implemented.");
return false;
}
public void CreateDevice()
{
Microsoft.Xna.Framework.Graphics.PresentationParameters presentationParameters = new
Microsoft.Xna.Framework.Graphics.PresentationParameters();
presentationParameters.IsFullScreen = false;
presentationParameters.BackBufferCount = 1;
presentationParameters.BackBufferHeight = this.renderControl.Height;
presentationParameters.BackBufferWidth = this.renderControl.Width;
this.graphicsDevice = new GraphicsDevice(
GraphicsAdapter.Adapters[0],
DeviceType.Hardware,
this.renderControl.Handle,
CreateOptions.HardwareVertexProcessing,
presentationParameters);
}
public void EndDraw()
{
//throw new Exception("The method or operation is not implemented.");
}
#endregion
}
And a windows form (the form has just one panel, I omitted the initialize method), that provides the IServiceProvider interface to the ContentManager:
public partial class Form1 : Form, IServiceProvider
{
private SimpleGraphicsDeviceService graphicsDeviceService;
private Microsoft.Xna.Framework.Content.ContentManager contentManager;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.graphicsDeviceService = new SimpleGraphicsDeviceService(this.panel1);
this.graphicsDeviceService.CreateDevice();
this.contentManager = new Microsoft.Xna.Framework.Content.ContentManager(this);
Texture2D texture = this.contentManager.Load<Texture2D>(@"Black") as Texture2D;
MessageBox.Show("Texture null " + (texture == null));
}
#region
IServiceProvider Members
public new object GetService(Type serviceType)
{
if (serviceType == typeof(Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService))
return this.graphicsDeviceService;
else
return base.GetService(serviceType);
}
#endregion
}