Transparency and DrawingSurface

Started by Gurok, Thu 09/01/2014 04:49:22

Previous topic - Next topic

Gurok

Hello,

I am trying to draw this simple graphic onto a GUI:



It's a partially transparent smiley face. The actual graphic is 16x16, but I've resized it for readability.

My game is a 32-bit colour game. I used the default game and made a new GUI called gTest. I imported the sprite and used its alpha channel. I changed Roger's interact function to:

Code: ags

DynamicSprite *mySprite;

function cEgo_Interact()
{
	DrawingSurface *out;

	if(mySprite != null)
		mySprite.Delete();
	mySprite = DynamicSprite.Create(16, 16, true);
	out = mySprite.GetDrawingSurface();
	out.DrawImage(0, 0, 6);
	out.Release();
	gTest.BackgroundGraphic = mySprite.Graphic;
	gTest.Width = 16;
	gTest.Height = 16;
	gTest.X = 50;
	gTest.Y = 50;
	gTest.Visible = true;
}


Here is what I see when I interact with Roger:



Transparent pixels where semi-opaque ones should be and opaque pixels remain where transparent ones are.

I've read some of the articles about AGS and blending and I appreciate that things are a little wonky when it comes to transparency in AGS. I'm not asking AGS to blend the sprite here. I just want it to set the alpha to a non-zero value for semi-transparent areas. Here's what I'd expect to see instead:



I would then be able to happily turn off the border/background and have a semi-transparent GUI.

I have tried playing around with various parameters to the functions. About the only thing that seems to make a difference is toggling transparency on the surface. If I set it to false, I get the classic purple blending going on:



I guess this proves that AGS is seeing my image has non-zero alpha in those areas, but not much else.

Please help me figure this out, guys. What do I need to do to draw this correctly on a DynamicSprite? If you want to try to replicate this, here's what I did:

1. Create a new default game
2. Set the colour depth to 32-bit
3. Add a new GUI called gTest
4. Import this sprite (here's the exact sprite: ) as sprite number 6
5. Replace Roger's interaction with the code above
6. Run the game and interact with Roger

Note: I am running 3.3.0 Beta 12.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

Default game template still uses old (improper) alpha blending. Good you noticed this, needs to be fixed.

Go to General Settings and set "Visual"->"Sprite alpha rendering style" to "Proper Alpha Blending".
Also probably is a good idea to set "Visual"->"GUI alpha rendering style" to "Multiplied Translucence..." (because it is proper alpha blending too).

Gurok

Thanks CW! I was tearing my hair out trying to find the right option.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Monsieur OUXX

Quote from: Crimson Wizard on Thu 09/01/2014 07:28:35
Go to General Settings and set "Visual"->"Sprite alpha rendering style" to "Proper Alpha Blending".
Also probably is a good idea to set "Visual"->"GUI alpha rendering style" to "Multiplied Translucence..."

WOW it's a good thing I read this thread, I didn't know the transparency fixes had been introduced that way. I definitely learnt something very useful here!
 

Crimson Wizard

Quote from: Monsieur OUXX on Fri 10/01/2014 11:57:10
WOW it's a good thing I read this thread, I didn't know the transparency fixes had been introduced that way.
This is done for backwards-compatibility (in case you import older project and want it retain all the behavior).
In most cases there should not be a reason to use other modes than "proper" ones.

We need to fix the templates that come with 3.3.0 to have this by default. At least "Empty" and "Default" templates.

SMF spam blocked by CleanTalk