News for hackers. Stuff that matters.
Re:The Littlest CPU Rasterizer by nwhitehead on Monday March 10, 2014 @08:35PM (#7376697)
Fun! When I saw spherical harmonics I was confused about why spherical harmonics would come into play in a voxel universe (isn't everything flat?). Digging into it a bit I found out more about spherical harmonic lighting: http://www.research.scea.com/gdc2003/spherical-harmonic-ligh...
Re:The Littlest CPU Rasterizer by ginsweater on Monday March 10, 2014 @09:50PM (#7376940)
The geometry may be flat, but relationships between objects are still arbitrary, so light can still hit things from any angle. Try as you might, you can't escape curves. ;)

That article's a classic; definitely worth a read for anyone interested in graphics.

Re:The Littlest CPU Rasterizer by glbn on Monday March 10, 2014 @05:56PM (#7375951)
cool ! shouldn't it be:

U32 ind = (xx-xStart + (yy-yStart) * 16+ ( zz-zStart ) * 16 * 16) * 2;

in your code, though ?

Re:The Littlest CPU Rasterizer by ginsweater on Monday March 10, 2014 @09:45PM (#7376919)
Whoops, yeah, you caught me. As I handwaved in the post, there's a little bit of implementation detail in the real code that I removed to clarify the algorithm. Fixed now, thanks.
Re:The Littlest CPU Rasterizer by AnthonBerg on Monday March 10, 2014 @05:17PM (#7375746)
Wonderful! Great writing too, very clear and intuitive.
Re:The Littlest CPU Rasterizer by mrcactu5 on Monday March 10, 2014 @06:57PM (#7376241)
i was trying to build a word cloud algorithm and then I had a question: how do you rasterize letter shapes?

I looked at pyCairo but I couldn't figure out how to use it. http://cairographics.org/documentation/pycairo/3/

I asked on StackOverflow no answer http://stackoverflow.com/questions/21915335/getting-the-bitm...

i found the true-type format shape files and extracted polygons from those - which i also don't know how to rasterize.

i know this not really a response to the posted link - which is very low level and interesting - but maybe someone here knows an answer.

Re:The Littlest CPU Rasterizer by ginsweater on Monday March 10, 2014 @09:56PM (#7376960)
I like stb_truetype myself. It's C so you'll have to bind it if you're using any other language, but it's a lot simpler than Freetype. (Less features too, but it'll take a .ttf and return a bitmap, which sounds like what you want.)

http://nothings.org/stb/stb_truetype.h

Re:The Littlest CPU Rasterizer by userbinator on Monday March 10, 2014 @10:46PM (#7377122)
It's always great to see things that people would consider nontrivial programming tasks being done with a much smaller amount of code than they would expect from looking at the more "mainstream" libraries that do it. Public domain is a big bonus too.

In comparison, Freetype is absolutely monsterous; it is a few times faster according to some benchmarks I've found, but a few orders of magnitude bigger too. Sometimes you don't need the fastest, you just want something simple that works.

Re:The Littlest CPU Rasterizer by cscheid on Monday March 10, 2014 @08:13PM (#7376603)
If you have access to a GPU (or can evaluate quadratic functions of barycentric coordinates) Loop and Blinn's 2005 algorithm is brilliant http://research.microsoft.com/en-us/um/people/cloop/loopblin...
Re:The Littlest CPU Rasterizer by dman on Monday March 10, 2014 @11:19PM (#7377214)
That technique is patented.
Re:The Littlest CPU Rasterizer by ANTSANTS on Monday March 10, 2014 @07:30PM (#7376404)
I think FreeType is the go-to solution for text rendering.

http://www.freetype.org/

My take on the word cloud problem:

  1. Sort words by frequency. Map the highest and lowest frequencies to some maximum and minimum font size.
  2. Render each word into an individual image with FreeType.
  3. Find some pleasing way to arrange the word images using only their bounding boxes.
  4. Render the word images into a final image, picking a random pleasant color to tint each word as you go.
EDIT: Or did you mean, "how does font rendering work"? In that case, I think it mostly boils down to rasterizing line segments and Bezier curves, along with algorithms for kerning and for trying to fit the text to the pixel grid. FreeType's documentation goes into great detail about what exactly a modern text renderer has to deal with, yet I found it to be very accessible as someone with little prior knowledge of the field. I recommend giving it a look:

http://www.freetype.org/freetype2/documentation.html

Re:The Littlest CPU Rasterizer by ginko on Monday March 10, 2014 @07:20PM (#7376353)
For concave shapes like letters the best choice would probably be a scanline-based rasterization algorithm.

Sort all polygon edges from top to bottom and walk through that list line-by-line, keeping track of all active edges for each scanline. For those you can then find all intersections and fill the ranges in-between. By using an even-odd rule you can make sure that concave polygons and polygons with holes are filled properly.

Re:The Littlest CPU Rasterizer by ginsweater on Monday March 10, 2014 @10:16PM (#7377033)
I wrote one of those once! It was a nightmare morass of one-pixel errors. Maybe there was some clever simplification I missed that would have made it all easy, but these days I use the libraries. :P

I know that's how stb_truetype's renderer works, incidentally. Don't know if Freetype is the same, but I'd be mildly surprised to find it wasn't.

Re:The Littlest CPU Rasterizer by userbinator on Monday March 10, 2014 @08:51PM (#7376751)
Reminds me of the sorts of techniques used in 4/64K demos.
Re:The Littlest CPU Rasterizer by wolfgke on Monday March 10, 2014 @06:02PM (#7375981)
Where can I find the complete source code?
Re:The Littlest CPU Rasterizer by gavanwoolery on Tuesday March 11, 2014 @05:20AM (#7378177)
Looks good! Are your models procedurally generated or did you create them in an external program?