kons-9 icon indicating copy to clipboard operation
kons-9 copied to clipboard

Implement OpenGL text engine

Open kaveh808 opened this issue 1 year ago • 15 comments

Allow for the display of text in OpenGL views.

kaveh808 avatar Aug 26 '22 20:08 kaveh808

I've had luck with cl-fond, though it uses a c library (also written by hafner, and available through quicklisp) to do the layout.

Specifically, I've used cl-fond:compute-text, which returns a vertex array buffer, and an element count which can be used with %gl:draw-elements from the cl-opengl system.

loskool avatar Aug 26 '22 21:08 loskool

Thought I'd try a quick hack. https://imgur.com/a/k0VCYFH TIL old GL is slow as molasses drawing pixels. Totally useless. Think I'll work on my font atlas.

JMC-design avatar Aug 27 '22 18:08 JMC-design

What did you use for the text rendering?

I would be keen to get an example of a clickable button up in our UI soon.

Not sure if we should try cl-fond, or something more substantial such as Imgui which @awolven mentions in this discussion: https://github.com/kaveh808/kons-9/discussions/29

Or should we wait for glop first? Not sure how all the pieces fit together.

kaveh808 avatar Aug 27 '22 21:08 kaveh808

I just used my font stuff to get cl-vector paths for the string, and then used a small render abstraction over cl-vectors to plot it a pixel at a time using gl:draw-pixels. I didn't think it would slow everything down to 1 fps or less though, since it's able to do this over CLX which is way more pixels than in that text. https://www.youtube.com/shorts/-FlYBFlgc9Y . I might have been doing something wrong though, because sbcl would complain after a while of too many open files if I tried to add more text to the loop. Not sure if that's a cl-opengl thing or a cl-glfw thing, either way, not a good a thing.

btw, it works on windows as long as the ~'s before newlines are removed in strings and the glfw3.dll is placed in the windows path or same directory as sbcl.exe Though removing lines in the viewport actually removed some lines in windows file manager.

As for glop there was a problem with smooth scrolling (there was none) so 3b implemented xinput2, but I'm not sure if it's completed or maybe the maintainer didn't want different behaviours on different platforms. It has a note saying mac is experimental but no idea what that means as I have no mac. But if you want to try it's minimal code change, I can do that tomorrow with a special to control it if you want.

JMC-design avatar Aug 27 '22 22:08 JMC-design

What happens if you draw a bezier curve with LINES or LINE_STRIP primitives? Just curious.

On Sat, Aug 27, 2022 at 5:30 PM Johannes Martinez Calzada < @.***> wrote:

I just used my font stuff to get cl-vector paths for the string, and then used a small render abstraction over cl-vectors to plot it a pixel at a time using gl:draw-pixels. I didn't think it would slow everything down to 1 fps or less though, since it's able to do this over CLX which is way more pixels than in that text. https://www.youtube.com/shorts/-FlYBFlgc9Y . I might have been doing something wrong though, because sbcl would complain after a while of too many open files if I tried to add more text to the loop. Not sure if that's a cl-opengl thing or a cl-glfw thing, either way, not a good a thing.

btw, it works on windows as long as the ~'s before newlines are removed in strings and the glfw3.dll is placed in the windows path or same directory as sbcl.exe Though removing lines in the viewport actually removed some lines in windows file manager.

As for glop there was a problem with smooth scrolling (there was none) so 3b implemented xinput2, but I'm not sure if it's completed or maybe the maintainer didn't want different behaviours on different platforms. It has a note saying mac is experimental but no idea what that means as I have no mac. But if you want to try it's minimal code change, I can do that tomorrow with a special to control it if you want.

— Reply to this email directly, view it on GitHub https://github.com/kaveh808/kons-9/issues/57#issuecomment-1229280566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGMMI3SKLAH2W4WUJE5UDV3KJJZANCNFSM57X3CXKA . You are receiving this because you were mentioned.Message ID: @.***>

awolven avatar Aug 27 '22 23:08 awolven

You just get an outline. Which is really useful in 3d, not so useful for reading :) I can't remember what discussion it was in, but i did exactly that, https://imgur.com/gallery/YvPt3RK . Well, actually I cheated and didn't do beziers, transformed the path into only lines first and convert that to polygon. To get a flat shape you'd need faces and a boolean operator to cut out inner shapes.

JMC-design avatar Aug 28 '22 00:08 JMC-design

This is probably a better view, https://imgur.com/a/pTzC9aV . And it's actually quite readable when not showing the points. Curves decimated to 100 lines.

JMC-design avatar Aug 28 '22 01:08 JMC-design

that looks good. if you make it small enough does it look like a regular bitmap glyph?

On Sat, Aug 27, 2022 at 8:38 PM Johannes Martinez Calzada < @.***> wrote:

This is probably a better view, https://imgur.com/a/pTzC9aV . And it's actually quite readable when not showing the points. Curves decimated to 100 lines.

— Reply to this email directly, view it on GitHub https://github.com/kaveh808/kons-9/issues/57#issuecomment-1229354433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGMMMLLUTPFHKMPF6VKILV3K7HVANCNFSM57X3CXKA . You are receiving this because you were mentioned.Message ID: @.***>

awolven avatar Aug 28 '22 02:08 awolven

actually, it sort of does. But what are you going to do, group it with the camera so it's always facing the user? Because they're just polygons added to the scene.

JMC-design avatar Aug 28 '22 02:08 JMC-design

For a prototype GUI, I'm wondering if we can create an ortho OpenGL view on top of the perspective one and do widgets and text rendering there.

kaveh808 avatar Aug 28 '22 07:08 kaveh808

That's my thinking. I'm experimenting with writing a gl backend for my 2d draw system to test how fast/slow it is. Could probably also use it to draw text if we remove antialiasing. Should be serviceable if you don't mind flat square buttons, oh wait, thank you material design!

JMC-design avatar Aug 28 '22 15:08 JMC-design

Kaveh wants me to share an idea with the team on the subject of text engines.

I've been experimenting with Bart Botta's (3b's) text engine 3b-bmfont, which is native lisp, and much more mature than the one we have come up with so far. It uses the same font library we are using, which was written by Zach Beane (zpb-pdf).

It has the ability to cache font atlases and font metadata for quick loading of kons-9, which is one of the requirements Kaveh wanted out of our text engine. It has the ability to do font discovery, which can pick a system font for you based on the qualities you suggest. There is code available for the layout of text based on font-metrics, which we were otherwise going to have to implement on our own.

It's currently under final development by Bart according to Shinmera, and I have managed to get it built and running in a vanilla sbcl. Currently it is running opengl 3.3, but could be modified to support vulkan and metal. It offloads the support to a certain extent to Bart, who with Shinmera is using it for Kandria.

I could make a new text engine branch with 3d-bmfont if folks are interested.

awolven avatar Sep 20 '22 21:09 awolven

If this is a more mature system and can run on MacOS, then it sounds like a good idea.

A text engine is a high priority, so we can work on a GUI.

kaveh808 avatar Sep 20 '22 21:09 kaveh808

lol that's why I mentioned a while ago why didn't you just use Shinmera's Trial which uses the (m)sdf font generation from 3b! and then you don't have to reinvent the gui wheel and work with one of the best Lisper's out there who already uses the stuff in production.

JMC-design avatar Sep 21 '22 15:09 JMC-design

Last I heard, Trial did not support MacOS. Has that changed?

kaveh808 avatar Sep 21 '22 19:09 kaveh808

Done by @awolven. Will revisit the issue once we move to Vulkan.

kaveh808 avatar Oct 27 '22 19:10 kaveh808