{

	RGBA rgb_col;
	RGBA *screen = buff->image;
	RGBA rgba_col= {128,128,192,0};

#if defined(ZBUFFER)
	int *zbuffer = buff->zbuffer;
#endif
	/*---> get current lighttable to corrsponding surface <-----*/
#if defined(GOURADE)
/*
	BYTE *r_lighttab = &buff->lighttab[ col.r];
	BYTE *g_lighttab = &buff->lighttab[ col.g];
	BYTE *b_lighttab = &buff->lighttab[ col.b];
*/
	RGBA g_col;

#endif

	struct
	{
		float x;
		float y;
#if defined(ZBUFFER)
		float z;
#endif
#if defined(GOURADE)
		float l;
#endif
	} c1,c2,c3;


// always!
	int x1,x1add,x2,x2add;
	int y,ylen,yc;

#if !defined(__X86__)
	int x,xlen,xf;
#endif

#if defined(ZBUFFER)
#if !defined(__X86__)
	int z,zadd,zf;
#endif
	int z1,z1add,z2,z2add;
#endif

#if defined(GOURADE)
#if !defined(__X86__)
	int l,ladd,lf;
#endif
	int l1,l1add,l2,l2add;
#endif

#if defined(LIGHT) && !defined(GOURADE)

	BYTE *lght = &buff->lighttab[((int)p1.l<<8) & 0xff00];

	col.r = lght[col.r];
	col.g = lght[col.g];
	col.b = lght[col.b];
#endif


	if( p3.y > p2.y)
	{
		c2.x = p2.x;
		c2.y = p2.y;
#if defined(ZBUFFER)
		c2.z = p2.z;
#endif
#if defined(GOURADE)
		c2.l = p2.l;
#endif

		c3.x = p3.x;
		c3.y = p3.y;
#if defined(ZBUFFER)
		c3.z = p3.z;
#endif
#if defined(GOURADE)
		c3.l = p3.l;
#endif
	}
	else
	{
		c2.x = p3.x;
		c2.y = p3.y;
#if defined(ZBUFFER)
		c2.z = p3.z;
#endif
#if defined(GOURADE)
		c2.l = p3.l;
#endif

		c3.x = p2.x;
		c3.y = p2.y;
#if defined(ZBUFFER)
		c3.z = p2.z;
#endif
#if defined(GOURADE)
		c3.l = p2.l;
#endif
	}

	if( c2.y > p1.y)
	{
		c1.x = p1.x;
		c1.y = p1.y;
#if defined(ZBUFFER)
		c1.z = p1.z;
#endif
#if defined(GOURADE)
		c1.l = p1.l;
#endif
	}
	else
	{
		c1.x = c2.x;
		c1.y = c2.y;
#if defined(ZBUFFER)
		c1.z = c2.z;
#endif
#if defined(GOURADE)
		c1.l = c2.l;
#endif

		if( c3.y > p1.y)
		{
			c2.x = p1.x;
			c2.y = p1.y;
#if defined(ZBUFFER)
			c2.z = p1.z;
#endif
#if defined(GOURADE)
			c2.l = p1.l;
#endif
		}
		else
		{
			c2.x = c3.x;
			c2.y = c3.y;
#if defined(ZBUFFER)
			c2.z = c3.z;
#endif
#if defined(GOURADE)
			c2.l = c3.l;
#endif

			c3.x = p1.x;
			c3.y = p1.y;
#if defined(ZBUFFER)
			c3.z = p1.z;
#endif
#if defined(GOURADE)
			c3.l = p1.l;
#endif
		}
	}

	if( (c3.y < buff->miny) || (c1.y > buff->maxy))
		return;	// Polygon out of bounds

	/* Upper loop */

	ylen = c3.y - c1.y;
	x2 = c1.x * 65536, x2add = ((c3.x - c1.x) * 65536) / ylen;
#if defined(ZBUFFER)
	z2 = c1.z * 65536, z2add = ((c3.z - c1.z) * 65536) / ylen;
#endif
#if defined(GOURADE)
	l2 = c1.l * 65536, l2add = ((c3.l - c1.l) * 65536) / ylen;
#endif

	if( c2.y >= buff->miny)
	{

		ylen = c2.y - c1.y;
		x1 = c1.x * 65536, x1add = ((c2.x - c1.x) * 65536) / ylen;
#if defined(ZBUFFER)
		z1 = c1.z * 65536, z1add = ((c2.z - c1.z) * 65536) / ylen;
#endif
#if defined(GOURADE)
		l1 = c1.l * 65536, l1add = ((c2.l - c1.l) * 65536) / ylen;
#endif

		yc = fchop(c1.y * 65536) & 0xffff;

		if( fchop(c1.y) < buff->miny)
		{
      ylen = buff->miny - (int)c1.y;
			x1 += x1add * ylen;
#if defined(ZBUFFER)
			z1 += z1add * ylen;
#endif
#if defined(GOURADE)
			l1 += l1add * ylen;
#endif

			x2 += x2add * ylen;
#if defined(ZBUFFER)
			z2 += z2add * ylen;
#endif
#if defined(GOURADE)
			l2 += l2add * ylen;
#endif

			y = buff->miny;
		}
		else
			y = c1.y;

		if( (int)c2.y > buff->maxy)
			ylen = buff->maxy - y;
		else
			ylen = (int)c2.y - y;

		screen += buff->ytab[ y];
#if defined(ZBUFFER)
		zbuffer += buff->ytab[ y];
#endif

#if defined(__X86__)

#if !defined(ZBUFFER) && !defined(GOURADE) && !defined(TRANS)
		poly_glzt_asm( screen, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, x2, x2add, col);
#elif defined(ZBUFFER) && !defined (LIGHT) && !defined(GOURADE) && !defined(TRANS)
		poly_glZt_asm( screen, zbuffer, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, z1, z1add, x2, x2add, z2, z2add, col);
#elif defined(ZBUFFER) && defined (LIGHT) && !defined(GOURADE) && !defined(TRANS)
		poly_glZt_asm( screen, zbuffer, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, z1, z1add, x2, x2add, z2, z2add, col);
#elif defined(ZBUFFER) && defined(GOURADE) && !defined(TRANS)
		poly_GLZt_asm (screen, zbuffer, lighttab, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, z1, z1add, l1, l1add, x2, x2add, z2, z2add, l2, l2add);
#endif

		screen += ylen * buff->width;
		x2 += x2add * ylen;
#if defined(ZBUFFER)
		zbuffer += ylen * buff->width;
		z2 += z2add * ylen;
#endif
#if defined(GOURADE)
		l2 += l2add * ylen;
#endif

#else
//#include "poly1.c"
#endif
	}
	else
	{
		x2 += x2add * ((int)(c2.y) - (int)(c1.y));
#if defined(ZBUFFER)
		z2 += z2add * ((int)(c2.y) - (int)(c1.y));
#endif
#if defined(GOURADE)
		l2 += l2add * ((int)(c2.y) - (int)(c1.y));
#endif
	}

	/* Lower loop */

	if( c2.y <= buff->maxy)
	{

		ylen = c3.y - c2.y;
		x1 = c2.x * 65536, x1add = ((c3.x - c2.x) * 65536) / ylen;
#if defined(ZBUFFER)
		z1 = c2.z * 65536, z1add = ((c3.z - c2.z) * 65536) / ylen;
#endif
#if defined(GOURADE)
		l1 = c2.l * 65536, l1add = ((c3.l - c2.l) * 65536) / ylen;
#endif

		yc = (int)(c2.y * 65536) & 0xffff;

		if( ((int)c2.y) < buff->miny)
		{
			ylen = buff->miny - (int)c2.y;
			x1 += x1add * ylen;
#if defined(ZBUFFER)
			z1 += z1add * ylen;
#endif
#if defined(GOURADE)
			l1 += l1add * ylen;
#endif

			x2 += x2add * ylen;
#if defined(ZBUFFER)
			z2 += z2add * ylen;
#endif
#if defined(GOURADE)
			l2 += l2add * ylen;
#endif
			y = buff->miny;
		}
		else
			y = c2.y;

		if( (int)c3.y > buff->maxy)
			ylen = buff->maxy - y;
		else
			ylen = (int)c3.y - y;
#if defined(__X86__)

#if !defined(ZBUFFER) && !defined(GOURADE) && !defined(TRANS)
	poly_glzt_asm( screen, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, x2, x2add, col);
#elif defined(ZBUFFER) && !defined (LIGHT) && !defined(GOURADE) && !defined(TRANS)
	poly_glZt_asm( screen, zbuffer, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, z1, z1add, x2, x2add, z2, z2add, col);
#elif defined(ZBUFFER) && defined (LIGHT) && !defined(GOURADE) && !defined(TRANS)
	poly_glZt_asm( screen, zbuffer, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, z1, z1add, x2, x2add, z2, z2add, col);
#elif defined(ZBUFFER) && defined(GOURADE) && !defined(TRANS)
		poly_GLZt_asm (screen, zbuffer, lighttab, buff->minx, buff->maxx, buff->width, ylen, x1, x1add, z1, z1add, l1, l1add, x2, x2add, z2, z2add, l2, l2add);
#endif

#else
//#include "poly1.c"
#endif
	}
}
