How to load content in a Monogame library?

I am making my own library for UI and I would like to add simple tools for drawing shapes. I would like to load one white pixel and then use that as texture. But I can’t figure out how to load any content. I have found simmilar question but the answer doesn’t say how to use the ResourceContentManager. It doesn’t have to be in static method, I will use it privately for my other classes so it doesn’t really matter.

Thanks for help.

You could just create the Texture instead of loading it as a resource:

    private static Texture2D WhiteRectangle;

        // Create a 1px square rectangle texture that will be scaled to the
        // desired size and tinted the desired color at draw time
        WhiteRectangle = new Texture2D(GraphicsDevice, 1, 1);
        WhiteRectangle.SetData(new[] { Color.White });
2 Likes

Yep, this is the easiest way to do it for a simple blank texture. However, if you really needed to load content within a library, you could just pass a ContentManager to the library for it to use, or I suppose one could be created within the library. Alternately, you could simply load the content in your main project and then pass the loaded content to the library. This is what I do for my font rendering.

Thank you, that works perfectly :slight_smile:

1 Like