logoalt Hacker News

Suracyesterday at 6:24 AM6 repliesview on HN

I had hoped for some more basic stuff. I struggle for 2 months now to implement a fast line draw with width for a embeed cpu. It only has a framebuffer no gpu


Replies

pjmlpyesterday at 7:05 AM

The bible of graphics programming, everything with software rendering,

"Computer Graphics: Principles and Practice"

https://www.informit.com/store/computer-graphics-principles-...

Yeah, it is a steep price as many academia books, maybe you can find it on a library nearby, as its first edition was in 1982.

show 1 reply
gmiller123456yesterday at 4:43 PM

"Basic" is a relative term. Modern graphics GPUs do not work the same way memory mapped graphics do, and working with them is different at a fundamental level.

You are probably better off searching for old graphics programming books from the 90s. The code they have likely won't work, the the algorithms should be what you're looking for, and shouldn't be hard to adapt.

xyzsparetimexyzyesterday at 7:49 AM

Fast, thick lines, no gpu

Choose 2

socalgal2yesterday at 7:55 AM

It's non-trival though not that hard. Have you asked an LLM?

It depends on your needs

* You can compute a rectangle by expanding a line purpendicular to its direction

The problem with this is you'll get gaps between 2 lines if they are supposed to be connected. You can solve that by trying to connect the corners if the rectangles. Once you do this though you're no longer drawing rectangles. You might have to make a simple triangle rasterizer. Or a scanline rasterizer

* You can "drag a brush". You compute a single line, then at each pixel, draw a sprite/circle/rectangle around that pixel. That's slow because you'll draw every pixel more than once but it will work and might be fast enough

This has the issue with the ends will be different unless your brush is round. If that's ok then it works.

All of these are something you can ask Gemini, ChatGPT, Claude, and they'll spit out an exmaple in the language of your choice.

show 1 reply