Subscribe to WolfCoder's Kawaii Column

## Software Rasterizing Triangles (Realtime Graphics)

I was writing a software fallback GPU for some engine I was working on for fun and the results are pretty standard of what you'd get. The basic idea is you want to map textures onto polygons and use a scanline algorithm to do so.

This is a pretty good diagram of what you do (that I found online because I am lazy). You start at the highest vertex of the triangle and work your way down, minding the side vertex. That pesky side vertex makes the entire algorithm a bit tricky.

The job is to convert the triangle into many horizontal 1-pixel bars (scanlines) and interpolate the texture coordinates on the left side as you go to the right side.

I took this as the texture to use:

And I decided to test it on my own scanline algorithm. I actually benchmarked the algorithm by first drawing 128 frames with 4 rotating images and then adding one rotating image for every frame after that:

I recorded my results in a millisecond histogram (FPS is not a proper way to benchmark graphics):

The top of the graph is 128ms a frame or about 8 FPS. At about 44 images, I hit the top of the graph >.< so I have a little bit of optimizing to do. I'm not too worried, this is only the GPU system my engine will use when there is no good video acceleration available. Video games become somewhat unplayable under 16 FPS which is halfway up my histogram.

This was still a fun little thing to do and I recommend anyone to write their own software rasterizer if they want to learn more about realtime graphics.

### 2 Comments On This Entry

Page 1 of 1

#### Amrykid

12 October 2011 - 02:32 PM
0

#### WolfCoder

22 October 2011 - 10:04 PM
I might. If you're interested in rasterizing your own graphics I might even write the basic intro. It involves tons of Linear Algebra though.
0
Page 1 of 1

S M T W T F S
12
3456789
10111213141516
17181920212223
24 25 2627282930

...