tdewolff / canvas

Cairo in Go: vector to raster, SVG, PDF, EPS, WASM, OpenGL, Gio, etc.
MIT License
1.5k stars 102 forks source link

[Feature request] Supporting Raylib #310

Closed ajitid closed 2 months ago

ajitid commented 2 months ago

Hello! Would it be possible to integrate this with https://github.com/gen2brain/raylib-go? Raylib provides its own OpenGL renderer and I'm wondering if canvas can directly hook into it.

My usecase is that I want to render variable fonts in Raylib, which it doesn't support natively. And my hope is that canvas is able to take this responsibility and directly render variable fonts in its renderer.

tdewolff commented 2 months ago

Hi Ajit, currently the OpenGL renderer simply renders to a texture and displays that on screen. Not very sophisticated for shapes but actually very common to render text. You could do the same: render a piece of text to an image.Image using canvas once, and then render it many times with Raylib. Would that work for you?

ajitid commented 2 months ago

Thanks for the quick response!

Than may work for me, yes. I just have started looking into this lib (and thus may not be very about clear about things) but I have few questions to ask:

ajitid commented 2 months ago

(Updated my list of questions)

tdewolff commented 2 months ago

Variable fonts are not supported yet, unfortunately.

Regarding SDF, that is exactly what I was looking at to implement for OpenGL. The problem is supporting both TTF and OTF, which consist of quadratic and cubic Béziers respectively. It is also required to triangulate the font path. Nothing that can't be done, but it is a significant piece of work that I haven't had the time for. Unlike what the article claims that you linked, it is not "really simple". It speaks of a matrix with distance values, but that would generate the same results as a bitmap in terms of pixelyness. You need to calculate those distance values on the fly using shader programming and triangles containing quadratic Béziers.

I could look at https://github.com/mapbox/tiny-sdf to see how to do this, but be aware that I have no time to implement new stuff for at least a few months.

ajitid commented 2 months ago

Ah ok. Variable fonts are more important to me than SDF at the moment. I'm closing the issue as that is not supported.