/*----------------------------------------------------------------
   Name   : Fight.c  (ARC1 demo - SGL2 Beta3 version)
   Author : Carlos Sarria
   Date   : September 1997, updated Jan98

   Copyright : 1998 by VideoLogic Limited. All rights reserved.
   Modified  : 10, June, 1998 by Takeshi Muto / NEC Software,Ltd. for KAMUI
 -----------------------------------------------------------------*/

/*
#define		_X86_
*/
/* _X86_ flag for win95 : SET2 */

#define		_DISPLAY_STRING_
/* if defined then display strings on screen */

#define		_DISP_PERFORMANCE_
/* Display performance : for windows */

/* Set Display Mode */
#define NTSC 1

#include	<math.h>
#include	<stdio.h>
#include	<stdlib.h>

#include	<shinobi.h>

/*--
#include	<conio.h>
--*/

#if defined(_X86_)
	#include	<time.h>
	#include	<windows.h>
#endif

#pragma warning (disable : 4244) /* Disables float to double conversion warning */

#include	"kamui.h"				/* for Kamui Call */
#include	"dispstr.h"				/* for DisplayString */
/* #include	"sgl2.h" */
#include	"kmtools.h"
#include "kmFlight.h"  /* This is the file with 3D data */


#if defined(_DISP_PERFORMANCE_)
#if defined(_X86_)
#else
	#include    "QPF.H"                 /* for QueryPerformance */
#endif
#endif

void kmflght2v_SetContext (INFO CInfo);

/****************************************************************************/
/**	Valuables for KAMUI *****************************************************/
/****************************************************************************/
	KMSTATUS			status;					/* return status of KAMUI API */
	KMVERSIONINFO		VersionInfo;			/* KAMUI Version information */
	KMSURFACEDESC		PrimarySurfaceDesc;		/* Primary frame buffer */
	KMSURFACEDESC		BackSurfaceDesc;		/* Back-buffer frame buffer */
	KMVERTEXBUFFDESC	VertexBufferDesc;		/* Vertex-buffer */
	KMVERTEXCONTEXT		VertexContextBat;		/* Vertex context */
	KMVERTEXCONTEXT		VertexContextGround;	/* Vertex context */
	KMVERTEXCONTEXT		VertexContextShadow;	/* Vertex context */
	KMVERTEXCONTEXT		VertexContextFire;		/* Vertex context */
	KMVERTEXCONTEXT		VertexContextThorm;		/* Vertex context */
	KMDWORD				FogDensity;				/* Fog density */
	KMDWORD				FogD = 1;


	int			frame;
	int			frame_2 = 0;
#if defined(_DISP_PERFORMANCE_)
	int			pcount_f;
	double		nFPS;
	double		aFPS;
	double		MxFPS;
	double		MnFPS;
	__int64 	Time3i;
	__int64		freqi;
	double		freq;
	double		Time3;
	double		maxTime = 0.00001;
	double		minTime = 99999;
	double		OldTime3;
	double		nowTime;
	double		totalTime	= 0;
	double		aveTime;
#if defined(_X86_)
	time_t		start_time;
#endif
#endif

/*------------------------------- Global Variables -----------------------------------*/
/* Globals */

/* Not counted. */
unsigned int nTrees = 0;
unsigned int Type = 0;

int			Frame = 0;
float		Ang, PosX, PosY;
/*
unsigned		TexBat,  TexGround, TexShadow, TexFire,  TexL;
*/
KMSURFACEDESC	TexBat,  TexGround, TexShadow, TexFire,  TexThorm;
sgl_vector	X_Axle = { 1, 0,0}, Y_Axle = { 0,1, 0}, Z_Axle = { 0,0, 1};

/* Info Structure */
INFO Info =
{
	FALSE,		/* OpaqMap       */
	TRUE,       /* Textured      */
	TRUE,		/* Gouraud       */
	FALSE,      /* GlobalTrans   */
	FALSE,      /* VertexAlpha   */
	FALSE,		/* TableFog      */
	FALSE,      /* VertexFog     */
	TRUE,       /* Bilinear      */
	TRUE,       /* Highlight     */
};

