Sunday, August 19, 2012

µGL - embedded text-mode OpenGL driver (2002)

For ECE354, at UW, we had to write a real-time OS which ran on ColdFire.  To demonstrate the multitasking abilities of the OS, one of the programs we had to write was a clock.  Thinking it through I thought it would be cool to render the clock using ASCII art, and, well, if in 2D, why not in 3D... so µGL was born.

µGL is a little wireframe-only OpenGL driver I wrote for our OS.  Its main particularity is that it renders in text mode over a serial port using VT100 escape codes to move the cursor around, using good old dirty rectangles to only update the required portions of the screen on the client terminal.

It uses extended ASCII characters 32, 219, 220 and 223, which look like little boxes, to double the number of vertical resolution lines.  These characters allow µGL to divide a single text character into two "pixels", one above the other.  32 is a space, so the background color shows everywhere; 220 is a character where only the bottom half is the foreground color; 223 is a character where the top half is the foreground color; and 219 is a character where the entire character is the foreground color.  These four combinations represent all possible states for two pixels, which allows the vertical resolution on the client to be doubled, and the aspect ratio of individual pixels to be brought much closer to 1.

How vertical resolution is double.  (Click to embiggen.)
I am not familiar with the entire line of ColdFire products, but the 5206 units we used at UW did not have hardware support for floating-point numbers, or even an integer division instruction.   To remedy this, I used fixed-point for all the math and rolled my own assembler division.  I was not overly worried about performance because the vast majority of time was sending serial data anyway, and the project was more about being amusing than pushing the metal.  (This partly explains why I never went through the trouble of making the display subpixel-accurate, though this would likely have resulted in much of a quality improvement on such a low-resolution display.)

No comments:

Post a Comment

FT Tiny Trainer (2015)

After flying the Towel for quite some time, I decided it was time for a slightly more complex RC plane project.  Browsing the Flite Test s...