/*
    Ninja Sample

    COPYRIGHT (C) SEGA ENTERSRISES,LTD.

    Teapot Sample

    1998.7.23
*/

#include <Shinobi.h>
#include <nindows.h>

extern Uint16 T009[];

#define OBJECT  object_tea_Teapot1_Teapot1
extern NJS_OBJECT OBJECT[];

NJS_TEXNAME texname[1];
NJS_TEXLIST tlist1 = {texname,1};
NJS_TEXINFO info;

extern NJS_MATRIX   matrix[8];
extern NJS_VERTEX_BUF   vbuf[4096];

NJS_TEXMEMLIST  tex[10];

NJS_VIEW    view;
NJS_LIGHT   light;

Sint32  xx,yy,zz = 0;

Uint32 count = 0;

void Count(void)
{
    count++;

}

Sint8 *buffer;

void njUserInit(void)
{

    njSetBorderColor( 0x00000000 ) ;
    sbInitSystem( NJD_RESOLUTION_640x480_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB555, 1 );
    
    njInitVertexBuffer( 800000, 0, 200000, 0 ,0);
    njInitPrint(NULL, 0, 0);
    njInitMatrix( matrix, 8 , 0);
    njInit3D( vbuf, 4096 );
    njInitView( &view );
    njCreateLight( &light, NJD_PHONG_DIR );
    njSetLightIntensity( &light, 1.5f, 1.0f, 0.7f );
    njSetLightAngle( &light, NJM_RAD_ANG(NJD_PI / 30.f), NJM_RAD_ANG(NJD_PI / 4.f) );
    njSetLightDirection( &light, 0, 0.707f, -0.707f );
    njSetView( &view );

    njInitTexture( tex, 10 );
    nwInitSystem(10,NJD_PORT_A0);
    njSetTextureInfo(&info,T009,NJD_TEXFMT_RGB_565|NJD_TEXFMT_TWIDDLED,128,128);
    njSetTextureName(&texname[0],&info,0,NJD_TEXATTR_TYPE_MEMORY|NJD_TEXATTR_GLOBALINDEX);
    njLoadTexture( &tlist1 );
    njSetTexture( &tlist1 );

    njControl3D( NJD_CONTROL_3D_CONSTANT_ATTR );
    njSetConstantAttr( 0xffffffff, NJD_FLAG_USE_TEXTURE | NJD_FLAG_USE_ENV|NJD_FILTER_BILINEAR);

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

    njSetVSyncFunction(Count);
    njPrintSize(16);
        
}

Sint32 njUserMain(void)
{
    njClearMatrix();
    njTranslate( NULL, 0.f, 0.f, -12.f );
    njRotateXYZ( NULL, xx,yy,zz );
    njDrawObject( OBJECT );
    
    xx += 257;
    yy += 179;
    zz += 193;

    njPrintD(NJM_LOCATION(2,3),count,8);

    return nwExecute();
}

void njUserExit(void)
{
    nwExitSystem();
    njExitPrint();
    njExitTexture();
    sbExitSystem();
}

