/********************************************************************************************/
/* CONFIDENTIAL AND PROPRIETARY:                                                            */
/*      Copyright 1998, Sega of America.  All rights reserved.                              */
/*      This sample source code is provided for demonstration purposes only.                */
/*      Use and distribution of Sega proprietary material is governed by                    */
/*      developer licensing agreement.                                                      */
/********************************************************************************************/

/********************************************************************************************/
/* Name:     QuikTest.c                                                                     */
/* Title:    QuickTest Example                                                              */
/* Author:   Gary Lake                                                                      */
/* Created:  April 8, 1998                                                                  */
/*                                                                                          */
/* Version:  0.1                                                                            */
/* Platform: Katana | Windows 95 | Kamui                                                    */
/*                                                                                          */
/* Description:                                                                             */
/*      The purpose of this example is to provide an extremely simple test program          */
/*      that also demonstrates some basic Kamui optimizations.                              */
/*                                                                                          */
/* History:                                                                                 */
/*      4/8/98 - Program created (Gary Lake).                                               */
/********************************************************************************************/


#include    <stdlib.h>
#include	<stdio.h>
#include	<io.h>					/* for _filelength */
#include	<FCNTL.H>				/* for _open switches */
#include    "kamui.h"

#define CTX_MASK_ALL   (KM_PARAMTYPE | KM_LISTTYPE | KM_COLORTYPE | KM_UVFORMAT |       \
                        KM_DEPTHMODE | KM_CULLINGMODE | KM_SCREENCOORDINATION |         \
                        KM_SHADINGMODE | KM_MODIFIER | KM_ZWRITEDISABLE |               \
                        KM_SRCBLENDINGMODE | KM_DSTBLENDINGMODE | KM_SRCSELECT |        \
                        KM_DSTSELECT | KM_FOGMODE | KM_USESPECULAR | KM_USEALPHA |      \
                        KM_IGNORETEXTUREALPHA | KM_CLAMPUV | KM_FLIPUV |                \
                        KM_FILTERMODE | KM_SUPERSAMPLE | KM_MIPMAPDADJUST |             \
                        KM_TEXTURESHADINGMODE | KM_COLORCLAMP | KM_PALETTEBANK)

KMVERTEXCONTEXT OpaqueColorContext =
{
    CTX_MASK_ALL, KM_POLYGON, KM_OPAQUE_POLYGON, KM_FLOATINGCOLOR, KM_32BITUV,
    KM_GREATER, KM_CULLCCW, KM_SCREEN, KM_NOTEXTUREGOURAUD, KM_NOMODIFIER,
    FALSE, KM_ONE, KM_ZERO, FALSE, FALSE, KM_NOFOG, FALSE, FALSE, FALSE,
    KM_NOCLAMP, KM_NOFLIP, KM_POINT_SAMPLE, FALSE, 0x4, KM_MODULATE, FALSE,
    0, 0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
    0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0.0f
};

KMVERTEXCONTEXT OpaqueTextureContext =
{
    CTX_MASK_ALL, KM_POLYGON, KM_OPAQUE_POLYGON, KM_FLOATINGCOLOR, KM_32BITUV,
    KM_GREATER, KM_CULLCCW, KM_SCREEN, KM_TEXTUREGOURAUD, KM_NOMODIFIER,
    FALSE, KM_ONE, KM_ZERO, FALSE, FALSE, KM_NOFOG, FALSE, FALSE, FALSE,
    KM_NOCLAMP, KM_NOFLIP, KM_BILINEAR, FALSE, 0x4, KM_MODULATE, FALSE,
    0, 0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
    0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0.0f
};

KMVERTEXCONTEXT TransparentTextureContext =
{
    CTX_MASK_ALL, KM_POLYGON, KM_TRANS_POLYGON, KM_FLOATINGCOLOR, KM_32BITUV,
    KM_GREATER, KM_CULLCCW, KM_SCREEN, KM_TEXTUREGOURAUD, KM_NOMODIFIER,
    FALSE, KM_SRCALPHA, KM_INVSRCALPHA, FALSE, FALSE, KM_NOFOG, FALSE, TRUE, FALSE,
    KM_NOCLAMP, KM_NOFLIP, KM_BILINEAR, FALSE, 0x4, KM_MODULATE_ALPHA, FALSE,
    0, 0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
    0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0.0f
};


