Jump to content

- - - - -

Text and filled shapes for the dsPIC33 VDC



2: Adsense

The dsPIC33 video display controller project I am working on needs to support several common text output and drawing operations offered by existing BBC BASIC implementations. The previous demo included basic point, line and circle outlining functions, but I also need to output text and outline (or fill) rectangles, circles, ellipses and triangles. On top of that the drawing operations need to support multiple colours and plotting modes. Owing to processing power and memory limitations the output is black and white only but different "shades" can be implemented with dither patterns. The plotting modes allow you to perform logical operations between what you are drawing and what's currently on the buffer — for example, you could fill a circle that is logically ORed with the existing background or draw a line that inverts every pixel along its length rather than applying the new colour.

dsPIC33 VDC text output demo
Filled rectangles and text output produce the above image.

Finding suitable algorithms for some of these routines has been a little tricky at times. Due to the way that filled shapes can be set to invert (rather than overwrite) what's on the background there has to be zero overdraw and the outline of filled triangles should exactly match the outline of a triangle drawn by plotting a line between its three vertices; this makes combining triangles to form more complex shapes possible, as you can guarantee that the overlap between the two shared vertices of a pair of triangles covers the same pixels as a line drawn between those two vertices.

dsPIC33 VDC spinning cube demo
Filled triangles produce a solid cube.

I ended up writing a program in C# that would plot a random triangle using the triangle filler I was attempting to write and then compare its outline to that of a triangle drawn by plotting lines between the three vertices. The final code is chock full of special cases and workarounds but has been tested against hundreds of thousands of random triangles and seems to be working!


Download a schematic for the project.

Due to a shortage of memory there is only a single frame buffer, which (naturally) means there is no double-buffering and hence smooth animation becomes a little tricky. When connected to a TV one can take advantage of the vertical blanking period to update the buffer (this is a period below and above the active display where you only need to feed sync signals, not image data, to the TV) and still get decent effects as long as you don't try to do too much. The LCD has no such vertical blanking period and so some of the demos look rather flickery.

dsPIC33 VDC demo video
View the demonstration video on YouTube

I have captured a video of the output of the circuit when running the demo which can be seen above. The horizontal grey lines are a limitation of my video capture card; these lines appear correctly as alternating black and white pixels on a real TV set! You can download the code for this demo from my site along with a PDF of the schematic. As this is a work in progress I'm sure there are plenty of bugs left to squash but I think it's getting there, slowly but surely!

Jul 23 2010 08:27 AM
Very nice work as always.
It seems fast. I expected that full screen graphics would look slow but your demo looks good.
Jul 23 2010 10:26 AM
Quote:
Original post by jbb
It seems fast. I expected that full screen graphics would look slow but your demo looks good.
Thanks! Yes, I was quite impressed by the speed of the dsPIC as virtually all of the code is written in unoptimised C (the only bit that's in assembly is the interrupt handler that periodically outputs something to the TV). It is running at 40 MIPS, though, and as I only output 240 scanlines that leaves a lot of time to update the buffer during the vertical blanking period.
Jul 24 2010 07:38 AM
Quote:
The horizontal grey lines are a limitation of my video capture card; these lines appear correctly as alternating black and white pixels on a real TV set!
If you think that's bad, then wait... Project MD is going to make that capture card hate you forever with the flickering.

Are those spheres rendered as triangles or is there some specific algorithm? I know some old 3D games would render spherical shapes as real circles rather than lo-poly shapes, so maybe there's some trick to it.

Eh, I should get the source code, I guess =P
Jul 24 2010 10:49 AM
Quote:
Original post by Sik_the_hedgehog
If you think that's bad, then wait... Project MD is going to make that capture card hate you forever with the flickering.
I saw the video on YouTube and it looks great! [grin]
Quote:
Are those spheres rendered as triangles or is there some specific algorithm?
They're just filled circles stacked on top of eachother, starting with a large dim circle and moving towards a small bright circle. The smaller the circle is the more it is offset towards the middle of the screen to give the impression of an overhead light source.

Note: GameDev.net moderates comments.