2-5 2D Rendering Process


The N64 displays 2D images using the same process it uses to display polygons. In reality, 2D images are just polygons with texture data pasted on them.


2-5-1 Kinds of 2D Images


To display a 2D image, the N64 uses two kinds of library functions:

The 2D images drawn can be moved in the X or Y directions or be rotated. Note: Rotation is currently not supported.



2-5-2 Procedure

The actual procedure is best illustrated with a sample program (2d.c). See [Appendix C Sample Description] about the sample program. Note that the gfx function is not a standard N64 function. It is defined within the 2D sample for use by that sample.


1. Main 2D Drawing Routine
The main drawing routine forms the executing core for the 2D image drawing sample. As a process flow, first construct the display list and enter (transfer) it into the RCP. The RCP creates the actual displaying data and outputs the video signal via the frame buffer.

void entry(void)
{
 Gfx *gp;  /* points to display list */
 u16 w, h;

 w=64; h=64;  /* sets up sprite size */
 while(1){


  • Construct the display list

  • The following code reserves the necessary memory area for the construction of the display list, sets up the RCP execution process for sprite drawing in the reserved area, and provides a termination process for the constructed display list.

    /* Start to construct a display list */
       gp = gfxBegin(1024);
       
    This code checks to see if a display list has already been constructed. If a display list has not been completed, this code reserves the GBI command area for new construction. If it has been completed, this code moves on to step 2, the process that transfers the display list to the RCP.


    /* Set the drawing mode for RSP and RDP */
       gp = setup_SP_DP(gp);
    This code constructs a command that sets the necessary RCP drawing mode, and then adds that command to the display list.


     /* Accept the texture pattern */
        gp = load_texture(gp,w,h);
    This code sets up a texture pattern loading command in the display list.


     /* Write the texture pattern */
       gp = draw_texture(gp,124,92,w,h);
    This code sets up a texture drawing command in the display list.


     /* End the construction of display list */
       gfxEnd(gp);
    This code terminates the display list.
  • Caution 1: Watch out for an unterminated display list. If it is transferred to the RCP, it will cause the RCP to hang (stop responding).
  • Caution 2: be sure to put the gDPFullSync function at the end of each display list. Otherwise, the RDP end message will not ever come.



  • Transfer the display list to the RCP to execute the drawing process

  • The following code transfers the display list to the RCP where the display list is interpreted and executed.


     /* Transfer display list to RCP */
       gfxFlush( ); 
    This code transfers the display list to the RCP where it is executed.
    This function also provides the frame buffer switch that writes the created image data into the frame buffer.


  • Synchronize the CPU with the RCP

  • The following function ensures coordination between the CPU and RSP:

     /* Wait for the retrace */
       gfxWaitSync( );
    } }


    2. Techniques for Construction of the Display List
    The actual construction of the display list uses one of these processes:
  • Set the RSP and RDP Drawing Modes

  • The following routines set the RCP drawing mode that actually creates the commands that render the drawing reflected in the display list. The gSP and gDP functions are included in the N64 library. For more information, please see the online "N64 Function Reference Manual" (HTML manual pages).

    static Gfx *setup_SP_DP(Gfx *gp)
         {
    /* Set all sorts */
    
    /* Set the texturing parameter */
     gSPTexture(gp++,0x8000,0x8000,0,G_TX_RENDERTILE,G_ON);
    
    /* The synchronous setting between the rendering and  sub-attribute*/
     gDPPipeSync(gp++);
    /* Set the RDP cycle type */ gDPSetCycleType(gp++,G_CYC_COPY); /* Set the rendering mode of the blender within RDP */ gDPSetRenderMode(gp++,G_RM_NOOP,G_RM_NOOP2); /* Set the textureLOD */ gDPSetTextureLOD(gp++,G_TL_TILE); /* Set the perspective of the texture map */ gDPSetTexturePersp(gp++,G_TP_NONE); /* Set the detail type */ gDPSetTextureDetail(gp++,G_TD_CLAMP); /* Set the texture filter type */ gDPSetTextureFilter(gp++,G_TF_BILERP); /* Set the conversion mode of the color space */ gDPSetTextureConvert(gp++,G_TC_FILT); /* Set the compare mode of the alpha value */ gDPSetAlphaCompare(gp++,G_AC_NONE); /* Set the dithering mode of the color data */ gDPSetColorDither(gp++,G_CD_DISABLE); /* Set the dithering mode of the alpha value */ gDPSetAlphaDither(gp++,G_AD_NOISE); return gp; }


  • Set and Read the Texture

  • The gDP functions are included in the N64 library. For more information, please see the online "N64 Function Reference Manual" (HTML manual pages).

    static Gfx *load_texture(Gfx *gp,u16 w,u16 h)
    {
    /* Read TLUT */
    
    /* Set the texture look-up table */
     gDPSetTextureLUT(gp++,G_TT_RGBA16);
    
    /* Read the texture look-up table */
     gDPLoadTLUT_pal16(gp++,0,texturetlut);
    
    /* Read the bitmap pattern */
     gDPLoadTextureTile_4b(gp++,texture,G_IM_FMT_CI,w,h,
      0,0,w-1,h-1,0,
      G_TX_WRAP | G_TX_NOMIRROR,G_TX_WRAP |
      G_TX_NOMIRROR,
      G_TX_NOMASK,G_TX_NOMASK,G_TX_NOLOD,
      G_TX_NOLOD);
    
      return gp;
      }


  • Set the Drawing Sequence for a Bitmap Pattern

  • The following code sets the drawing sequence for an accepted texture image. The gSP functions are included in the N64 library. For more information, please see the online "N64 Function Reference Manual" (HTML manual pages).

    static Gfx *draw_texture(Gfx *gp,u16 left,u16 top,u16 w,u16 h)
    {
    /* The bitmap pattern drawing */
     gSPTextureRectangle(gp++,
      left<<2,top<<2,((left+w)<<2)-1,((top+h)<<2)-1,
      G_TX_RENDERTILE,
      0,0,4<<10,1<<10);
     return gp;
    }