/*
	Ninja Sample
	
	COPYRIGHT (C) SEGA ENTERSRISES,LTD.

	Texture Sample

	1997.10.20
*/
#include <Ninjawin.h>
#include <Nindows.h>
#define NUM 3

NJS_TEXTURE_VTX	poly[4];
extern Uint16 sonic[];

/* setting textures */
NJS_TEXINFO	info;
NJS_TEXNAME texname[NUM];
NJS_TEXLIST texlist = {texname,NUM};
NJS_TEXMEMLIST	tex[100];

NJS_PERIPHERAL *per,*per1;
Sint32 TexNum = 0;

void njUserInit(void)
{
	njInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
	njInitVertexBuffer( 100000, 0, 100000, 0 );

	njInitTexture( tex,100);
	nwInitSystem(256);			//nwInitSystem function should be put immediately after njInitTexture
	njSetTexturePath("Image\\");

	/* setting memory textures */
	njSetTextureInfo(&info,sonic,NJD_TEXFMT_ARGB_4444|NJD_TEXFMT_TWIDDLED,256,256);
	njSetTextureName(&texname[0],&info,0,NJD_TEXATTR_TYPE_MEMORY|NJD_TEXATTR_GLOBALINDEX);
	
	njSetTextureName(&texname[1],"frog_room",1,NJD_TEXATTR_TYPE_FILE|NJD_TEXATTR_GLOBALINDEX);
	njSetTextureName(&texname[2],"people.pvr",2,NJD_TEXATTR_TYPE_FILE|NJD_TEXATTR_GLOBALINDEX);

	njLoadTexture( &texlist );
	njSetTexture( &texlist );

	njSetBackColor(0x000000FF,0x000000FF,0x00000000);

	poly[0].x = 100;
	poly[0].y = 100;
	poly[0].z = 0.5;
	poly[0].u = 0;
	poly[0].v = 0;
	poly[0].col = 0xFFFFFFFF;
	
	poly[1].x = 100;
	poly[1].y = 300;
	poly[1].z = 0.5;
	poly[1].u = 0;
	poly[1].v = 1.f;
	poly[1].col = 0xFFFFFFFF;
	
	poly[2].x = 300;
	poly[2].y = 100;
	poly[2].z = 0.5;
	poly[2].u = 1.f;
	poly[2].v = 0;
	poly[2].col = 0xFFFFFFFF;

	poly[3].x = 300;
	poly[3].y = 300;
	poly[3].z = 0.5;
	poly[3].u = 1.f;
	poly[3].v = 1.f;
	poly[3].col = 0xFFFFFFFF;
	
}

Sint32 njUserMain(void)
{

	njPrintC(NJM_LOCATION(4,4),"NINJA TEXTURE SAMPLE");

	per1 = njGetPeripheral(NJD_PORT_SYSKEYBOARD);


	if(per1->push & NJD_DGT_TA){
		TexNum++;
		if(TexNum >= NUM) TexNum=0;
		
	}

	njDrawTexture( poly, 4, TexNum,TRUE);

	njPrintC(NJM_LOCATION(4,4),"NINJA TEXTURE SAMPLE");
	njPrintC(NJM_LOCATION(20,40),"PUSH Z KEY");
	
	return nwExecute();
}

void njUserExit(void)
{
	nwExitSystem();
	njExitTexture();
	njExitSystem();
}