/****************************************************************************/
/**	Load texture ************************************************************/
/****************************************************************************/
PKMDWORD LoadTextureFile(char *filename)
{
	int			hFile;
	long		filelen;
	PKMDWORD	pTexture;

	/* Open input file */
	hFile = _open(filename, _O_RDONLY | _O_BINARY);
	if(hFile != -1) {
		filelen = _filelength(hFile);			// length of texture file
		pTexture = (PKMDWORD)malloc(filelen);	// allocate mainmemory
		_read(hFile, pTexture, filelen);		// read in texture file
		_close(hFile);							// file close
	}
	else {
		printf("LoadTextureFile: ERROR Can not read file %s.\n",filename);
	}
	return pTexture;
}


int main (void)
{
    KMVERSIONINFO       VersionInfo;            /* Kamui version information. */
    KMSURFACEDESC       PrimarySurfaceDesc;     /* Primary framebuffer. */
    KMSURFACEDESC       BackSurfaceDesc;        /* Back framebuffer surface. */
    KMSURFACEDESC       TexSurfaceDesc;         /* Texture surface. */
    KMVERTEXBUFFDESC    VertexBufferDesc;       /* Vertex buffer. */
    KMVERTEX_01         CurrentStrip_01[16];    /* Strip of opaque color triangles. */
    KMVERTEX_05         CurrentStrip_05[16];    /* Strip of textured triangles. */
    PKMVERTEX_01        BackPlane[3];           /* Background plane. */
    PKMDWORD            pTexture;               /* Pointer to texture. */
    int                 i;
    float               Red = 0.0f, Green = 0.0f, Blue = 0.0f;      /* Gradient colors. */
    float               ColorDelta = 0.01f;

    /* Tell the user about this app. */
    printf ("QuickTest: Simple test demonstrates some useful Kamui optimizations.\n\n");

    /* Check Kamui version and memory information. */
    kmGetVersionInfo (&VersionInfo);
    printf ("Kamui Version =\n");
    printf ("  Major Version: %d\n", VersionInfo.kmMajorVersion);
    printf ("  Minor Version: %d\n", ((VersionInfo.kmLocalVersion >> 24) & 0xFF));
    printf ("  Major Build:   %d\n", ((VersionInfo.kmLocalVersion >> 16) & 0xFF));
    printf ("  Minor Build:   %d\n\n", (VersionInfo.kmLocalVersion & 0xFFFF));
    printf ("VRAM size %d bytes.\n", VersionInfo.kmFrameBufferSize);

    /* Initialize the display device (VGA/PAL/NTSC). */
    kmInitDevice (KM_VGA);

    /* Set the frame buffer display mode. */
    kmSetDisplayMode (KM_DSPMODE_VGA, KM_DSPBPP_RGB565, FALSE, FALSE);

    /* Allocate memory for vertex buffers (opaque, modifier, transparent, trans-modifier) */
    kmCreateVertexBuffer (&VertexBufferDesc, 131072, 0, 131072, 0);
    //kmCreateTABuffer (&VertexBufferDesc, 262144);

    /* Allocate front and back framebuffer surfaces. */
    kmCreateFrameBufferSurface (&PrimarySurfaceDesc, 640, 480, FALSE, FALSE);
    kmCreateFrameBufferSurface (&BackSurfaceDesc, 640, 480, FALSE, FALSE);

    /* Tell Kamui to use these two framebuffers for page flipping. */
    kmActivateFrameBuffer (&PrimarySurfaceDesc, &BackSurfaceDesc, FALSE, FALSE);

    /* Create a texture surface. */
    kmCreateTextureSurface (&TexSurfaceDesc, 128, 128,
        (KM_TEXTURE_TWIDDLED | KM_TEXTURE_RGB565));

    /* Load a texture file from disk, then load the texture data into VRAM. */
    pTexture = LoadTextureFile (".\\PVRLogo.pvr");
    kmLoadTexture (&TexSurfaceDesc, pTexture + (16 / sizeof (KMDWORD)), FALSE, FALSE);
    free (pTexture);

    /* Pre-process the vertex context for opaque textures, using the loaded texture. */
    OpaqueTextureContext.pTextureSurfaceDesc = &TexSurfaceDesc;
    kmProcessVertexRenderState (&OpaqueTextureContext);

    /* Pre-process the vertex context for transparent textures, using the loaded texture. */
    TransparentTextureContext.pTextureSurfaceDesc = &TexSurfaceDesc;
    kmProcessVertexRenderState (&TransparentTextureContext);

    /* Pre-process the vertex context for opaque non-textured color polygons. */
    kmProcessVertexRenderState (&OpaqueColorContext);

    /* Initialize the background plane to point to each vertex in a screen-sized strip. */
    for (i = 0; i < 3; i++)
        BackPlane[i] = &CurrentStrip_01[i];

    /* The main render loop. */
    while (TRUE)
    {
        /* Set background plane render state to opaque color. */
        kmSetBackGroundRenderState (&OpaqueColorContext);

        /* Set the vertices of the background plane for a nice color gradient. */
        /* NOTE: Yes, you can change the background plane on-the-fly. */
        CurrentStrip_01[0].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_01[0].fX                   =   0.0f;
        CurrentStrip_01[0].fY                   = 480.0f;
        CurrentStrip_01[0].fZ                   =   0.2f;
        CurrentStrip_01[0].fBaseAlpha           =   1.0f;
        CurrentStrip_01[0].fBaseRed             =   0.0f;
        CurrentStrip_01[0].fBaseGreen           =   0.0f;
        CurrentStrip_01[0].fBaseBlue            =   0.0f;

        CurrentStrip_01[1].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_01[1].fX                   =   0.0f;
        CurrentStrip_01[1].fY                   =   0.0f;
        CurrentStrip_01[1].fZ                   =   0.2f;
        CurrentStrip_01[1].fBaseAlpha           =   1.0f;
        CurrentStrip_01[1].fBaseRed             =   Red;
        CurrentStrip_01[1].fBaseGreen           =   Green;
        CurrentStrip_01[1].fBaseBlue            =   Blue;

        CurrentStrip_01[3].ParamControlWord     = KM_VERTEXPARAM_ENDOFSTRIP;
        CurrentStrip_01[2].fX                   = 640.0f;
        CurrentStrip_01[2].fY                   = 480.0f;
        CurrentStrip_01[2].fZ                   =   0.2f;
        CurrentStrip_01[2].fBaseAlpha           =   1.0f;
        CurrentStrip_01[2].fBaseRed             =   0.0f;
        CurrentStrip_01[2].fBaseGreen           =   0.0f;
        CurrentStrip_01[2].fBaseBlue            =   0.0f;

        /* Set the background plane to the vertices filled in above. */
        kmSetBackGroundPlane (BackPlane, KM_VERTEXTYPE_01, sizeof (KMVERTEX_01));

        /* Update colors - just to show we're doing something. */
        if (Blue < 0.99)
        {
            Blue += ColorDelta;
            if (ColorDelta < 0)
            {
                Red += ColorDelta;
                Green += ColorDelta;
            }
        }
        else
        {
            if (Red > 0.99)
            {
                ColorDelta = -ColorDelta;
                Blue += ColorDelta;
            }
            Red += ColorDelta;
            Green += ColorDelta;
        }

        if (Blue < 0.0)
        {
            Blue = 0.0;
            Red = 0.0;
            Green = 0.0;
            ColorDelta = 0.01f;
        }

        /* Set Kamui's global render state for opaque non-textured color polygons. */
        kmSetVertexRenderState (&OpaqueColorContext);

        /* Start rendering opaque color strips. */
        kmStartVertexStrip (&VertexBufferDesc);
        //kmStartVertexStripDirect();

        /* Set the vertices in the current strip to draw a colorful square. */
        CurrentStrip_01[0].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_01[0].fX                   = 210.0f;
        CurrentStrip_01[0].fY                   = 290.0f;
        CurrentStrip_01[0].fZ                   =  10.0f;
        CurrentStrip_01[0].fBaseAlpha           =   1.0f;
        CurrentStrip_01[0].fBaseRed             =   1.0f;
        CurrentStrip_01[0].fBaseGreen           =   0.0f;
        CurrentStrip_01[0].fBaseBlue            =   0.0f;

        CurrentStrip_01[1].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_01[1].fX                   = 210.0f;
        CurrentStrip_01[1].fY                   = 190.0f;
        CurrentStrip_01[1].fZ                   =  10.0f;
        CurrentStrip_01[1].fBaseAlpha           =   1.0f;
        CurrentStrip_01[1].fBaseRed             =   0.0f;
        CurrentStrip_01[1].fBaseGreen           =   1.0f;
        CurrentStrip_01[1].fBaseBlue            =   0.0f;

        CurrentStrip_01[2].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_01[2].fX                   = 310.0f;
        CurrentStrip_01[2].fY                   = 290.0f;
        CurrentStrip_01[2].fZ                   =  10.0f;
        CurrentStrip_01[2].fBaseAlpha           =   1.0f;
        CurrentStrip_01[2].fBaseRed             =   0.0f;
        CurrentStrip_01[2].fBaseGreen           =   0.0f;
        CurrentStrip_01[2].fBaseBlue            =   1.0f;

        CurrentStrip_01[3].ParamControlWord     = KM_VERTEXPARAM_ENDOFSTRIP;
        CurrentStrip_01[3].fX                   = 310.0f;
        CurrentStrip_01[3].fY                   = 190.0f;
        CurrentStrip_01[3].fZ                   =  10.0f;
        CurrentStrip_01[3].fBaseAlpha           =   1.0f;
        CurrentStrip_01[3].fBaseRed             =   0.0f;
        CurrentStrip_01[3].fBaseGreen           =   0.0f;
        CurrentStrip_01[3].fBaseBlue            =   0.0f;

        /* NOTE: All four vertices can be set at once by providing size * num vertices. */
        kmSetVertex (&VertexBufferDesc, CurrentStrip_01,
            KM_VERTEXTYPE_01, 4 * sizeof (KMVERTEX_01));
        //kmSetVertexDirect (CurrentStrip_01, KM_VERTEXTYPE_01, 4 * sizeof (KMVERTEX_01));

        /* Set Kamui's global render state for opaque textures. */
        kmSetVertexRenderState (&OpaqueTextureContext);

        /* Start rendering opaque textured strips. */
        kmStartVertexStrip (&VertexBufferDesc);
        //kmStartVertexStripDirect();

        /* Set the vertices in the current strip to draw a textured square. */
        CurrentStrip_05[0].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[0].fX                   = 270.0f;
        CurrentStrip_05[0].fY                   = 240.0f;
        CurrentStrip_05[0].fZ                   =  11.0f;
        CurrentStrip_05[0].fU                   =   0.0f;
        CurrentStrip_05[0].fV                   =   0.836f;
        CurrentStrip_05[0].fBaseAlpha           =   1.0f;
        CurrentStrip_05[0].fBaseRed             =   1.0f;
        CurrentStrip_05[0].fBaseGreen           =   0.0f;
        CurrentStrip_05[0].fBaseBlue            =   0.0f;

        CurrentStrip_05[1].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[1].fX                   = 270.0f;
        CurrentStrip_05[1].fY                   = 140.0f;
        CurrentStrip_05[1].fZ                   =  11.0f;
        CurrentStrip_05[1].fU                   =   0.0f;
        CurrentStrip_05[1].fV                   =   0.0f;
        CurrentStrip_05[1].fBaseAlpha           =   1.0f;
        CurrentStrip_05[1].fBaseRed             =   0.0f;
        CurrentStrip_05[1].fBaseGreen           =   1.0f;
        CurrentStrip_05[1].fBaseBlue            =   0.0f;

        CurrentStrip_05[2].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[2].fX                   = 370.0f;
        CurrentStrip_05[2].fY                   = 240.0f;
        CurrentStrip_05[2].fZ                   =  11.0f;
        CurrentStrip_05[2].fU                   =   0.625f;
        CurrentStrip_05[2].fV                   =   0.836f;
        CurrentStrip_05[2].fBaseAlpha           =   1.0f;
        CurrentStrip_05[2].fBaseRed             =   0.0f;
        CurrentStrip_05[2].fBaseGreen           =   0.0f;
        CurrentStrip_05[2].fBaseBlue            =   1.0f;

        CurrentStrip_05[3].ParamControlWord     = KM_VERTEXPARAM_ENDOFSTRIP;
        CurrentStrip_05[3].fX                   = 370.0f;
        CurrentStrip_05[3].fY                   = 140.0f;
        CurrentStrip_05[3].fZ                   =  11.0f;
        CurrentStrip_05[3].fU                   =   0.625f;
        CurrentStrip_05[3].fV                   =   0.0f;
        CurrentStrip_05[3].fBaseAlpha           =   1.0f;
        CurrentStrip_05[3].fBaseRed             =   0.0f;
        CurrentStrip_05[3].fBaseGreen           =   0.0f;
        CurrentStrip_05[3].fBaseBlue            =   0.0f;

        kmSetVertex (&VertexBufferDesc, CurrentStrip_05,
            KM_VERTEXTYPE_05, 4 * sizeof (KMVERTEX_05));
        //kmSetVertexDirect (CurrentStrip_05, KM_VERTEXTYPE_05, 4 * sizeof (KMVERTEX_05));

        /* Tell Kamui we're done with opaque polygon data. */
        //kmSetEndOfListDirect();

        /* Set Kamui's global render state for transparent textures. */
        kmSetVertexRenderState (&TransparentTextureContext);

        /* Start transparent opaque textured strips. */
        kmStartVertexStrip (&VertexBufferDesc);
        //kmStartVertexStripDirect();

        /* Set the vertices in the current strip to draw a transparent textured square. */
        CurrentStrip_05[0].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[0].fX                   = 270.0f;
        CurrentStrip_05[0].fY                   = 340.0f;
        CurrentStrip_05[0].fZ                   =  21.0f;
        CurrentStrip_05[0].fU                   =   0.0f;
        CurrentStrip_05[0].fV                   =   0.836f;
        CurrentStrip_05[0].fBaseAlpha           =   0.25f;
        CurrentStrip_05[0].fBaseRed             =   1.0f;
        CurrentStrip_05[0].fBaseGreen           =   0.0f;
        CurrentStrip_05[0].fBaseBlue            =   0.0f;

        CurrentStrip_05[1].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[1].fX                   = 270.0f;
        CurrentStrip_05[1].fY                   = 240.0f;
        CurrentStrip_05[1].fZ                   =  21.0f;
        CurrentStrip_05[1].fU                   =   0.0f;
        CurrentStrip_05[1].fV                   =   0.0f;
        CurrentStrip_05[1].fBaseAlpha           =   0.25f;
        CurrentStrip_05[1].fBaseRed             =   0.0f;
        CurrentStrip_05[1].fBaseGreen           =   1.0f;
        CurrentStrip_05[1].fBaseBlue            =   0.0f;

        CurrentStrip_05[2].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[2].fX                   = 370.0f;
        CurrentStrip_05[2].fY                   = 340.0f;
        CurrentStrip_05[2].fZ                   =  21.0f;
        CurrentStrip_05[2].fU                   =   0.625f;
        CurrentStrip_05[2].fV                   =   0.836f;
        CurrentStrip_05[2].fBaseAlpha           =   0.25f;
        CurrentStrip_05[2].fBaseRed             =   0.0f;
        CurrentStrip_05[2].fBaseGreen           =   0.0f;
        CurrentStrip_05[2].fBaseBlue            =   1.0f;

        CurrentStrip_05[3].ParamControlWord     = KM_VERTEXPARAM_ENDOFSTRIP;
        CurrentStrip_05[3].fX                   = 370.0f;
        CurrentStrip_05[3].fY                   = 240.0f;
        CurrentStrip_05[3].fZ                   =  21.0f;
        CurrentStrip_05[3].fU                   =   0.625f;
        CurrentStrip_05[3].fV                   =   0.0f;
        CurrentStrip_05[3].fBaseAlpha           =   0.25f;
        CurrentStrip_05[3].fBaseRed             =   0.0f;
        CurrentStrip_05[3].fBaseGreen           =   0.0f;
        CurrentStrip_05[3].fBaseBlue            =   0.0f;

        /* NOTE: We can keep adding vertices, even past an ENDOFSTRIP flag - see below. */
        CurrentStrip_05[4].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[4].fX                   = 330.0f;
        CurrentStrip_05[4].fY                   = 290.0f;
        CurrentStrip_05[4].fZ                   =  20.0f;
        CurrentStrip_05[4].fU                   =   0.0f;
        CurrentStrip_05[4].fV                   =   0.836f;
        CurrentStrip_05[4].fBaseAlpha           =   0.75f;
        CurrentStrip_05[4].fBaseRed             =   1.0f;
        CurrentStrip_05[4].fBaseGreen           =   0.0f;
        CurrentStrip_05[4].fBaseBlue            =   0.0f;

        CurrentStrip_05[5].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[5].fX                   = 330.0f;
        CurrentStrip_05[5].fY                   = 190.0f;
        CurrentStrip_05[5].fZ                   =  20.0f;
        CurrentStrip_05[5].fU                   =   0.0f;
        CurrentStrip_05[5].fV                   =   0.0f;
        CurrentStrip_05[5].fBaseAlpha           =   0.75f;
        CurrentStrip_05[5].fBaseRed             =   0.0f;
        CurrentStrip_05[5].fBaseGreen           =   1.0f;
        CurrentStrip_05[5].fBaseBlue            =   0.0f;

        CurrentStrip_05[6].ParamControlWord     = KM_VERTEXPARAM_NORMAL;
        CurrentStrip_05[6].fX                   = 430.0f;
        CurrentStrip_05[6].fY                   = 290.0f;
        CurrentStrip_05[6].fZ                   =  20.0f;
        CurrentStrip_05[6].fU                   =   0.625f;
        CurrentStrip_05[6].fV                   =   0.836f;
        CurrentStrip_05[6].fBaseAlpha           =   0.75f;
        CurrentStrip_05[6].fBaseRed             =   0.0f;
        CurrentStrip_05[6].fBaseGreen           =   0.0f;
        CurrentStrip_05[6].fBaseBlue            =   1.0f;

        CurrentStrip_05[7].ParamControlWord     = KM_VERTEXPARAM_ENDOFSTRIP;
        CurrentStrip_05[7].fX                   = 430.0f;
        CurrentStrip_05[7].fY                   = 190.0f;
        CurrentStrip_05[7].fZ                   =  20.0f;
        CurrentStrip_05[7].fU                   =   0.625f;
        CurrentStrip_05[7].fV                   =   0.0f;
        CurrentStrip_05[7].fBaseAlpha           =   0.75f;
        CurrentStrip_05[7].fBaseRed             =   0.0f;
        CurrentStrip_05[7].fBaseGreen           =   0.0f;
        CurrentStrip_05[7].fBaseBlue            =   0.0f;

        /* NOTE: A lot of context switching and setup can be avoided by providing several   */
        /*       strips in a single kmSetVertex/Direct() call.                              */
        /*       Don't call kmStartVertexStrip/Direct() for each strip!  This is wasteful.  */
        kmSetVertex (&VertexBufferDesc, CurrentStrip_05,
            KM_VERTEXTYPE_05, 8 * sizeof (KMVERTEX_05));
        //kmSetVertexDirect (CurrentStrip_05, KM_VERTEXTYPE_05, 8 * sizeof (KMVERTEX_05));

        /* Tell Kamui we're done with transparent polygon data. */
        //kmSetEndOfListDirect();

        /* Render the polygons and flip the display. */
        kmRender();
        //kmRenderDirect();
        kmFlipFrameBuffer();
    }

    /* Free vertex buffers. */
    kmDiscardVertexBuffer (&VertexBufferDesc);

    /* Free the texture surface. */
    kmFreeTexture (&TexSurfaceDesc);

    /* Free the frame buffers. */
    kmFreeTexture (&PrimarySurfaceDesc);
    kmFreeTexture (&BackSurfaceDesc);

    /* Stop the display - blank screen. */
    //kmStopDisplayFrameBuffer();

    return 0;
}