I am currently trying to get a MonoGame-based engine to run under WPF. So far, things are working out nicely, based on the WPFInterop sample as shown here:
However, loading assets such as SpriteFonts via the content manager does not work so far, the exception thrown complains being “No Graphics Device Service.” This issue has been discussed already here:
As far as I can see, the problem has not been solved, though. The obvious problem seems to be that the ContentManager does not get the reference to the GraphicsDevice. So I tried to fix this via:
var container = new ServiceContainer();
container.AddService(typeof(GraphicsDevice), _graphicsDevice);
_content = new ContentManager(container);
Now, I get the error message: “No Graphics Device Service”. Problem is now, that for a construction of a IGraphicsDeviceService to add to the container, I would need a instance of Game, wouldn’t I?
I have the feeling the solution is not far off, but I do not seem to work it out. I am happy about any suggestions!
Thanks a lot, it works! But I am still a little confused: I am using a already existing GraphicsDevice to initialize a GraphicsDeviceManager, which then provides the interface for my ContentManager?
I will try again: So, first, I am creating a GraphicsDevice, e.g., using the default adapter and one of the two possible profiles. Then, I hand a reference of this GraphicsDevice to the (dummy) GraphicsDeviceManager, which I thought was there to, well, handle all my GraphicsDevice, in case I have multiple.
So, basically, I am confused, since I thought that hierarchy-wise, I would first have to create a GraphicsDeviceManager, before even thinking about a GraphicsDevice. But that’s apparently not correct.
The purpose of the IGraphicsDeviceService interface is:
Defines a mechanism for retrieving GraphicsDevice objects.
The DummyGraphicsDeviceManager fulfills only this purpose at the moment. It enables other services, like the ContentManager, to get a hold of the GraphicsDevice.
If you want, you can move your custom GraphicsDevice creation code into the DummyGraphicsDeviceManager. One could argue that this would be a cleaner design.