/* Prototypes */

static void SetTextures			(void);
static void NextFrame			(void);
static void DisplayInformation	(void);
static void DrawToy             (void);

/* Textures */
extern unsigned char Bat;
extern unsigned char Fire;
extern unsigned char Ground;
extern unsigned char Shadow;
extern unsigned char Thorm;

/* Macros for kamui */
#define		GetRED(col)			((KMFLOAT) ( ((col) & 0x00ff0000) >> 16 ) / 256.0f)
#define		GetGREEN(col)		((KMFLOAT) ( ((col) & 0x0000ff00) >>  8 ) / 256.0f)
#define		GetBLUE(col)		((KMFLOAT) ( ((col) & 0x000000ff)       ) / 256.0f)
#define		GetALPHA(col)		((KMFLOAT) ( ((col) & 0xff000000) >> 24 ) / 256.0f)


/*-------------------------------------------------------------------------------------*/
/*                                       MAIN                                          */
/*-------------------------------------------------------------------------------------*/
int main (void)
{
KMPACKEDARGB   cBorder;
int Control = 0, Device, Val = 0;

#ifdef __GNUC__
	shinobi_workaround();
#endif

#if 0
	Device = sgl_create_screen_device (0, 640, 480, sgl_device_16bit, FALSE);
	if (Device<0) return -1;
#endif

	txt_ClearScreen();	/* Clear text screen */
	PRINTOUT(("** Flight 2V Latency Trans Direct **\n\n"));

	/*----------------------------------------------------------------------------------- */
	/* Initialize Hardware */

#if NTSC
	sbInitSystem( NJD_RESOLUTION_640x480_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
#else
	sbInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
#endif

	/* Black Border */
	cBorder.dwPacked	=	0x00000000;
	kmSetBorderColor(cBorder);

	kmGetVersionInfo(&VersionInfo);
	PRINTOUT(("MajorVersion      0x0%08x\n",VersionInfo.kmMajorVersion));
	PRINTOUT(("LocalVersion      0x0%08x\n",VersionInfo.kmLocalVersion));
	PRINTOUT(("kmFrameBufferSize 0x0%08x\n",VersionInfo.kmFrameBufferSize));

	/*----------------------------------------------------------------------------------- */
	/* Set Latency Model */
	kmChangeLatencyModel(KM_LATENCYMODEL_2V, KM_VERTEXBUFMODEL_NOBUF_TRANS);

	/*----------------------------------------------------------------------------------- */
	/* Create vertex buffer */
	status = kmCreateVertexBuffer(&VertexBufferDesc,		/* pBufferDesc */
									262144,					/* Opaque-Polygon 1MB */
									0,						/* Opaque-Modifier */
									262144,					/* Trans-Polygon 1MB */
									0						/* Trans-Modifier */
									);
	Check_Status(status, "kmCreateVertexBuffer");

	/*----------------------------------------------------------------------------------- */
	/* Create primary frame buffer surface */
	status = kmCreateFrameBufferSurface(&PrimarySurfaceDesc,	/* pSurfaceDesc */
								640,	/* nWidth */
								480,	/* nHeight */
								FALSE,	/* bStripBuffer */
								FALSE	/* bBufferClear */
								);
	Check_Status(status, "kmCreateFrameBufferSurface(Primary)");

	/*----------------------------------------------------------------------------------- */
	/* Create backbuffer frame buffer surface */
	status = kmCreateFrameBufferSurface(&BackSurfaceDesc,	/* pSurfaceDesc */
								640,	/* nWidth */
								480,	/* nHeight */
								FALSE,	/* bStripBuffer */
								FALSE	/* bBufferClear */
								);
	Check_Status(status, "kmCreateFrameBufferSurface(Back-buffer)");

	kmSetWaitVsyncCount( 0 );	/* No wait V-Sync */

	/*----------------------------------------------------------------------------------- */
	/* set display surface */
	status = kmActivateFrameBuffer(	&PrimarySurfaceDesc,	/* pSurfaceDesc */
									&BackSurfaceDesc,		/* pSurfaceDesc */
									FALSE,					/* bStripBuffer */
									TRUE					/* bWaitVSync */
									);
	Check_Status(status, "kmActivateFrameBuffer");

	/*-----------------------------------------------------------------------------------*/
	/* Initialize DisplayString routine */
	txt_InitDisplayString();

	/*-----------------------------------------------------------------------------------*/
	/* Set Culling Register */
	status = kmSetCullingRegister(1.0f);
	Check_Status(status, "kmSetCullingRegister");

	/*----------------------------------------------------------------------------------- */
	/* some initializes */
	SetTextures ();
    kmflght2v_SetContext  (Info);
	SetBackground ((PKMSURFACEDESC)NULL);
	DisplayInformation ();

	/*-------------------------------------------------------------------------------- */
	frame		= 0;
#if defined(_DISP_PERFORMANCE_)
	totalTime	= 0;

	pcount_f = QueryPerformanceFrequency((LARGE_INTEGER*)&freqi);
	if(pcount_f) {
		QueryPerformanceCounter((LARGE_INTEGER*)&Time3i);
		freq = 1000.0f / (double)freqi;
		OldTime3 = Time3 = (double)Time3i * freq;
	}
	else {
		Time3 = (double)timeGetTime();
	}

	/* Get AP start time ---------------------------------------------*/
#if defined(_X86_)
	 time( &start_time );
#endif
#endif	/* defined(_DISP_PERFORMANCE_) */

	/*
	 *This function creates an array of structures with 3D data (is in Batwing.h)
	 */
	CreateMeshesArray ();

	InitMeshes (NUM_MESHES, (CASTMESHES *) Mesh);


	while (TRUE)
	{
#if defined(_X86_)
	   while(!kbhit())  NextFrame ();
	   Val = _getch ();

	   switch (Val)
	   {
			case K_ESC:
			case K_F12:
				 goto Finish;

	      	case K_F1 :
			     Info.Bilinear = (Info.Bilinear) ? FALSE:TRUE;
				 DisplayInformation ();
				 break;

			case K_F2 :
				 Info.Gouraud = (Info.Gouraud) ? FALSE:TRUE;
				 DisplayInformation ();
				 break;
			case K_F3 :
				 Info.Textured = (Info.Textured) ? FALSE:TRUE;
				 DisplayInformation ();
				 break;


			case K_F4 :
				 Info.Highlight = (Info.Highlight) ? FALSE:TRUE;
				 DisplayInformation ();
				 break;

			default:
				Timer (RESET_TIME);break;
	   }
	   Val = 0;
#else	/* not _X86_ */
		NextFrame ();
#endif

	}

Finish:

    FreeMeshes (NUM_MESHES);
	/* Don't forget to free all textures when the app finishes   */
/*	FreeAllBMPTextures (); */
/*	sgl_delete_device(Device); */

	/*----------------------------------------------------------------------------------- */
	/* Free vertex buffer */
	status = kmDiscardVertexBuffer(&VertexBufferDesc);
	Check_Status(status, "kmDiscardVertexBuffer");

	/*----------------------------------------------------------------------------------- */
	/* End display */
	status = kmStopDisplayFrameBuffer();
	Check_Status(status, "kmStopDisplayFrameBuffer");

    return 0;
}
/*-------------------------------------------------------------------------------------*/
void SetTextures (void)
{
#if 0
	TexBat	=  LoadBMPTexture("Bat.bmp",	FALSE,	TRUE,	FALSE);
	TexGround	=  LoadBMPTexture("Ground.bmp", FALSE,	TRUE,	FALSE);
	/*TexShadow	=  LoadBMPTexture("Bat.bmp",	TRUE,	TRUE,	FALSE); */
	/*TexFire	=  LoadBMPTexture("Fire.bmp",	FALSE,	TRUE,	FALSE); */
	/*TexL		=  LoadBMPTexture("Thorm.bmp",	TRUE,	TRUE,	FALSE); */

	/*TexBat		=  LoadVQTexture("Bat.vqf"); */
	/*TexGround	=  LoadVQTexture("Ground.vqf"); */
	TexShadow	=  LoadVQTexture("tBat.vqf");
	TexFire		=  LoadVQTexture("Fire.vqf");
	TexL		=  LoadVQTexture("Thorm.vqf");
#endif

	PKMDWORD			pTexture01;				/* Pointer to texture */
	KMTEXTURETYPE		nTextureType;			/* texture type definition */

	/*----------------------------------------------------------------------------------- */
	/* Create texture surface */
	nTextureType = KM_TEXTURE_TWIDDLED_MM | KM_TEXTURE_RGB565;	/* Set texture type */
	status = kmCreateTextureSurface(
		&TexBat,				/* OUT	PKMSURFACEDESC	pSurfaceDesc */
		128,					/*	IN	KMINT32			nWidth  */
		128,					/*	IN	KMINT32			nHeight  */
		nTextureType			/*	IN	KMTEXTURETYPE	nTextureType */
	);
	Check_Status(status, "kmCreateTextureSurface #1");
	/*----------------------------------------------------------------------------------- */
	/* Create texture surface */
	nTextureType = KM_TEXTURE_TWIDDLED_MM | KM_TEXTURE_RGB565;	/* Set texture type */
	status = kmCreateTextureSurface(
		&TexGround,				/* OUT	PKMSURFACEDESC	pSurfaceDesc */
		64,						/*	IN	KMINT32			nWidth  */
		64,						/*	IN	KMINT32			nHeight  */
		nTextureType			/*	IN	KMTEXTURETYPE	nTextureType */
	);
	Check_Status(status, "kmCreateTextureSurface #2");
	/*----------------------------------------------------------------------------------- */
	/* Create texture surface */
	nTextureType = KM_TEXTURE_TWIDDLED_MM | KM_TEXTURE_ARGB4444;	/* Set texture type */
	status = kmCreateTextureSurface(
		&TexShadow,				/* OUT	PKMSURFACEDESC	pSurfaceDesc */
		128,					/*	IN	KMINT32			nWidth  */
		128,					/*	IN	KMINT32			nHeight  */
		nTextureType			/*	IN	KMTEXTURETYPE	nTextureType */
	);
	Check_Status(status, "kmCreateTextureSurface #3");
	/*----------------------------------------------------------------------------------- */
	/* Create texture surface */
	nTextureType = KM_TEXTURE_TWIDDLED_MM | KM_TEXTURE_RGB565;	/* Set texture type */
	status = kmCreateTextureSurface(
		&TexFire,				/* OUT	PKMSURFACEDESC	pSurfaceDesc */
		128,					/*	IN	KMINT32			nWidth  */
		128,					/*	IN	KMINT32			nHeight  */
		nTextureType			/*	IN	KMTEXTURETYPE	nTextureType */
	);
	Check_Status(status, "kmCreateTextureSurface #4");
	/*----------------------------------------------------------------------------------- */
	/* Create texture surface */
	nTextureType = KM_TEXTURE_TWIDDLED_MM | KM_TEXTURE_ARGB4444;	/* Set texture type */
	status = kmCreateTextureSurface(
		&TexThorm,				/* OUT	PKMSURFACEDESC	pSurfaceDesc */
		128,					/*	IN	KMINT32			nWidth  */
		128,					/*	IN	KMINT32			nHeight  */
		nTextureType			/*	IN	KMTEXTURETYPE	nTextureType */
	);
	Check_Status(status, "kmCreateTextureSurface #5");
	/*----------------------------------------------------------------------------------- */
	/* Load and set texture */
	pTexture01 = (unsigned long *)&Bat;
	status = kmLoadTexture(&TexBat,			/* PKMSURFACEDESC pSurfaceDesc */
							pTexture01 + (16 / sizeof(KMDWORD)),			/* PKMDWORD pTexture */
							FALSE,				/* KMBOOLEAN bAutoMipMap */
							FALSE				/* KMBOOLEAN bDither */
							);
	Check_Status(status, "kmLoadTexture #1");
	/*----------------------------------------------------------------------------------- */
	/* Load and set texture */
	pTexture01 = (unsigned long *)&Ground;
	status = kmLoadTexture(&TexGround,			/* PKMSURFACEDESC pSurfaceDesc */
							pTexture01 + (16 / sizeof(KMDWORD)),			/* PKMDWORD pTexture */
							FALSE,				/* KMBOOLEAN bAutoMipMap */
							FALSE				/* KMBOOLEAN bDither */
							);
	Check_Status(status, "kmLoadTexture #2");
	/*----------------------------------------------------------------------------------- */
	/* Load and set texture */
	pTexture01 = (unsigned long *)&Shadow;
	status = kmLoadTexture(&TexShadow,			/* PKMSURFACEDESC pSurfaceDesc */
							pTexture01 + (16 / sizeof(KMDWORD)),			/* PKMDWORD pTexture */
							FALSE,				/* KMBOOLEAN bAutoMipMap */
							FALSE				/* KMBOOLEAN bDither */
							);
	Check_Status(status, "kmLoadTexture #3");
	/*----------------------------------------------------------------------------------- */
	/* Load and set texture */
	pTexture01 = (unsigned long *)&Fire;
	status = kmLoadTexture(&TexFire,			/* PKMSURFACEDESC pSurfaceDesc */
							pTexture01 + (16 / sizeof(KMDWORD)),			/* PKMDWORD pTexture */
							FALSE,				/* KMBOOLEAN bAutoMipMap */
							FALSE				/* KMBOOLEAN bDither */
							);
	Check_Status(status, "kmLoadTexture #4");
	/*----------------------------------------------------------------------------------- */
	/* Load and set texture */
	pTexture01 = (unsigned long *)&Thorm;
	status = kmLoadTexture(&TexThorm,			/* PKMSURFACEDESC pSurfaceDesc */
							pTexture01 + (16 / sizeof(KMDWORD)),			/* PKMDWORD pTexture */
							FALSE,				/* KMBOOLEAN bAutoMipMap */
							FALSE				/* KMBOOLEAN bDither */
							);
	Check_Status(status, "kmLoadTexture #5");
}
/*-------------------------------------------------------------------------------------*/
void NextFrame (void)
{
/*
extern SGLCONTEXT SGLContext;
extern SGLCONTEXT2 SGLContext2;
*/
static Movement = 0;
static float Sun = 0, HPos;
register i;


  InitScene ();


  for (i=0;i<NUM_MESHES; i++)  ResetMatrix (i);

  /*
   *  Processing the spaceship
   *  (Blend modes need to be set in the second Context structure)
   */
  for (i=0;i<NUM_MESHES; i++) {
      if (i==SHADOW) continue;

/*	  SetContext (Info); */

      Translate (i, -120.0f*sin(Ang), -20*sin(Frame/250.0f)-30, -400);
	  Rotate (i, X_Axle, -PI/16);
	  Rotate (i, Z_Axle, -(PI/8)*sin(Ang));
	  Rotate (i, Y_Axle, PI+(PI/8)*sin(Ang));

      if (i==PLANE)
	  {
		  SetSmoothShading (i, C_NONE);
		  SetVertices (i,  VertexContextBat, FX_NONE);
	  }

	  else{
	  /*
	   * Fire: 4 polygons blended using  Source:OTHER and Destination:ONE
	   */
	  Translate (i, -2.0f*sin(i*Frame/10.0f), -2*sin(i*Frame),0);
/*
	  SGLContext2.u32BlendCntl  = sgl_blend_cntl( sgl_blend_other, sgl_blend_one, sgl_accum2_notused );
      SGLContext2.u32Flags      = SGLTT2_BLENDCNTL | SGLTT2_TEXTUREBLEND;
*/
      SetVertices (i, VertexContextFire, FX_NONE);
	  }


	} /* End of for */

   /*
    * Shadow blended using Source:ZERO and Destination:INVSOURCEALPHA
    */
   Translate (SHADOW, -120.0f*sin(Ang), 0, -400);
   Rotate    (SHADOW, Y_Axle, PI+(PI/8)*sin(Ang));
/*
   SGLContext2.u32BlendCntl = sgl_blend_cntl( sgl_blend_zero, sgl_blend_invsrca, sgl_accum2_notused );
   SGLContext2.u32Flags     = SGLTT2_BLENDCNTL | SGLTT2_TEXTUREBLEND;
*/
   SetVertices (SHADOW,  VertexContextShadow, FX_NONE);

   Ang = (PI*2) * sin(Frame/2500.0f);
   PosY+=0.1f;  if (PosY>100.0f) PosY =0.0f;

   SetGround(VertexContextGround);
   Lightning(VertexContextThorm);

/*   Timer(DISPLAY_TIME); */


   EndScene();


   Frame+=2;
}
/*-------------------------------------------------------------------------------------*/

void DisplayInformation (void)
{
char *Flag[2]   = { "FALSE", "TRUE" };

	txt_SetCursor(0,21);

	PRINTOUT(( " F1 : Bilinear    %s\n",   Flag[Info.Bilinear]));
	PRINTOUT(( " F2 : Gouraud     %s\n",   Flag[Info.Gouraud]));
	PRINTOUT(( " F3 : Textured    %s\n",   Flag[Info.Textured]));
	PRINTOUT(( " F4 : HighLight   %s\n\n", Flag[Info.Highlight]));

/*	Timer (RESET_TIME); */
}

/*----------------------------------------------------------------------*/
/*  Function Name   : kmflght2v_SetContext                              */
/*  Inputs          : CInfo                                             */
/*  Outputs         :                                                   */
/*  Returns         :                                                   */
/*  Globals Used    :                                                   */
/*  Description     :                                                   */
/*----------------------------------------------------------------------*/

void kmflght2v_SetContext (INFO CInfo)
{
	/*-------------------------------------------------------------------------------- */
	/* Initialize Vertex Context : VertexContextBat */
	/*-------------------------------------------------------------------------------- */
	memset( &VertexContextBat, 0, sizeof(VertexContextBat));	/* Crear Context */
	InitVertexContext(&VertexContextBat);					/* Initialize context */

	VertexContextBat.RenderState = 0;
	if (CInfo.Bilinear) {
			VertexContextBat.RenderState	|= KM_FILTERMODE;
			VertexContextBat.FilterMode	 = KM_BILINEAR;
	}
	VertexContextBat.RenderState	|= KM_CULLINGMODE;
	VertexContextBat.CullingMode	= KM_CULLSMALL;
	/* Set texture surface */
	VertexContextBat.pTextureSurfaceDesc	= &TexBat;
	/* Process Context */
	status = kmProcessVertexRenderState(&VertexContextBat);
	Check_Status(status, "kmProcessVertexRenderState");
	/*-------------------------------------------------------------------------------- */
	/* Initialize Vertex Context : VertexContextGround */
	/*-------------------------------------------------------------------------------- */
	memset( &VertexContextGround, 0, sizeof(VertexContextGround));	/* Crear Context */
	InitVertexContext(&VertexContextGround);					/* Initialize context */

	VertexContextGround.RenderState = 0;
	if (CInfo.Bilinear) {
			VertexContextGround.RenderState	|= KM_FILTERMODE;
			VertexContextGround.FilterMode	 = KM_BILINEAR;
	}
	/* Set texture surface */
	VertexContextGround.pTextureSurfaceDesc	= &TexGround;
	/* Process Context */
	status = kmProcessVertexRenderState(&VertexContextGround);
	Check_Status(status, "kmProcessVertexRenderState");
	/*-------------------------------------------------------------------------------- */
	/* Initialize Vertex Context : VertexContextShadow */
	/*-------------------------------------------------------------------------------- */
	memset( &VertexContextShadow, 0, sizeof(VertexContextShadow));	/* Crear Context */
	InitVertexContext(&VertexContextShadow);					/* Initialize context */

	VertexContextShadow.RenderState = 0;
	if (CInfo.Bilinear) {
			VertexContextShadow.RenderState	|= KM_FILTERMODE;
			VertexContextShadow.FilterMode	 = KM_BILINEAR;
	}
	VertexContextShadow.RenderState	|= KM_SRCBLENDINGMODE;
	VertexContextShadow.SRCBlendingMode	= KM_ZERO;

	VertexContextShadow.RenderState	|= KM_DSTBLENDINGMODE;
	VertexContextShadow.DSTBlendingMode	= KM_INVSRCALPHA;

	VertexContextShadow.RenderState	|= KM_LISTTYPE;
	VertexContextShadow.ListType  = KM_TRANS_POLYGON;
#if 0
	VertexContextShadow.RenderState	|= KM_TEXTURESHADINGMODE;
	VertexContextShadow.TextureShadingMode	= KM_MODULATE_ALPHA;

	VertexContextShadow.RenderState	|= KM_USEALPHA;
	VertexContextShadow.bUseAlpha = TRUE;
#endif
	/* Set texture surface */
	VertexContextShadow.pTextureSurfaceDesc	= &TexShadow;
	/* Process Context */
	status = kmProcessVertexRenderState(&VertexContextShadow);
	Check_Status(status, "kmProcessVertexRenderState");
	/*-------------------------------------------------------------------------------- */
	/* Initialize Vertex Context : VertexContextFire */
	/*-------------------------------------------------------------------------------- */
	memset( &VertexContextFire, 0, sizeof(VertexContextFire));	/* Crear Context */
	InitVertexContext(&VertexContextFire);					/* Initialize context */

	VertexContextFire.RenderState = 0;
	if (CInfo.Bilinear) {
			VertexContextFire.RenderState	|= KM_FILTERMODE;
			VertexContextFire.FilterMode	 = KM_BILINEAR;
	}
	VertexContextFire.RenderState	|= KM_SRCBLENDINGMODE;
	VertexContextFire.SRCBlendingMode	= KM_DESTCOLOR;

	VertexContextFire.RenderState	|= KM_DSTBLENDINGMODE;
	VertexContextFire.DSTBlendingMode	= KM_ONE;

	VertexContextFire.RenderState	|= KM_LISTTYPE;
	VertexContextFire.ListType  = KM_TRANS_POLYGON;
#if 0
	VertexContextFire.RenderState	|= KM_TEXTURESHADINGMODE;
	VertexContextFire.TextureShadingMode	= KM_MODULATE_ALPHA;

	VertexContextFire.RenderState	|= KM_USEALPHA;
	VertexContextFire.bUseAlpha = TRUE;
#endif
	/* Set texture surface */
	VertexContextFire.pTextureSurfaceDesc	= &TexFire;
	/* Process Context */
	status = kmProcessVertexRenderState(&VertexContextFire);
	Check_Status(status, "kmProcessVertexRenderState");
	/*-------------------------------------------------------------------------------- */
	/* Initialize Vertex Context : VertexContextThorm */
	/*-------------------------------------------------------------------------------- */
	memset( &VertexContextThorm, 0, sizeof(VertexContextThorm));	/* Crear Context */
	InitVertexContext(&VertexContextThorm);					/* Initialize context */

	VertexContextThorm.RenderState = 0;
	if (CInfo.Bilinear) {
			VertexContextThorm.RenderState	|= KM_FILTERMODE;
			VertexContextThorm.FilterMode	 = KM_BILINEAR;
	}
	VertexContextThorm.RenderState	|= KM_SRCBLENDINGMODE;
	VertexContextThorm.SRCBlendingMode	= KM_SRCALPHA;

	VertexContextThorm.RenderState	|= KM_DSTBLENDINGMODE;
	VertexContextThorm.DSTBlendingMode	= KM_INVSRCALPHA;

	VertexContextThorm.RenderState	|= KM_LISTTYPE;
	VertexContextThorm.ListType  = KM_TRANS_POLYGON;

	VertexContextThorm.RenderState	|= KM_TEXTURESHADINGMODE;
	VertexContextThorm.TextureShadingMode	= KM_MODULATE_ALPHA;

	VertexContextThorm.RenderState	|= KM_USEALPHA;
	VertexContextThorm.bUseAlpha = TRUE;
	/* Set texture surface */
	VertexContextThorm.pTextureSurfaceDesc	= &TexThorm;
	/* Process Context */
	status = kmProcessVertexRenderState(&VertexContextThorm);
	Check_Status(status, "kmProcessVertexRenderState");
}

/*--------------------------- End of File --------------------------------*/
