2.6 The basic2 Rendering Routine

Below is the source for vsyncCallback, the basic2 rendering callback function that was just registered. As you can see, this function does nothing itself, but relies on a function called Draw to complete the tasks.

List 2-4 See basic2 "main.c"

void  vsyncCallback(int pendingTaskCount)
{
    Draw();
}

The Draw function directly writes values to the framebuffer holding the video output image, and prepares the image for output. Since the same value is written to all pixels, the screen output is a single color. However, the color changes as time passes. More specifically, since the RGB intensity value is provided by the unsigned char type variable, col, (appropriately multiplied), the screen color gradually changes in proportion to the increase in col.

List 2-5 See basic2 "graphic.c"

/* Function in charge of drawing */
void  Draw(void)
{
  int                     i, j;
  static unsigned char    col = 0;

  /* Directly write into the framebuffer */
  for(j = 0; j < SCREEN_WD * SCREEN_HT; j++)
    nuGfxCfb_ptr[j] = GPACK_RGBA5551(col, 2 * col, 3 * col, 1);
  col++;

  (The rest is omitted)
}

The other processes performed by the Draw function will be explained in a later chapter.