3 ms·
So the blog post ends with a promise of sections about: * inline layout * text rendering. * networking. * scripting. LAYOUT I think here could be useful t
by emmanueloga_ 8y ago
So the blog post ends with a promise of sections about:
* inline layout
* text rendering.
* networking.
* scripting.
LAYOUT
I think here could be useful to take a look at something like Facebook's Yoga [1] although maybe not great to start. There's this little layout demo that could be interesting to investigate [2].
TEXT
Regarding text probably the keyword to learn about is "rasterization". I found a few tutorials back in the day [3], [4]. In general rendering text is a PITA and you don't want to do it no matter what :-) The only lightweight solution I found was stb's truetype [3].
So if you want to render text yourself you'll need:
- a parser for a font format format (e.g. TTF, PITA) to have a way to get the curve definitions for each font.
- a rasterizer (could be a fun project for getting something reasonable and probably slow performant)
- a curve filling algorithm and plugging it to your rasterizer, which will probably be able to do humble things like drawing filled triangles and other simple shapes (PITA! :-p)
- a word and paragraph layout engine (PITA again :-)
Overall I'm happy half understanding the steps involved and not having to deal with all the messy steps in the middle.
NETWORKING
I'm super lazy in this area, and I would rather learn something like ZeroMQ to posix sockets... back in the day I followed Beej's tutorial which was nice. [6] Then you can connect your sockets to some pre-existing HTTP parser which are a dime a dozen these days [7] and you are all set! :-p
SCRIPTING
Not much to say here... hundreds of languages available. Probably Lua is a nice alternative to JavaScript, but there are also plenty of lightweight JavaScript implementations these days (I think there is a nice little one called V7). If you want to learn how to actually implement an interpreter there are plenty of resources too. If I went this route I would start by implementing some version of lisp or scheme for simplicity.
1: https://yogalayout.com/ https://yogalayout.com/
2: https://github.com/randrew/layout https://github.com/randrew/layout
3: https://github.com/NotCamelCase/RasterizationInOneWeekend https://github.com/NotCamelCase/RasterizationInOneWeekend
4: http://www.scratchapixel.com/index.php http://www.scratchapixel.com/index.php
5: https://github.com/nothings/stb/blob/master/stb_truetype.h https://github.com/nothings/stb/blob/master/stb_truetype.h
6: https://beej.us/guide/bgnet/ https://beej.us/guide/bgnet/
7: https://github.com/search?q=http+parser&ref=opensearch https://github.com/search?q=http+parser&ref=opensearch
- krapp 8y ago>So if you want to render text yourself you'll need (...) Or possibly use SDL or a similar graphics library meant for game development. You would still probably have to write a lot of code but you would get a rasterizer, font loading, simple primitives and image rendering in a cross-platform compatible API.
- codezero 8y agoAmazing follow up. Thanks so much.