#include <v_lib.h>

void	tlistDump(trilist_t *list)
{
	listtri_t *tris=(listtri_t*)stackGetStorage(&list->vlist);
	int i,j,num_tri=stackCount(&list->vlist);
	for(i=0;i<num_tri;i++)
	{
		conPrintf("Triangle #%d ========================\n",i);
		for(j=0;j<3;j++)
			conPrintf(
				"vert(%g,%g,%g):\tcolor[%g,%g,%g,%g]\t"
				"texcoord[%g,%g]\tnormal[%g,%g,%g]\n",
				tris[i].verts[j].vert[0],
				tris[i].verts[j].vert[1],
				tris[i].verts[j].vert[2],
				tris[i].verts[j].color[0],
				tris[i].verts[j].color[1],
				tris[i].verts[j].color[2],
				tris[i].verts[j].color[3],
				tris[i].verts[j].texcoord[0],
				tris[i].verts[j].texcoord[1],
				tris[i].verts[j].normal[0],
				tris[i].verts[j].normal[1],
				tris[i].verts[j].normal[2]);
	}
}

/* #define	MUST_DIE */

#ifdef	MUST_DIE
#ifdef	_MSC_VER
#pragma warning(disable:4100)
#endif
int __stdcall WinMain(void *inst,void *stub,char *cmdline,int show)
#else
int main()
#endif
{
	trilist_t *list;
	vec3_t viewer;
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	
	list=tlistCreate();
	
	/* Add 3 triangles */
	
	tlistColor(list,1,0,0,0);
	tlistVertex(list,1,0,0);
	tlistVertex(list,0,1,0);
	tlistVertex(list,0,0,1);

	tlistColor(list,0,1,0,0);
	tlistVertex(list,11,0,0);
	tlistVertex(list,10,1,0);
	tlistVertex(list,10,0,1);
	
	tlistColor(list,0,0,1,0);
	tlistVertex(list,-8,0,0);
	tlistVertex(list,-9,1,0);
	tlistVertex(list,-9,0,1);

	/* set viewer pos near 1st tri, sort & dump */
	vec3Set(viewer,0,1,0);
	tlistDraw(list,viewer,true);
	tlistDump(list);
	/* set viewer pos near 3st tri, sort & dump */
	vec3Set(viewer,-10,-10,-10);
	tlistDraw(list,viewer,true);
	tlistDump(list);
	return 0;
}
