I’m trying to use the Chromium Embedded Framework inside of MonoGame (via CefGlue), so I can create a HTML/CSS based UI. I actually have pretty much everything I want working, but there’s an issue I’m not sure how to deal with.
Any colours I specify are displayed with RGB inverted to BGR - ie, #FF0000 or rgb(255,0,0) will be represented as blue when it should be red, and vice versa. Having not done any graphics dev to speak of prior to now, I’m a bit stuck.
Incidentally, this same bug exists in MonoCef, which handles the texture copy in a slightly more complex but fundamentally similar way to my code.
Here’s some code showing how I’m creating my Texture2D from Cef’s frame buffer:
byte[] managedArray = new byte[width * height * 4];
// Note: buffer is an IntPtr coming from CefGlue, pointing to memory containing the rendered UI
Marshal.Copy(buffer, managedArray, 0, width * height * 4);
Texture2D uiTexture = new Texture2D(GraphicsDevice, width, height);
uiTexture.SetData(managedArray);
this._UITexture = uiTexture;
Basically, I’m looking for a way to either specify the format of the texture I’m sending in is the opposite of the way it’s currently read, or else somehow performantly switch all the colours, every frame, to be correct. Ideally there’s some API that I’m not aware of to specify how to read in this data, or something, but I’ve been unable to locate one.
Does anyone have any knowledge that could help me out here? Thanks.
Note: I’m trying to be as cross-platform friendly as possible, running on dotnet core (hence not using MonoCef, which depends on CefSharp), so would rather avoid any System.Drawing references, but if you only have an answer that does use System.Drawing, I’d still love to see one. Also, does anyone know of a way to avoid copying the texture data? It’d be way nicer to reference it directly from the IntPtr…