Digital Clock

7 May 2011 17:03
Last Modified
13 Jan 2013 18:21

I was thinking about approaches for displaying the date and time in XNA applications. The easiest approach is simply to use the SpriteBatch class and render a string, however I wanted to be able to support a display of arbitrary sizes, which can be problemmatic with rasterized fonts.

I could use a set of vector fonts, however I would then have to calculate the vertices dynamically when the date or time changed.

An interesting alternative is to pre-generate the vertices for a digital clock. In this way, I have all the vertices I need in a VertexBuffer and can decide the colors for each segment on the GPU after passing the date and time as an effect parameter. An initial screenshot is shown in Figure 1.

Digital Clock

Figure 1. Digital Clock.

The "on" and "off" colors are set with effect parameters, and in Figure 1 I have used an "off" color to simulate light-bleed in a physical display.

The geometry is configurable with parameters for segment thickness, size of gap between segments, character spacing, seperator width and slant.

Add Comment