lime icon indicating copy to clipboard operation
lime copied to clipboard

Font.renderGlyphs crashes (windows, neko)

Open Anheurystics opened this issue 10 years ago • 9 comments

I know that this is because of the body of renderGlyphs being commented out, I'd just like to know what the state of this is? Do we have to use renderGlyph instead?

I tried to update the renderGlyphs function myself (with the whole ByteArray -> Bytes thing), but with no luck.

Anheurystics avatar Jan 25 '16 10:01 Anheurystics

fwiw, this is still an issue (on all platforms I'm pretty sure). Also, one of the examples that ships with lime does not work because of this. I would either recommend fixing the renderGlyphs function so that the original text rendering example works, or modify the example to render text in a supported way.

jahndis avatar Apr 12 '17 21:04 jahndis

I tried using renderGlyph on each individual glyph and storing the results manually in the Map, but it outputs weird text.

Anheurystics avatar Apr 18 '17 03:04 Anheurystics

There were a lot of improvements we were making to TextLayout, focused on OpenFL as the rendering layer. Font.renderGlyphs is working again, and the "TextRendering" Lime sample has been updated with minor fixes as well as Cairo renderer support as well :grin:

jgranick avatar Feb 15 '18 23:02 jgranick

One followup question on this. Is there a supported way to render the glyphs to a single Image (i.e. a font atlas of some sort)? It would be useful on the OpenGL end to not have to switch textures each time a different character is rendered.

The only thing I could come up with off the top of my head was using the Image.copyPixels to merge all of the separate images into a single Image, keeping track of glyph positions/sizes in some kind of atlas.

jahndis avatar Feb 18 '18 15:02 jahndis

Currently, Font.renderGlyphs can be used with a text string, it will render all the glyphs it finds in the string.

Long-term, it would be nice if this API allowed for ways to add extra glyphs to an existing texture. Happy to help if someone is interested in drafting an API or working on that

jgranick avatar Feb 19 '18 19:02 jgranick

For ASCII, you could use Font.renderGlyphs ("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~ ", fontSize)`, but it might be nice (also) to have an API for glyph ranges as well

jgranick avatar Feb 19 '18 19:02 jgranick

Ah nice! That should work just fine for now.

jahndis avatar Feb 20 '18 00:02 jahndis

So, followup on this. It looks like the example doesn't work for the html5 target (lime test html5). It complains with:

128WebGL: INVALID_OPERATION: vertexAttribPointer: no ARRAY_BUFFER is bound and offset is non-zero
128WebGL: INVALID_OPERATION: drawElements: no buffer is bound to enabled attribute
TextRendering.js:1358 Uncaught (in promise) TypeError: Cannot read property 'bitsPerPixel' of null
    at TextRender.init (TextRendering.js:1358)
    at Main.onPreloadComplete (TextRendering.js:1189)
    at Array.f (TextRendering.js:26723)
    at lime_app__$Event_$Void_$Void.dispatch (TextRendering.js:8119)
    at lime_app_Preloader.start (TextRendering.js:7172)
    at lime_app_Preloader.updateProgress (TextRendering.js:7256)
    at lime_app_Preloader.loadedAssetLibrary (TextRendering.js:7165)
    at TextRendering.js:7134
    at lime_app_Promise.complete (TextRendering.js:7277)
    at lime_utils_AssetLibrary.__assetLoaded (TextRendering.js:25026)
TextRendering.js:1408 WebGL: too many errors, no more errors will be reported to the console for this context.

In my own personal project, I specifically am running into problems with the TextLayout's positions array being empty, even when the TextLayout was created with a string on the html5 target. This can be verified in the TextRendering example as well by sticking a trace(textLayout.positions); right after one of the new TextLayout()'s. It shows up as an empty array for me on html5.

Is there something I might be missing? Otherwise, it seems like there might still be some work to be done here.

(On a side note, it appears that TextLayout doesn't do anything with newlines in terms of setting the y offset of glyphs, but this is a separate issue.)

jahndis avatar Apr 02 '18 06:04 jahndis

The TextLayout API is only for native targets, at the moment, but I'm hoping we can migrate some of this logic over:

https://github.com/openfl/openfl/issues/1693

jgranick avatar Apr 02 '18 19:04 jgranick