MonoCef icon indicating copy to clipboard operation
MonoCef copied to clipboard

Colours are represented with Blue and Red switched

Open Hecksa opened this issue 5 years ago • 1 comments

I'll preface this with the fact that I don't specifically use MonoCef. I've been working on an integration between CefGlue and MonoGame for my own purposes, and looking at this project among others for help at times. I've hit a problem and realised it's present here too, so I thought I'd raise an issue, so you can be aware and look into it if you wish.

Simplest way to replicate is just set the background of .main-grid in this project to be #f00. Rebuild the UI, load up the game and you'll notice the colour is displayed as blue, rather than red.

I've popped a thread on the MonoGame forum asking for help - if I make any progress I'll try to remember to update here. Other than that, would appreciate any insights you may have.

Hecksa avatar Jul 02 '20 16:07 Hecksa

There's now an excellent answer posted on that thread that provides a shader as a fix, barely took a minute to implement and test - seems to work perfectly. Just to reiterate it here in case some far-future searcher comes along and the thread doesn't exist anymore (courtesy of TheKelsam):

Texture2D SpriteTexture;
sampler2D SpriteTextureSampler = sampler_state { Texture = <SpriteTexture>; };


struct VertexShaderOutput
{
	float4 Position : SV_POSITION;
	float4 Color : COLOR0;
	float2 TextureCoordinates : TEXCOORD0;
};


float4 MainPS(VertexShaderOutput input) : COLOR
{
	float4 color = tex2D(SpriteTextureSampler, input.TextureCoordinates);

	float rBuffer = color.r;
	color.r = color.b;
	color.b = rBuffer;

	return color;
}

technique SpriteDrawing
{
	pass P0
	{
		PixelShader = compile PS_SHADERMODEL MainPS();
	}
}

Put that in a “rbSwapShader.fx” file and add to your content builder, It can then be used like so:

shader = Content.Load<Effect>("rbSwapShader");

spriteBatch.Begin(
	sortMode: spriteSortMode,
	blendState: blendState ?? BlendState.AlphaBlend,
	effect: shader
);

Hecksa avatar Jul 02 '20 17:07 Hecksa