GRaphics: LCD and Contexts

In this section, you will learn about:

Before we dive into using the TI Graphics Library, let's take a look at the specifications of the LCD screen. Here is a snippet from the BoosterPack User Guide:

There are lot of words, but the important takeaways are these:

Graphics can be rather complicated to operate efficiently. As such, an important tool is used when operating with graphics functions: contexts. A graphics context is simply a group of settings used by the graphics driver. Whenever you call a graphics function, you will almost always pass a graphics context as a parameter to the function. For the sake of simplicity, it is strongly recommended to only use one context. The snippet below is taken from the file located at <ti/grlib/grlib.h> and shows what settings are contained within the Graphics_Context struct:

For now, let's focus on the foreground and background (we will talk about fonts in a later page). The foreground is the color used to draw new graphics objects on the LCD screen, whereas the background is the color that fills the screen when the screen has been cleared. The foreground and background are similar to using Microsoft Paint. In the screenshot below, black (Color 1) serves as the background color and white (Color 2) is the foreground color.

It's worth noting that the foreground color works especially like Microsoft Paint. Changing the foreground color has no impact on graphics that were already drawn on the screen. Notice how Color 2 (which was white in the previous example) has been changed to red, but the image is still the same.

While the old graphics are still in white, the new ones are now in red!

The analogy somewhat falls apart with changing the background color, though. In this example, Color 1 is now blue, but the graphics have not changed. This is also what happens with the LCD -- changing the background color has no immediate effect.

In Microsoft Paint, you can (mostly) change the background by using the fill tool without erasing what you had previously.

This is not the case with the LCD. The background will only update to the new color after the screen has been cleared. Thus, the only way to see the new background color is to call Graphics_clearDisplay().