Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradient on TextField #1067

Open
CrazyFlasher opened this issue Feb 12, 2020 · 6 comments
Open

Gradient on TextField #1067

CrazyFlasher opened this issue Feb 12, 2020 · 6 comments

Comments

@CrazyFlasher
Copy link

CrazyFlasher commented Feb 12, 2020

Is it possible to create something like this without using bitmap fonts?
https://bit.ly/3bvEo8u

@PrimaryFeather
Copy link
Contributor

Hmm ... Starling uses the Flash API to draw TrueType text, so to make this possible, one would first need to figure out how this can be done with Flash.

The Graphics class unfortunately doesn't support drawing of text – that would be the natural place to look for the options for line thickness, gradients, etc. So you'd have to use the TextField and draw that to a BitmapData object (what Starling does internally), but this doesn't support color gradients.

Well ... you might be able to get to the gradient via masking (in Flash, not Starling), and then apply the drop shadow and outline as filters. But in the end, you'd always have to upload that to the GPU.

So, I think the short answer is probably "no". 😉

@CrazyFlasher
Copy link
Author

Well I can apply shadows, outline and other stuff. But stuck with gradients.
May be this can help: https://forum.starling-framework.org/d/21087-contribution-mesh-gradient-fill/10

@JohnBlackburne
Copy link

JohnBlackburne commented Feb 13, 2020

I wrote that mesh gradient fill routine. Unfortunately there’s no straightforward way to use it with text, My code works with a Mesh object, and text in Starling does not use Meshes in a way that is useful (it draws a line of text as a Quad, which is a Mesh, but applying a gradient fill to that will just give you a shaded rectangle).

If I had to do this I would probably do it in the classic Flash API. As Daniel notes the Graphics API has gradients, but it is separate from the BitmapData API which Starling uses for drawing text. But there are various ways to combine them. Draw a gradient filled rectangle in one BitmapData, draw your text in another, then use BitmapData.copyPixels to combine them by using the font BitmapData for the alphaBitmapData parameter, for example.

@CrazyFlasher
Copy link
Author

Thanks. I'll try to do that way and post results soon

@CrazyFlasher
Copy link
Author

Another way recommended by openfl communuty
https://community.openfl.org/t/gradient-fill-for-textfield-with-truetype-font/12300/2

@JohnBlackburne
Copy link

I don’t know how that is implemented in OpenFL, but in Starling a mask has only one bit per pixel – it is either on or off. So you get jagged edges which tends to look horrible with text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants