I did some cleanup in ivis, here is the patch.
Index: lib/ivis02/piestate.c
===================================================================
--- lib/ivis02/piestate.c	(revision 33)
+++ lib/ivis02/piestate.c	(working copy)
@@ -7,215 +7,25 @@
  */
 /***************************************************************************/
 
-#include "frame.h"
 #include "piestate.h"
-#include "piedef.h"
 
-#include "tex.h"
-
-
-
 /***************************************************************************/
 /*
  *	Global Variables
  */
 /***************************************************************************/
 
-SDWORD		pieStateCount = 0;
-BOOL		bSwirls = FALSE;
-BOOL		bWave = FALSE;
-/***************************************************************************/
-/*
- *	Local Definitions
- */
-/***************************************************************************/
+extern RENDER_STATE	rendStates;
 
-typedef	enum	COLOUR_MODE
-				{
-					COLOUR_FLAT_CONSTANT,
-					COLOUR_FLAT_ITERATED,
-					COLOUR_TEX_ITERATED,
-					COLOUR_TEX_CONSTANT
-				}
-				COLOUR_MODE;
-
-typedef	enum	TEX_MODE
-				{
-					TEX_LOCAL,
-					TEX_NONE
-				}
-				TEX_MODE;
-
-typedef	enum	ALPHA_MODE
-				{
-					ALPHA_ITERATED,
-					ALPHA_CONSTANT
-				}
-				ALPHA_MODE;
-
-typedef struct _renderState
-{
-	REND_ENGINE			rendEngine;
-	BOOL				bHardware;
-	DEPTH_MODE			depthBuffer;
-	BOOL				translucent;
-	BOOL				additive;
-	FOG_CAP				fogCap;
-	BOOL				fogEnabled;
-	BOOL				fog;
-	UDWORD				fogColour;
-	TEX_CAP				texCap;
-	SDWORD				texPage;
-	REND_MODE			rendMode;
-	BOOL				bilinearOn;
-	BOOL				keyingOn;
-	COLOUR_MODE			colourCombine;
-	TEX_MODE			texCombine;
-	ALPHA_MODE			alphaCombine;
-	TRANSLUCENCY_MODE	transMode;
-	UDWORD				colour;
-#ifdef STATES
-	BOOL				textured;
-	UBYTE				lightLevel;
-#endif
-	UBYTE				DDrawDriverName[256];
-	UBYTE				D3DDriverName[256];
-} RENDER_STATE;
-
 /***************************************************************************/
 /*
- *	Local Variables
- */
-/***************************************************************************/
-
-RENDER_STATE	rendStates;
-
-/***************************************************************************/
-/*
- *	Local ProtoTypes
- */
-/***************************************************************************/
-static void pie_SetColourCombine(COLOUR_MODE colCombMode);
-static void pie_SetTexCombine(TEX_MODE texCombMode);
-static void pie_SetAlphaCombine(ALPHA_MODE alphaCombMode);
-static void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode);
-//static void pie_SetAlphaCombine(BOOL trans);
-
-/***************************************************************************/
-/*
  *	Source
  */
 /***************************************************************************/
-void pie_SetDefaultStates(void)//Sets all states
-{
-//		pie_SetFogColour(0x00B08f5f);//nicks colour
-	//fog off
-	rendStates.fogEnabled = FALSE;// enable fog before renderer
-	rendStates.fog = FALSE;//to force reset to false
-	pie_SetFogStatus(FALSE);
-	pie_SetFogColour(0x00000000);//nicks colour
 
-	//depth Buffer on
-	rendStates.depthBuffer = FALSE;//to force reset to true
-	pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
-
-	//set render mode
-	pie_SetTranslucent(TRUE);
-	pie_SetAdditive(TRUE);
-	
-	//basic gouraud textured rendering
-	rendStates.texCombine = TEX_NONE;//to force reset to GOURAUD_TEX
-	pie_SetTexCombine(TEX_LOCAL);
-	rendStates.colourCombine = COLOUR_FLAT_CONSTANT;//to force reset to GOURAUD_TEX
-	pie_SetColourCombine(COLOUR_TEX_ITERATED);
-	rendStates.alphaCombine = ALPHA_ITERATED;//to force reset to GOURAUD_TEX
-	pie_SetAlphaCombine(ALPHA_CONSTANT);
-	rendStates.transMode = TRANS_ALPHA;//to force reset to DECAL
-	pie_SetTranslucencyMode(TRANS_DECAL);
-
-	//chroma keying on black
-	rendStates.keyingOn = FALSE;//to force reset to true
-	pie_SetColourKeyedBlack(TRUE);
-
-	//bilinear filtering
-	rendStates.bilinearOn = FALSE;//to force reset to true
-	pie_SetBilinear(TRUE);
-}
-
-/***************************************************************************/
-/***************************************************************************/
-void pie_ResetStates(void)//Sets all states
-{
-	SDWORD		temp;
-
-//		pie_SetFogColour(0x00B08f5f);//nicks colour
-	rendStates.fog = !rendStates.fog;//to force reset
-	pie_SetFogStatus(!rendStates.fog);
-
-	//depth Buffer on
-	temp = rendStates.depthBuffer;
-	rendStates.depthBuffer = -1;//to force reset
-	pie_SetDepthBufferStatus(temp);
-
-	//set render mode
-//	pie_SetTranslucent(TRUE);
-//	pie_SetAdditive(TRUE);
-	
-	//basic gouraud textured rendering
-	temp = rendStates.texCombine;
-	rendStates.texCombine = -1;//to force reset
-	pie_SetTexCombine(temp);
-
-	temp = rendStates.colourCombine;
-	rendStates.colourCombine = -1;//to force reset
-	pie_SetColourCombine(temp);
-
-	temp = rendStates.alphaCombine;
-	rendStates.alphaCombine = -1;//to force reset
-	pie_SetAlphaCombine(temp);
-
-	temp = rendStates.transMode;
-	rendStates.transMode = -1;//to force reset
-	pie_SetTranslucencyMode(temp);
-
-	//chroma keying on black
-	temp = rendStates.keyingOn;
-	rendStates.keyingOn = -1;//to force reset
-	pie_SetColourKeyedBlack(temp);
-
-	//bilinear filtering
-	temp = rendStates.bilinearOn;
-	rendStates.bilinearOn = -1;//to force reset
-	pie_SetBilinear(temp);
-}
-
-/***************************************************************************/
-/***************************************************************************/
-void pie_SetRenderEngine(REND_ENGINE rendEngine)
-{
-	rendStates.rendEngine = rendEngine;
-
-	{
-		rendStates.bHardware = FALSE;
-	}
-}
-
-REND_ENGINE pie_GetRenderEngine(void)
-{
-	return rendStates.rendEngine;
-}
-
-BOOL	pie_Hardware(void)
-{
-	return rendStates.bHardware;
-}
-
-/***************************************************************************/
-/***************************************************************************/
-
 void pie_SetDepthBufferStatus(DEPTH_MODE depthMode)
 {
-#ifndef PIETOOL		
+#ifndef PIETOOL
 	if (rendStates.depthBuffer != depthMode)
 	{
 		rendStates.depthBuffer = depthMode;
@@ -225,106 +35,6 @@
 
 //***************************************************************************
 //
-// pie_SetTranslucent(BOOL val);
-//
-// Global enable/disable Translucent effects 
-//
-//***************************************************************************
-
-void pie_SetTranslucent(BOOL val)
-{
-	rendStates.translucent = val;
-}
-
-BOOL pie_Translucent(void)
-{
-	return rendStates.translucent;
-}
-
-//***************************************************************************
-//
-// pie_SetAdditive(BOOL val);
-//
-// Global enable/disable Additive effects 
-//
-//***************************************************************************
-
-void pie_SetAdditive(BOOL val)
-{
-	rendStates.additive = val;
-}
-
-BOOL pie_Additive(void)
-{
-	return rendStates.additive;
-}
-
-//***************************************************************************
-//
-// pie_SetCaps(BOOL val);
-//
-// HIGHEST LEVEL enable/disable modes 
-//
-//***************************************************************************
-
-
-void pie_SetFogCap(FOG_CAP val)
-{
-	rendStates.fogCap = val;
-}
-
-FOG_CAP pie_GetFogCap(void)
-{
-	return rendStates.fogCap;
-}
-
-void pie_SetTexCap(TEX_CAP val)
-{
-	rendStates.texCap = val;
-}
-
-TEX_CAP pie_GetTexCap(void)
-{
-	return rendStates.texCap;
-}
-
-//***************************************************************************
-//
-// pie_EnableFog(BOOL val)
-//
-// Global enable/disable fog to allow fog to be turned of ingame 
-//
-//***************************************************************************
-
-void pie_EnableFog(BOOL val)
-{
-	if (rendStates.fogCap == FOG_CAP_NO)
-	{
-		val = FALSE;
-	}
-	if (rendStates.fogEnabled != val)
-	{
-		rendStates.fogEnabled = val;
-		if (val == TRUE)
-		{
-//			pie_SetFogColour(0x0078684f);//(nicks colour + 404040)/2
-			pie_SetFogColour(0x00B08f5f);//nicks colour
-		}
-		else
-		{
-			pie_SetFogColour(0x00000000);//clear background to black
-		}
-
-	}
-}
-
-BOOL pie_GetFogEnabled(void)
-{
-	return  rendStates.fogEnabled;
-}
-
-//***************************************************************************
-//
 // pie_SetFogStatus(BOOL val)
 //
 // Toggle fog on and off for rendering objects inside or outside the 3D world
@@ -335,7 +45,7 @@
 {
 	if (rendStates.fogEnabled)
 	{
-		//fog enabled so toggle if required 
+		//fog enabled so toggle if required
 		if (rendStates.fog != val)
 		{
 			rendStates.fog = val;
@@ -344,7 +54,7 @@
 	}
 	else
 	{
-		//fog disabled so turn it off if not off already 
+		//fog disabled so turn it off if not off already
 		if (rendStates.fog != FALSE)
 		{
 			rendStates.fog = FALSE;
@@ -353,132 +63,12 @@
 	}
 }
 
-BOOL pie_GetFogStatus(void)
-{
-	return  rendStates.fog;
-}
-/***************************************************************************/
-void pie_SetFogColour(UDWORD colour)
-{
-	UDWORD grey;
- 	if (rendStates.fogCap == FOG_CAP_GREY)
-	{
-		grey = colour & 0xff;
-		colour >>= 8;
-		grey += (colour & 0xff);
-		colour >>= 8;
-		grey += (colour & 0xff);
-		grey /= 3;
-		grey &= 0xff;//check only
-		colour = grey + (grey<<8) + (grey<<16);
-		rendStates.fogColour = colour;
-	}
-	else if (rendStates.fogCap == FOG_CAP_NO)
-	{
-		rendStates.fogColour = 0;
-	}
-	else
-	{
-		rendStates.fogColour = colour;
-	}
-}
-
-UDWORD pie_GetFogColour(void)
-{
-	return rendStates.fogColour;
-}
-
 void pie_SetTexturePage(SDWORD num)
 {
 }
 
 /***************************************************************************/
-void pie_SetRendMode(REND_MODE rendMode)
-{
-	if (rendMode != rendStates.rendMode)
-	{
-		rendStates.rendMode = rendMode;
-		switch (rendMode)
-		{
-			case REND_GOURAUD_TEX:
-				pie_SetColourCombine(COLOUR_TEX_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_DECAL);
-				break;
-			case REND_ALPHA_TEX:
-				pie_SetColourCombine(COLOUR_TEX_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_ADDITIVE_TEX:
-				pie_SetColourCombine(COLOUR_TEX_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ADDITIVE);
-				break;
-			case REND_TEXT:
-				pie_SetColourCombine(COLOUR_TEX_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_DECAL);
-				break;
-			case REND_ALPHA_TEXT:
-				pie_SetColourCombine(COLOUR_TEX_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_ALPHA_FLAT:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_ALPHA_ITERATED:
-				pie_SetColourCombine(COLOUR_FLAT_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ADDITIVE);
-				break;
-		   	case REND_FILTER_FLAT:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_FILTER);
-				break;
-			case REND_FILTER_ITERATED:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_FLAT:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_DECAL);
-			default:
-				break;
-		}
-	}
-	return;
-}
 
-/*
-BOOL pie_GetTranslucent(void)
-{
-	if (rendStates.transMode == TRANS_DECAL)
-	{
-		return FALSE;
-	}
-	return TRUE;
-
-}
-*/
-/***************************************************************************/
-
 void pie_SetColourKeyedBlack(BOOL keyingOn)
 {
 #ifndef PIETOOL
@@ -491,33 +81,11 @@
 }
 
 /***************************************************************************/
-void pie_SetBilinear(BOOL bilinearOn)
+void pie_SetColourCombine(COLOUR_MODE colCombMode)
 {
-#ifndef PIETOOL
-	if (bilinearOn != rendStates.bilinearOn)
-	{
-		rendStates.bilinearOn = bilinearOn;
-		pieStateCount++;
-	}
-#endif
-}
-
-BOOL pie_GetBilinear(void)
-{
-#ifndef PIETOOL
-	return rendStates.bilinearOn;
-#else
-	return FALSE;
-#endif
-}
-
-/***************************************************************************/
-static void pie_SetColourCombine(COLOUR_MODE colCombMode)
-{
 #ifndef PIETOOL	//ffs
 
-	if (colCombMode != rendStates.colourCombine)
-	{
+	if (colCombMode != rendStates.colourCombine) {
 		rendStates.colourCombine = colCombMode;
 		pieStateCount++;
 	}
@@ -525,41 +93,8 @@
 }
 
 /***************************************************************************/
-static void pie_SetTexCombine(TEX_MODE texCombMode)
+void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode)
 {
-#ifndef PIETOOL	//ffs
-	if (texCombMode != rendStates.texCombine)
-	{
-		rendStates.texCombine = texCombMode;
-		pieStateCount++;
-		switch (texCombMode)
-		{
-			case TEX_LOCAL:
-			case TEX_NONE:
-			default:
-
-				break;
-		}
-	}
-#endif
-}
-
-/***************************************************************************/
-static void pie_SetAlphaCombine(ALPHA_MODE alphaCombMode)
-{
-#ifndef PIETOOL	//ffs
-	if (alphaCombMode != rendStates.alphaCombine)
-	{
-		rendStates.alphaCombine = alphaCombMode;
-		pieStateCount++;
-
-	}
-#endif
-}
-
-/***************************************************************************/
-static void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode)
-{
 #ifndef PIETOOL
 	if (transMode != rendStates.transMode)
 	{
@@ -583,70 +118,7 @@
 }
 
 /***************************************************************************/
-// get the constant colour used in text and flat render modes
-/***************************************************************************/
-UDWORD pie_GetColour(void)
-{
-	return	rendStates.colour;
-}
-
-/***************************************************************************/
 void pie_SetGammaValue(float val)
 {
 	pieStateCount++;
-
 }
-
-/***************************************************************************/
-void pie_DrawMouse(SDWORD x,SDWORD y)
-{
-
-
-
-}
-
-/***************************************************************************/
-UWORD	presentMouseID;
-void pie_SetMouse(IMAGEFILE *psImageFile,UWORD ImageID)
-{
-
-
-
-	presentMouseID = ImageID;
-}
-
-/***************************************************************************/
-UDWORD	pie_GetMouseID( void )
-{
-	return(presentMouseID);
-}
-/***************************************************************************/
-BOOL	pie_SwirlyBoxes( void )
-{
-	return(bSwirls);
-}
-
-void	pie_SetSwirlyBoxes( BOOL val )
-{
-	bSwirls = val;
-}
-
-BOOL	pie_WaveBlit( void )
-{
-	return(bWave);
-}
-
-void	pie_SetWaveBlit( BOOL val )
-{
-	bWave = val;
-}
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
Index: lib/ivis02/screen.h
===================================================================
--- lib/ivis02/screen.h	(revision 33)
+++ lib/ivis02/screen.h	(working copy)
@@ -23,6 +23,15 @@
 
 #include "types.h"
 
+/* Image structure */
+
+typedef struct {
+	unsigned int	width;
+	unsigned int	height;
+	unsigned int	channels;
+	unsigned char*	data;
+} pie_image;
+
 /* Free up a COM object */
 #undef RELEASE
 #define RELEASE(x) if ((x) != NULL) {(void)(x)->lpVtbl->Release(x); (x) = NULL;}
Index: lib/ivis02/pieclip.c
===================================================================
--- lib/ivis02/pieclip.c	(revision 33)
+++ lib/ivis02/pieclip.c	(working copy)
@@ -7,29 +7,17 @@
  */
 /***************************************************************************/
 
-#include "ivi.h"
 #include "pieclip.h"
-#include "frame.h"
-#include "piedef.h"
-#include "piestate.h"
-#include "rendmode.h"
+#include "ivi.h"
 
-
 /***************************************************************************/
 /*
- *	Local Definitions
+ *	Global Variables
  */
 /***************************************************************************/
 
-/***************************************************************************/
-/*
- *	Local Variables
- */
-/***************************************************************************/
+extern iSurface	*psRendSurface;
 
-static BOOL bClipSpecular = TRUE; 
-static UDWORD	videoBufferWidth = 640,videoBufferHeight = 480;
-
 /***************************************************************************/
 /*
  *	Local ProtoTypes
@@ -38,62 +26,15 @@
 
 static int _xtclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip);
 static int _ytclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip);
-static int _xclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip);
-static int _yclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip);
-static int pie_ClipXT(PIEVERTEX *s1, PIEVERTEX *s2, PIEVERTEX *clip);
-static int pie_ClipYT(PIEVERTEX *s1, PIEVERTEX *s2, PIEVERTEX *clip);
 
 /***************************************************************************/
 /*
  *	Source
  */
 /***************************************************************************/
-BOOL pie_SetVideoBuffer(UDWORD width, UDWORD height)
-{
-	videoBufferWidth = width;
-	videoBufferHeight = height;
-	return(TRUE);
-}
 
-/***************************************************************************/
-UDWORD pie_GetVideoBufferWidth(void)
-{
-	return(videoBufferWidth);
-}
-/***************************************************************************/
-UDWORD pie_GetVideoBufferHeight(void)
-{
-	return(videoBufferHeight);
-}
-/***************************************************************************/
-
-void pie_Set2DClip(int x0, int y0, int x1, int y1)
-{
-/*	if (pie_GetRenderEngine() == ENGINE_GLIDE)
-	{
-		grClipWindow((FxU32)x0,(FxU32)y0,(FxU32)x1,(FxU32)y1);
-	}
-	else if (pie_GetRenderEngine() == ENGINE_D3D)
-	{
-		D3DSetClipWindow(x0,y0,x1,y1);
-	}
-	else
-*/
-	{
-		psRendSurface->clip.left = x0;
-		psRendSurface->clip.top = y0;
-		psRendSurface->clip.right = x1;
-		psRendSurface->clip.bottom = y1;
-	}
-}
-
-
-//*************************************************************************
-
 int pie_PolyClipTex2D(int npoints, iVertex *points, iVertex *clip)
-
 {
-
 	static iVertex xclip[iV_POLY_MAX_POINTS+4];
 	iVertex *p0, *p1;
 	int n1, n, i;
@@ -126,128 +67,10 @@
 
 }
 
-//*************************************************************************
-// New clipper that clips rgb lighting values
-int pie_ClipTextured(int npoints, PIEVERTEX *points, PIEVERTEX *clip, BOOL bSpecular)
-
-{
-	static PIEVERTEX xclip[iV_POLY_MAX_POINTS+4];
-	PIEVERTEX *p0, *p1;
-	int n1, n, i;
-
-	bClipSpecular = bSpecular;
-
-	p0 = &points[0];
-	p1 = &points[1];
-
-	for (i=0, n1=0; i<npoints; i++, p0++, p1++) {
-
-		if (i==(npoints-1))
-			p1 = &points[0];
-
-		if ((p0->sx == 1<<15) || (p0->sy == -1<<15))//check for invalid points jps19aug97
-			return 0;
-
-		n1 += pie_ClipXT(p0,p1,&xclip[n1]);
-	}
-
-	p0 = &xclip[0];
-	p1 = &xclip[1];
-
-	for (i=0, n=0; i<n1; p0++, p1++, i++) {
-		if (i==(n1-1))
-			p1 = &xclip[0];
-		n += pie_ClipYT(p0,p1,&clip[n]);
-	}
-
-	return n;
-}
-
-//*************************************************************************
-/* Alex - much faster tri clipper - won't clip owt else tho' */
-int	pie_ClipTexturedTriangleFast(PIEVERTEX *v1, PIEVERTEX *v2, PIEVERTEX *v3, PIEVERTEX *clipped, BOOL bSpecular)
-{
-static	PIEVERTEX	xClip[iV_POLY_MAX_POINTS+4];	// plus 4 hopefully is limit?
-static	PIEVERTEX	*p0,*p1;
-UDWORD	numPreY,numAll;
-UDWORD	i;
-
-	bClipSpecular = bSpecular;
- 
-	numPreY = 0;
-	if( (v1->sx > LONG_TEST) OR (v1->sy > LONG_TEST) )
-	{
-		/* bomb out for out of range points */
-		return(0);
-	}
-	numPreY += pie_ClipXT(v1,v2,&xClip[numPreY]);
-
-	if( (v2->sx > LONG_TEST) OR (v2->sy > LONG_TEST) )
-	{
-		/* bomb out for out of range points */
-		return(0);
-	}
-	numPreY += pie_ClipXT(v2,v3,&xClip[numPreY]);
-
-	if( (v3->sx > LONG_TEST) OR (v3->sy > LONG_TEST) )
-	{
-		/* bomb out for out of range points */
-		return(0);
-	}
-	numPreY += pie_ClipXT(v3,v1,&xClip[numPreY]);
-
-	/* We've now clipped against x axis - now for Y */
-
-	p0 = &xClip[0];
-	p1 = &xClip[1];
-
-	for (i=0, numAll=0; i<numPreY; p0++, p1++, i++) {
-		if (i==(numPreY-1))
-			p1 = &xClip[0];
-		numAll += pie_ClipYT(p0,p1,&clipped[numAll]);
-	}
-
-	return numAll;
-}
-//*************************************************************************
-
-int iV_PolyClip2D(int npoints, iVertex *points, iVertex *clip)
-
-{
-	static iVertex xclip[iV_POLY_MAX_POINTS+4];
-	iVertex *p0, *p1;
-	int n1, n, i;
-
-
-	p0 = &points[0];
-	p1 = &points[1];
-
-	for (i=0, n1=0; i<npoints; i++, p0++, p1++) {
-
-		if (i==(npoints-1))
-			p1 = &points[0];
-
-		n1 += _xclip_edge2d(p0,p1,&xclip[n1]);
-	}
-
-	p0 = &xclip[0];
-	p1 = &xclip[1];
-
-	for (i=0, n=0; i<n1; p0++, p1++, i++) {
-		if (i==(n1-1))
-			p1 = &xclip[0];
-		n += _yclip_edge2d(p0,p1,&clip[n]);
-	}
-
-	return n;
-}
-
 /***************************************************************************/
 
 static int _xtclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip)
-
 {
-
 	int n, dx;
 	int32 t;
 
@@ -363,168 +186,9 @@
 }
 
 /***************************************************************************/
-// New version that clips rgb lighting values
-static int pie_ClipXT(PIEVERTEX *s1, PIEVERTEX *s2, PIEVERTEX *clip)
 
-{
-	int n, dx;
-	int32 t;
-
-	n = 1;
-
-	if (s2->sx >= s1->sx) {
-		if (s1->sx < psRendSurface->clip.left) {
-
-			if (s2->sx <= psRendSurface->clip.left) return 0;
-
-			dx = s2->sx - s1->sx;
-
-			if (dx != 0)
-				clip->sy = s1->sy + (s2->sy - s1->sy) * (psRendSurface->clip.left - s1->sx) / dx;
-			else
-				clip->sy = s1->sy;
-
-			clip->sx = psRendSurface->clip.left;
-
-			// clip uv
-			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
-
-			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
-			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-		} else
-			*clip = *s1;
-
-		if (s2->sx > psRendSurface->clip.right) {
-
-			if (s1->sx > psRendSurface->clip.right) return 0;
-
-			clip++;
-
-			dx = s2->sx - s1->sx;
-
-			if (dx != 0)
-				clip->sy = s2->sy - (s2->sy - s1->sy) * (s2->sx - psRendSurface->clip.right) / dx;
-			else
-				clip->sy = s2->sy;
-
-			clip->sx = psRendSurface->clip.right;
-
-			// clip uv
-			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
-			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
-  			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-			n = 2;
-		}
-
-		return n;
-
-	} else {
-		if (s1->sx > psRendSurface->clip.right) {
-
-			if (s2->sx >= psRendSurface->clip.right) return 0;
-
-			dx = s1->sx - s2->sx;
-
-			if (dx != 0)
-				clip->sy = s1->sy - (s1->sy - s2->sy) * (s1->sx - psRendSurface->clip.right) / dx;
-			else
-				clip->sy = s1->sy;
-
-			clip->sx = psRendSurface->clip.right;
-
-			// clip uv
-			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
-			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
-			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-
-		} else
-			*clip = *s1;
-
-
-		if (s2->sx < psRendSurface->clip.left) {
-
-			if (s1->sx < psRendSurface->clip.left)  return 0;
-
-			clip++;
-
-			dx = s1->sx - s2->sx;
-
-			if (dx != 0)
-				clip->sy = s2->sy + (s1->sy - s2->sy) * (psRendSurface->clip.left - s2->sx) / dx;
-			else
-				clip->sy = s2->sy;
-
-   		clip->sx = psRendSurface->clip.left;
-
-			// clip uv
-			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
-			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
-  			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-
-			n = 2;
-   	}
-		return n;
-	}
-}
-
-//*************************************************************************
-
 static int _ytclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip)
-
 {
-
 	register int n, dy;
 	int32 t;
 
@@ -641,349 +305,9 @@
 	}
 
 }
-//*************************************************************************
-// New version - clips rgb lighting values
-static int pie_ClipYT(PIEVERTEX *s1, PIEVERTEX *s2, PIEVERTEX *clip)
 
-{
-	register int n, dy;
-	int32 t;
-
-
-	n = 1;
-
-	if (s2->sy >= s1->sy) {
-
-		if (s1->sy < psRendSurface->clip.top) {
-
-			if (s2->sy <= psRendSurface->clip.top) return 0;
-
-			dy = s2->sy - s1->sy;
-
-			if (dy != 0)
-				clip->sx = s1->sx + (s2->sx - s1->sx) * (psRendSurface->clip.top - s1->sy) / dy;
-			else
-				clip->sx = s1->sx;
-
-			clip->sy = psRendSurface->clip.top;
-
-			// clip uv
-			t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
-			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
-			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-
-		} else
-			*clip = *s1;
-
-
-		if (s2->sy > psRendSurface->clip.bottom) {
-
-			if (s1->sy > psRendSurface->clip.bottom) return 0;
-
-			clip++;
-
-			dy = s2->sy - s1->sy;
-
-			if (dy != 0)
-				clip->sx = s2->sx - (s2->sx - s1->sx) * (s2->sy - psRendSurface->clip.bottom) / dy;
-			else
-				clip->sx = s2->sx;
-
-			clip->sy = psRendSurface->clip.bottom;
-
-			// clip uv
-			t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
-			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
-   			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-
-			n = 2;
-		}
-
-		return n;
-
-	} else {
-		if (s1->sy > psRendSurface->clip.bottom) {
-
-			if (s2->sy >= psRendSurface->clip.bottom) return 0;
-
-			dy = s1->sy - s2->sy;
-
-			if (dy != 0)
-				clip->sx = s1->sx - (s1->sx - s2->sx) * (s1->sy - psRendSurface->clip.bottom) / dy;
-			else
-				clip->sx = s1->sx;
-
-			clip->sy = psRendSurface->clip.bottom;
-
-			// clip uv
-			t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
-			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
-   			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
-
-		} else
-			*clip = *s1;
-
-		if (s2->sy < psRendSurface->clip.top) {
-
-			if (s1->sy < psRendSurface->clip.top) return 0;
-
-			clip++;
-
-			dy = s1->sy - s2->sy;
-
-			if (dy != 0)
-				clip->sx = s2->sx + (s1->sx - s2->sx) * (psRendSurface->clip.top - s2->sy) / dy;
-			else
-				clip->sx = s2->sx;
-
- 			clip->sy = psRendSurface->clip.top;
-
-			// clip uv
-			t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
-			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
-			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
-			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
-			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
-			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
-			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
-			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
-			if (bClipSpecular)
-			{
-				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
-				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
-				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
-				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
-			}
-
- 			n = 2;
-
-		}
-
-		return n;
-	}
-}
-
-
-static int _xclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip)
-
-{
-
-	int n, dx;
-
-	n = 1;
-
-	if (s2->x >= s1->x) {
-		if (s1->x < psRendSurface->clip.left) {
-
-			if (s2->x <= psRendSurface->clip.left) return 0;
-
-			dx = s2->x - s1->x;
-
-			if (dx != 0)
-				clip->y = s1->y + (s2->y - s1->y) * (psRendSurface->clip.left - s1->x) / dx;
-			else
-				clip->y = s1->y;
-
-			clip->x = psRendSurface->clip.left;
-
-		} else
-			*clip = *s1;
-
-		if (s2->x > psRendSurface->clip.right) {
-
-			if (s1->x > psRendSurface->clip.right) return 0;
-
-			clip++;
-
-			dx = s2->x - s1->x;
-
-			if (dx != 0)
-				clip->y = s2->y - (s2->y - s1->y) * (s2->x - psRendSurface->clip.right) / dx;
-			else
-				clip->y = s2->y;
-
-			clip->x = psRendSurface->clip.right;
-
-			n = 2;
-		}
-
-		return n;
-
-	} else {
-		if (s1->x > psRendSurface->clip.right) {
-
-			if (s2->x >= psRendSurface->clip.right) return 0;
-
-			dx = s1->x - s2->x;
-
-			if (dx != 0)
-				clip->y = s1->y - (s1->y - s2->y) * (s1->x - psRendSurface->clip.right) / dx;
-			else
-				clip->y = s1->y;
-
-			clip->x = psRendSurface->clip.right;
-
-		} else
-			*clip = *s1;
-
-
-		if (s2->x < psRendSurface->clip.left) {
-
-			if (s1->x < psRendSurface->clip.left)  return 0;
-
-			clip++;
-
-			dx = s1->x - s2->x;
-
-			if (dx != 0)
-				clip->y = s2->y + (s1->y - s2->y) * (psRendSurface->clip.left - s2->x) / dx;
-			else
-				clip->y = s2->y;
-
-   		clip->x = psRendSurface->clip.left;
-
-			n = 2;
-   	}
-		return n;
-	}
-
-}
-
-//*************************************************************************
-
-static int _yclip_edge2d(iVertex *s1, iVertex *s2, iVertex *clip)
-
-{
-
-	register int n, dy;
-
-
-	n = 1;
-
-	if (s2->y >= s1->y) {
-
-		if (s1->y < psRendSurface->clip.top) {
-
-			if (s2->y <= psRendSurface->clip.top) return 0;
-
-			dy = s2->y - s1->y;
-
-			if (dy != 0)
-				clip->x = s1->x + (s2->x - s1->x) * (psRendSurface->clip.top - s1->y) / dy;
-			else
-				clip->x = s1->x;
-
-			clip->y = psRendSurface->clip.top;
-
-		} else
-			*clip = *s1;
-
-
-		if (s2->y > psRendSurface->clip.bottom) {
-
-			if (s1->y > psRendSurface->clip.bottom) return 0;
-
-			clip++;
-
-			dy = s2->y - s1->y;
-
-			if (dy != 0)
-				clip->x = s2->x - (s2->x - s1->x) * (s2->y - psRendSurface->clip.bottom) / dy;
-			else
-				clip->x = s2->x;
-
-			clip->y = psRendSurface->clip.bottom;
-
-			n = 2;
-		}
-
-		return n;
-
-	} else {
-		if (s1->y > psRendSurface->clip.bottom) {
-
-			if (s2->y >= psRendSurface->clip.bottom) return 0;
-
-			dy = s1->y - s2->y;
-
-			if (dy != 0)
-				clip->x = s1->x - (s1->x - s2->x) * (s1->y - psRendSurface->clip.bottom) / dy;
-			else
-				clip->x = s1->x;
-
-			clip->y = psRendSurface->clip.bottom;
-
-		} else
-			*clip = *s1;
-
-		if (s2->y < psRendSurface->clip.top) {
-
-			if (s1->y < psRendSurface->clip.top) return 0;
-
-			clip++;
-
-			dy = s1->y - s2->y;
-
-			if (dy != 0)
-				clip->x = s2->x + (s1->x - s2->x) * (psRendSurface->clip.top - s2->y) / dy;
-			else
-				clip->x = s2->x;
-
- 			clip->y = psRendSurface->clip.top;
-
- 			n = 2;
-
-		}
-
-		return n;
-	}
-
-}
-
 int	pie_ClipFlat2dLine(SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1)
 {
-
-
-
 	if ((x0 > LONG_TEST) OR (y0 > LONG_TEST) )
 	{
 		/* bomb out for out of range points */
@@ -1004,7 +328,7 @@
 			return(0);
 		}
 		//relign left edge
-		
+
 		y0 = y0 + ((y1 - y0) * (psRendSurface->clip.left - x0))/(x1 - x0);
 		x0 = psRendSurface->clip.left;
 	}
@@ -1026,7 +350,7 @@
 			return(0);
 		}
 		//relign top
-		
+
 		x0 = x0 + ((x1 - x0) * (psRendSurface->clip.top - y0))/(y1 - y0);
 		y0 = psRendSurface->clip.top;
 	}
Index: lib/ivis_common/piestate.c
===================================================================
--- lib/ivis_common/piestate.c	(revision 0)
+++ lib/ivis_common/piestate.c	(revision 0)
@@ -0,0 +1,337 @@
+#include "piestate.h"
+
+SDWORD		pieStateCount = 0; // FIXME Is this really used somewhere? Or is it just a dummy?
+RENDER_STATE	rendStates;
+
+void pie_SetColourCombine(COLOUR_MODE colCombMode);
+void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode);
+static void pie_SetTexCombine(TEX_MODE texCombMode);
+static void pie_SetAlphaCombine(ALPHA_MODE alphaCombMode);
+
+void pie_SetDefaultStates(void)//Sets all states
+{
+//		pie_SetFogColour(0x00B08f5f);//nicks colour
+	//fog off
+	rendStates.fogEnabled = FALSE;// enable fog before renderer
+	rendStates.fog = FALSE;//to force reset to false
+	pie_SetFogStatus(FALSE);
+	pie_SetFogColour(0x00000000);//nicks colour
+
+	//depth Buffer on
+	rendStates.depthBuffer = FALSE;//to force reset to true
+	pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
+
+	//set render mode
+	pie_SetTranslucent(TRUE);
+	pie_SetAdditive(TRUE);
+
+	//basic gouraud textured rendering
+	rendStates.texCombine = TEX_NONE;//to force reset to GOURAUD_TEX
+	pie_SetTexCombine(TEX_LOCAL);
+	rendStates.colourCombine = COLOUR_FLAT_CONSTANT;//to force reset to GOURAUD_TEX
+	pie_SetColourCombine(COLOUR_TEX_ITERATED);
+	rendStates.alphaCombine = ALPHA_ITERATED;//to force reset to GOURAUD_TEX
+	pie_SetAlphaCombine(ALPHA_CONSTANT);
+	rendStates.transMode = TRANS_ALPHA;//to force reset to DECAL
+	pie_SetTranslucencyMode(TRANS_DECAL);
+
+	//chroma keying on black
+	rendStates.keyingOn = FALSE;//to force reset to true
+	pie_SetColourKeyedBlack(TRUE);
+
+	//bilinear filtering
+	rendStates.bilinearOn = FALSE;//to force reset to true
+	pie_SetBilinear(TRUE);
+}
+
+void pie_SetRenderEngine(REND_ENGINE rendEngine)
+{
+	rendStates.rendEngine = rendEngine;
+	if( rendEngine == ENGINE_4101 )
+		rendStates.bHardware = FALSE;
+	else
+		rendStates.bHardware = TRUE;
+}
+
+REND_ENGINE pie_GetRenderEngine(void)
+{
+	return rendStates.rendEngine;
+}
+
+BOOL	pie_Hardware(void)
+{
+	return rendStates.bHardware;
+}
+
+//***************************************************************************
+//
+// pie_SetTranslucent(BOOL val);
+//
+// Global enable/disable Translucent effects
+//
+//***************************************************************************
+
+void pie_SetTranslucent(BOOL val)
+{
+	rendStates.translucent = val;
+}
+
+BOOL pie_Translucent(void)
+{
+	return rendStates.translucent;
+}
+
+//***************************************************************************
+//
+// pie_SetAdditive(BOOL val);
+//
+// Global enable/disable Additive effects
+//
+//***************************************************************************
+
+void pie_SetAdditive(BOOL val)
+{
+	rendStates.additive = val;
+}
+
+BOOL pie_Additive(void)
+{
+	return rendStates.additive;
+}
+
+//***************************************************************************
+//
+// pie_SetCaps(BOOL val);
+//
+// HIGHEST LEVEL enable/disable modes
+//
+//***************************************************************************
+
+void pie_SetFogCap(FOG_CAP val)
+{
+	rendStates.fogCap = val;
+}
+
+FOG_CAP pie_GetFogCap(void)
+{
+	return rendStates.fogCap;
+}
+
+void pie_SetTexCap(TEX_CAP val)
+{
+	rendStates.texCap = val;
+}
+
+TEX_CAP pie_GetTexCap(void)
+{
+	return rendStates.texCap;
+}
+
+//***************************************************************************
+//
+// pie_EnableFog(BOOL val)
+//
+// Global enable/disable fog to allow fog to be turned of ingame
+//
+//***************************************************************************
+
+void pie_EnableFog(BOOL val)
+{
+	if (rendStates.fogCap == FOG_CAP_NO)
+	{
+		val = FALSE;
+	}
+	if (rendStates.fogEnabled != val)
+	{
+		rendStates.fogEnabled = val;
+		if (val == TRUE)
+		{
+//			pie_SetFogColour(0x0078684f);//(nicks colour + 404040)/2
+			pie_SetFogColour(0x00B08f5f);//nicks colour
+		}
+		else
+		{
+			pie_SetFogColour(0x00000000);//clear background to black
+		}
+
+	}
+}
+
+BOOL pie_GetFogEnabled(void)
+{
+	return rendStates.fogEnabled;
+}
+
+//***************************************************************************
+//
+// pie_SetFogStatus(BOOL val)
+//
+// Toggle fog on and off for rendering objects inside or outside the 3D world
+//
+//***************************************************************************
+
+BOOL pie_GetFogStatus(void)
+{
+	return rendStates.fog;
+}
+
+void pie_SetFogColour(UDWORD colour)
+{
+	UDWORD grey;
+	if (rendStates.fogCap == FOG_CAP_GREY)
+	{
+		grey = colour & 0xff;
+		colour >>= 8;
+		grey += (colour & 0xff);
+		colour >>= 8;
+		grey += (colour & 0xff);
+		grey /= 3;
+		grey &= 0xff;//check only
+		colour = grey + (grey<<8) + (grey<<16);
+		rendStates.fogColour = colour;
+	}
+	else if (rendStates.fogCap == FOG_CAP_NO)
+	{
+		rendStates.fogColour = 0;
+	}
+	else
+	{
+		rendStates.fogColour = colour;
+	}
+}
+
+UDWORD pie_GetFogColour(void)
+{
+	return rendStates.fogColour;
+}
+
+void pie_SetRendMode(REND_MODE rendMode)
+{
+	if (rendMode != rendStates.rendMode)
+	{
+		rendStates.rendMode = rendMode;
+		switch (rendMode)
+		{
+			case REND_GOURAUD_TEX:
+				pie_SetColourCombine(COLOUR_TEX_ITERATED);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_CONSTANT);
+				pie_SetTranslucencyMode(TRANS_DECAL);
+				break;
+			case REND_ALPHA_TEX:
+				pie_SetColourCombine(COLOUR_TEX_ITERATED);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_ITERATED);
+				pie_SetTranslucencyMode(TRANS_ALPHA);
+				break;
+			case REND_ADDITIVE_TEX:
+				pie_SetColourCombine(COLOUR_TEX_ITERATED);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_ITERATED);
+				pie_SetTranslucencyMode(TRANS_ADDITIVE);
+				break;
+			case REND_TEXT:
+				pie_SetColourCombine(COLOUR_TEX_CONSTANT);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_CONSTANT);
+				pie_SetTranslucencyMode(TRANS_DECAL);
+				break;
+			case REND_ALPHA_TEXT:
+				pie_SetColourCombine(COLOUR_TEX_CONSTANT);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_CONSTANT);
+				pie_SetTranslucencyMode(TRANS_ALPHA);
+				break;
+			case REND_ALPHA_FLAT:
+				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_CONSTANT);
+				pie_SetTranslucencyMode(TRANS_ALPHA);
+				break;
+			case REND_ALPHA_ITERATED:
+				pie_SetColourCombine(COLOUR_FLAT_ITERATED);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_ITERATED);
+				pie_SetTranslucencyMode(TRANS_ADDITIVE);
+				break;
+			case REND_FILTER_FLAT:
+				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_CONSTANT);
+				pie_SetTranslucencyMode(TRANS_FILTER);
+				break;
+			case REND_FILTER_ITERATED:
+				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_ITERATED);
+				pie_SetTranslucencyMode(TRANS_ALPHA);
+				break;
+			case REND_FLAT:
+				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
+				pie_SetTexCombine(TEX_LOCAL);
+				pie_SetAlphaCombine(ALPHA_CONSTANT);
+				pie_SetTranslucencyMode(TRANS_DECAL);
+			default:
+				break;
+		}
+	}
+	return;
+}
+
+void pie_SetBilinear(BOOL bilinearOn)
+{
+#ifndef PIETOOL
+	if (bilinearOn != rendStates.bilinearOn)
+{
+	rendStates.bilinearOn = bilinearOn;
+	pieStateCount++;
+}
+#endif
+}
+
+BOOL pie_GetBilinear(void)
+{
+#ifndef PIETOOL
+	return rendStates.bilinearOn;
+#else
+	return FALSE;
+#endif
+}
+
+static void pie_SetTexCombine(TEX_MODE texCombMode)
+{
+#ifndef PIETOOL	//ffs
+	if (texCombMode != rendStates.texCombine)
+{
+	rendStates.texCombine = texCombMode;
+	pieStateCount++;
+}
+#endif
+}
+
+static void pie_SetAlphaCombine(ALPHA_MODE alphaCombMode)
+{
+#ifndef PIETOOL	//ffs
+	if (alphaCombMode != rendStates.alphaCombine)
+{
+	rendStates.alphaCombine = alphaCombMode;
+	pieStateCount++;
+}
+#endif
+}
+
+/***************************************************************************/
+// get the constant colour used in text and flat render modes
+/***************************************************************************/
+UDWORD pie_GetColour(void)
+{
+	return	rendStates.colour;
+}
+
+void WZ_DEPRECATED pie_SetMouse(IMAGEFILE *psImageFile,UWORD ImageID)
+{
+}
+
+void WZ_DEPRECATED pie_SetSwirlyBoxes( BOOL val )
+{
+}
Index: lib/ivis_common/piestate.h
===================================================================
--- lib/ivis_common/piestate.h	(revision 33)
+++ lib/ivis_common/piestate.h	(working copy)
@@ -41,7 +41,7 @@
 					REND_ALPHA_FLAT,
 					REND_ALPHA_ITERATED,
 					REND_FILTER_FLAT,
-					REND_FILTER_ITERATED			
+					REND_FILTER_ITERATED
 				}
 				REND_MODE;
 
@@ -82,6 +82,61 @@
 				}
 				TEX_CAP;
 
+typedef	enum	COLOUR_MODE
+				{
+					COLOUR_FLAT_CONSTANT,
+					COLOUR_FLAT_ITERATED,
+					COLOUR_TEX_ITERATED,
+					COLOUR_TEX_CONSTANT
+				}
+				COLOUR_MODE;
+
+typedef	enum	TEX_MODE
+				{
+					TEX_LOCAL,
+					TEX_NONE
+				}
+				TEX_MODE;
+
+typedef	enum	ALPHA_MODE
+				{
+					ALPHA_ITERATED,
+					ALPHA_CONSTANT
+				}
+				ALPHA_MODE;
+
+
+typedef struct	RENDER_STATE
+				{
+					REND_ENGINE			rendEngine;
+					BOOL				bHardware;
+					DEPTH_MODE			depthBuffer;
+					BOOL				translucent;
+					BOOL				additive;
+					FOG_CAP				fogCap;
+					BOOL				fogEnabled;
+					BOOL				fog;
+					UDWORD				fogColour;
+					TEX_CAP				texCap;
+					SDWORD				texPage;
+					REND_MODE			rendMode;
+					BOOL				bilinearOn;
+					BOOL				keyingOn;
+					COLOUR_MODE			colourCombine;
+					TEX_MODE			texCombine;
+					ALPHA_MODE			alphaCombine;
+					TRANSLUCENCY_MODE	transMode;
+					UDWORD				colour;
+#ifdef STATES
+					BOOL				textured;
+					UBYTE				lightLevel;
+#endif
+					// FIXME Needed???
+					// 	UBYTE				DDrawDriverName[256];
+					// 	UBYTE				D3DDriverName[256];
+				}
+				RENDER_STATE;
+
 #define NO_TEXPAGE -1
 
 /***************************************************************************/
@@ -130,13 +185,7 @@
 extern void pie_SetColour(UDWORD val);
 extern UDWORD pie_GetColour(void);
 //mouse states
-extern void pie_DrawMouse(SDWORD x, SDWORD y);
 extern void pie_SetMouse(IMAGEFILE *ImageFile,UWORD ImageID);
-extern UDWORD	pie_GetMouseID( void );
-extern BOOL	pie_SwirlyBoxes( void );
 extern void	pie_SetSwirlyBoxes( BOOL val );
-extern BOOL	pie_WaveBlit( void );
-extern void	pie_SetWaveBlit( BOOL val );
-void pie_ResetStates(void);//Sets all states
 
 #endif // _pieState_h
Index: lib/ivis_common/pieclip.c
===================================================================
--- lib/ivis_common/pieclip.c	(revision 0)
+++ lib/ivis_common/pieclip.c	(revision 0)
@@ -0,0 +1,418 @@
+#include "pieclip.h"
+#include "ivi.h"
+
+static BOOL bClipSpecular = TRUE;
+static UDWORD	videoBufferWidth = 640, videoBufferHeight = 480;
+extern iSurface	*psRendSurface;
+
+BOOL pie_SetVideoBuffer(UDWORD width, UDWORD height)
+{
+	videoBufferWidth = width;
+	videoBufferHeight = height;
+	return(TRUE);
+}
+
+UDWORD pie_GetVideoBufferWidth(void)
+{
+	return(videoBufferWidth);
+}
+
+UDWORD pie_GetVideoBufferHeight(void)
+{
+	return(videoBufferHeight);
+}
+
+void pie_Set2DClip(int x0, int y0, int x1, int y1)
+{
+	psRendSurface->clip.left = x0;
+	psRendSurface->clip.top = y0;
+	psRendSurface->clip.right = x1;
+	psRendSurface->clip.bottom = y1;
+}
+
+static int pie_ClipXT(PIEVERTEX *s1, PIEVERTEX *s2, PIEVERTEX *clip)
+{
+	int n, dx;
+	int32 t;
+
+	n = 1;
+
+	if (s2->sx >= s1->sx) {
+		if (s1->sx < psRendSurface->clip.left) {
+			if (s2->sx <= psRendSurface->clip.left)
+				return 0;
+
+			dx = s2->sx - s1->sx;
+
+			if (dx != 0)
+				clip->sy = s1->sy + (s2->sy - s1->sy) * (psRendSurface->clip.left - s1->sx) / dx;
+			else
+				clip->sy = s1->sy;
+
+			clip->sx = psRendSurface->clip.left;
+
+			// clip uv
+			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
+
+			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
+			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
+			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
+			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
+			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
+			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
+			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
+			if (bClipSpecular)
+			{
+				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
+				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
+				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
+				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
+			}
+
+		} else
+			*clip = *s1;
+
+		if (s2->sx > psRendSurface->clip.right) {
+			if (s1->sx > psRendSurface->clip.right)
+				return 0;
+
+			clip++;
+			dx = s2->sx - s1->sx;
+
+			if (dx != 0)
+				clip->sy = s2->sy - (s2->sy - s1->sy) * (s2->sx - psRendSurface->clip.right) / dx;
+			else
+				clip->sy = s2->sy;
+
+			clip->sx = psRendSurface->clip.right;
+
+			// clip uv
+			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
+			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
+			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
+			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
+			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
+			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
+			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
+			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
+			if (bClipSpecular) {
+				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
+				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
+				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
+				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
+			}
+
+			n = 2;
+		}
+		return n;
+
+	} else {
+		if (s1->sx > psRendSurface->clip.right) {
+
+			if (s2->sx >= psRendSurface->clip.right) return 0;
+
+			dx = s1->sx - s2->sx;
+
+			if (dx != 0)
+				clip->sy = s1->sy - (s1->sy - s2->sy) * (s1->sx - psRendSurface->clip.right) / dx;
+			else
+				clip->sy = s1->sy;
+
+			clip->sx = psRendSurface->clip.right;
+
+			// clip uv
+			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
+			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
+			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
+			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
+			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
+			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
+			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
+			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
+			if (bClipSpecular)
+			{
+				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
+				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
+				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
+				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
+			}
+
+
+		} else
+			*clip = *s1;
+
+
+		if (s2->sx < psRendSurface->clip.left) {
+			if (s1->sx < psRendSurface->clip.left)
+				return 0;
+
+			clip++;
+			dx = s1->sx - s2->sx;
+
+			if (dx != 0)
+				clip->sy = s2->sy + (s1->sy - s2->sy) * (psRendSurface->clip.left - s2->sx) / dx;
+			else
+				clip->sy = s2->sy;
+
+			clip->sx = psRendSurface->clip.left;
+
+			// clip uv
+			t = ((clip->sx - s1->sx)<<iV_DIVSHIFT) / dx;
+			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
+			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
+			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
+			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
+			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
+			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
+			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
+			if (bClipSpecular)
+			{
+				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
+				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
+				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
+				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
+			}
+
+			n = 2;
+		}
+		return n;
+	}
+}
+
+static int pie_ClipYT(PIEVERTEX *s1, PIEVERTEX *s2, PIEVERTEX *clip)
+{
+	int n, dy;
+	int32 t;
+
+	n = 1;
+
+	if (s2->sy >= s1->sy) {
+
+		if (s1->sy < psRendSurface->clip.top) {
+
+			if (s2->sy <= psRendSurface->clip.top) return 0;
+
+			dy = s2->sy - s1->sy;
+
+			if (dy != 0)
+				clip->sx = s1->sx + (s2->sx - s1->sx) * (psRendSurface->clip.top - s1->sy) / dy;
+			else
+				clip->sx = s1->sx;
+
+			clip->sy = psRendSurface->clip.top;
+
+			// clip uv
+			t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
+			clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
+			clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
+			clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
+			clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
+			clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
+			clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
+			clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
+			if (bClipSpecular)
+			{
+				clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
+				clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
+				clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
+				clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
+			}
+
+
+		} else
+			*clip = *s1;
+
+
+			if (s2->sy > psRendSurface->clip.bottom) {
+
+				if (s1->sy > psRendSurface->clip.bottom) return 0;
+
+				clip++;
+
+				dy = s2->sy - s1->sy;
+
+				if (dy != 0)
+					clip->sx = s2->sx - (s2->sx - s1->sx) * (s2->sy - psRendSurface->clip.bottom) / dy;
+				else
+					clip->sx = s2->sx;
+
+				clip->sy = psRendSurface->clip.bottom;
+
+			// clip uv
+				t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
+				clip->tu = s1->tu + ((t * (s2->tu - s1->tu)) >> iV_DIVSHIFT);
+				clip->tv = s1->tv + ((t * (s2->tv - s1->tv)) >> iV_DIVSHIFT);
+				clip->sz = s1->sz + ((t * (s2->sz - s1->sz)) >> iV_DIVSHIFT);
+				clip->light.byte.r = s1->light.byte.r + ((t * (s2->light.byte.r - s1->light.byte.r)) >> iV_DIVSHIFT);
+				clip->light.byte.g = s1->light.byte.g + ((t * (s2->light.byte.g - s1->light.byte.g)) >> iV_DIVSHIFT);
+				clip->light.byte.b = s1->light.byte.b + ((t * (s2->light.byte.b - s1->light.byte.b)) >> iV_DIVSHIFT);
+				clip->light.byte.a = s1->light.byte.a + ((t * (s2->light.byte.a - s1->light.byte.a)) >> iV_DIVSHIFT);
+				if (bClipSpecular)
+				{
+					clip->specular.byte.r = s1->specular.byte.r + ((t * (s2->specular.byte.r - s1->specular.byte.r)) >> iV_DIVSHIFT);
+					clip->specular.byte.g = s1->specular.byte.g + ((t * (s2->specular.byte.g - s1->specular.byte.g)) >> iV_DIVSHIFT);
+					clip->specular.byte.b = s1->specular.byte.b + ((t * (s2->specular.byte.b - s1->specular.byte.b)) >> iV_DIVSHIFT);
+					clip->specular.byte.a = s1->specular.byte.a + ((t * (s2->specular.byte.a - s1->specular.byte.a)) >> iV_DIVSHIFT);
+				}
+
+
+				n = 2;
+			}
+
+			return n;
+
+	} else {
+		if (s1->sy > psRendSurface->clip.bottom) {
+
+			if (s2->sy >= psRendSurface->clip.bottom) return 0;
+
+			dy = s1->sy - s2->sy;
+
+			if (dy != 0)
+				clip->sx = s1->sx - (s1->sx - s2->sx) * (s1->sy - psRendSurface->clip.bottom) / dy;
+			else
+				clip->sx = s1->sx;
+
+			clip->sy = psRendSurface->clip.bottom;
+
+			// clip uv
+			t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
+			clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
+			clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
+			clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
+			clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
+			clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
+			clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
+			clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
+			if (bClipSpecular)
+			{
+				clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
+				clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
+				clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
+				clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
+			}
+
+
+		} else
+			*clip = *s1;
+
+			if (s2->sy < psRendSurface->clip.top) {
+
+				if (s1->sy < psRendSurface->clip.top) return 0;
+
+				clip++;
+
+				dy = s1->sy - s2->sy;
+
+				if (dy != 0)
+					clip->sx = s2->sx + (s1->sx - s2->sx) * (psRendSurface->clip.top - s2->sy) / dy;
+				else
+					clip->sx = s2->sx;
+
+				clip->sy = psRendSurface->clip.top;
+
+			// clip uv
+				t = ((clip->sy - s1->sy)<<iV_DIVSHIFT) / dy;
+				clip->tu = s1->tu + ((t * (s1->tu - s2->tu)) >> iV_DIVSHIFT);
+				clip->tv = s1->tv + ((t * (s1->tv - s2->tv)) >> iV_DIVSHIFT);
+				clip->sz = s1->sz + ((t * (s1->sz - s2->sz)) >> iV_DIVSHIFT);
+				clip->light.byte.r = s1->light.byte.r + ((t * (s1->light.byte.r - s2->light.byte.r)) >> iV_DIVSHIFT);
+				clip->light.byte.g = s1->light.byte.g + ((t * (s1->light.byte.g - s2->light.byte.g)) >> iV_DIVSHIFT);
+				clip->light.byte.b = s1->light.byte.b + ((t * (s1->light.byte.b - s2->light.byte.b)) >> iV_DIVSHIFT);
+				clip->light.byte.a = s1->light.byte.a + ((t * (s1->light.byte.a - s2->light.byte.a)) >> iV_DIVSHIFT);
+				if (bClipSpecular)
+				{
+					clip->specular.byte.r = s1->specular.byte.r + ((t * (s1->specular.byte.r - s2->specular.byte.r)) >> iV_DIVSHIFT);
+					clip->specular.byte.g = s1->specular.byte.g + ((t * (s1->specular.byte.g - s2->specular.byte.g)) >> iV_DIVSHIFT);
+					clip->specular.byte.b = s1->specular.byte.b + ((t * (s1->specular.byte.b - s2->specular.byte.b)) >> iV_DIVSHIFT);
+					clip->specular.byte.a = s1->specular.byte.a + ((t * (s1->specular.byte.a - s2->specular.byte.a)) >> iV_DIVSHIFT);
+				}
+
+				n = 2;
+
+			}
+
+			return n;
+	}
+}
+
+int pie_ClipTextured(int npoints, PIEVERTEX *points, PIEVERTEX *clip, BOOL bSpecular)
+{
+	static PIEVERTEX xclip[iV_POLY_MAX_POINTS+4];
+	PIEVERTEX *p0, *p1;
+	int n1, n, i;
+
+	bClipSpecular = bSpecular;
+
+	p0 = &points[0];
+	p1 = &points[1];
+
+	for (i=0, n1=0; i<npoints; i++, p0++, p1++) {
+
+		if (i==(npoints-1))
+			p1 = &points[0];
+
+		if ((p0->sx == 1<<15) || (p0->sy == -1<<15))//check for invalid points jps19aug97
+			return 0;
+
+		n1 += pie_ClipXT(p0,p1,&xclip[n1]);
+	}
+
+	p0 = &xclip[0];
+	p1 = &xclip[1];
+
+	for (i=0, n=0; i<n1; p0++, p1++, i++) {
+		if (i==(n1-1))
+			p1 = &xclip[0];
+		n += pie_ClipYT(p0,p1,&clip[n]);
+	}
+
+	return n;
+}
+
+//*************************************************************************
+/* Alex - much faster tri clipper - won't clip owt else tho' */
+int	pie_ClipTexturedTriangleFast(PIEVERTEX *v1, PIEVERTEX *v2, PIEVERTEX *v3, PIEVERTEX *clipped, BOOL bSpecular)
+{
+	static	PIEVERTEX	xClip[iV_POLY_MAX_POINTS+4];	// plus 4 hopefully is limit?
+	static	PIEVERTEX	*p0,*p1;
+	UDWORD	numPreY,numAll;
+	UDWORD	i;
+
+	bClipSpecular = bSpecular;
+
+	numPreY = 0;
+	if( (v1->sx > LONG_TEST) OR (v1->sy > LONG_TEST) )
+	{
+		/* bomb out for out of range points */
+		return(0);
+	}
+	numPreY += pie_ClipXT(v1,v2,&xClip[numPreY]);
+
+	if( (v2->sx > LONG_TEST) OR (v2->sy > LONG_TEST) )
+	{
+		/* bomb out for out of range points */
+		return(0);
+	}
+	numPreY += pie_ClipXT(v2,v3,&xClip[numPreY]);
+
+	if( (v3->sx > LONG_TEST) OR (v3->sy > LONG_TEST) )
+	{
+		/* bomb out for out of range points */
+		return(0);
+	}
+	numPreY += pie_ClipXT(v3,v1,&xClip[numPreY]);
+
+	/* We've now clipped against x axis - now for Y */
+
+	p0 = &xClip[0];
+	p1 = &xClip[1];
+
+	for (i=0, numAll=0; i<numPreY; p0++, p1++, i++) {
+		if (i==(numPreY-1))
+			p1 = &xClip[0];
+		numAll += pie_ClipYT(p0,p1,&clipped[numAll]);
+	}
+
+	return numAll;
+}
Index: lib/ivis_common/pieclip.h
===================================================================
--- lib/ivis_common/pieclip.h	(revision 33)
+++ lib/ivis_common/pieclip.h	(working copy)
@@ -26,23 +26,14 @@
 
 /***************************************************************************/
 /*
- *	Global Variables
- */
-/***************************************************************************/
-
-/***************************************************************************/
-/*
  *	Global ProtoTypes
  */
 /***************************************************************************/
-extern void pie_Set2DClip(int x0, int y0, int x1, int y1);
-extern int	pie_PolyClipTex2D(int npoints, iVertex *points, iVertex *clip);
-extern int	pie_PolyClip2D(int npoints, iVertex *points, iVertex *clip);
-extern int	pie_ClipTextured(int npoints, PIEVERTEX *points, PIEVERTEX *clip, BOOL bSpecular);
-extern int	pie_ClipTexturedTriangleFast(PIEVERTEX *v1, PIEVERTEX *v2, PIEVERTEX *v3, PIEVERTEX *clipped, BOOL bSpecular);
-extern int	pie_ClipFlat2dLine(SDWORD x0, SDWORD y0, SDWORD x1, SDWORD y1);
-extern BOOL	pie_SetVideoBuffer(UDWORD width, UDWORD height);
-extern UDWORD	pie_GetVideoBufferWidth( void );
-extern UDWORD	pie_GetVideoBufferHeight( void );
+void pie_Set2DClip(int x0, int y0, int x1, int y1);
+int	pie_ClipTextured(int npoints, PIEVERTEX *points, PIEVERTEX *clip, BOOL bSpecular);
+int	pie_ClipTexturedTriangleFast(PIEVERTEX *v1, PIEVERTEX *v2, PIEVERTEX *v3, PIEVERTEX *clipped, BOOL bSpecular);
+BOOL	pie_SetVideoBuffer(UDWORD width, UDWORD height);
+UDWORD	pie_GetVideoBufferWidth( void );
+UDWORD	pie_GetVideoBufferHeight( void );
 
 #endif // _pieclip_h
Index: lib/ivis_common/Makefile.am
===================================================================
--- lib/ivis_common/Makefile.am	(revision 33)
+++ lib/ivis_common/Makefile.am	(working copy)
@@ -19,11 +19,13 @@
 	ivispatch.h \
 	pieblitfunc.h \
 	pieclip.h \
+	pieclip.c \
 	piedef.h \
 	piefunc.h \
 	piemode.h \
 	piepalette.h \
 	piestate.h \
+	piestate.c \
 	pietypes.h \
 	rendfunc.h \
 	rendmode.h \
Index: lib/ivis_opengl/piestate.c
===================================================================
--- lib/ivis_opengl/piestate.c	(revision 33)
+++ lib/ivis_opengl/piestate.c	(working copy)
@@ -8,7 +8,7 @@
 /***************************************************************************/
 
 #include <string.h>
-#ifdef _MSC_VER	
+#ifdef _MSC_VER
 #include <windows.h>  //needed for gl.h!  --Qamly
 #endif
 #include <GL/gl.h>
@@ -24,194 +24,32 @@
  */
 /***************************************************************************/
 
-SDWORD		pieStateCount = 0;
-BOOL		bSwirls = FALSE;
-BOOL		bWave = FALSE;
+extern RENDER_STATE	rendStates;
+
 /***************************************************************************/
 /*
  *	Local Definitions
  */
 /***************************************************************************/
 
-typedef	enum	COLOUR_MODE
-				{
-					COLOUR_FLAT_CONSTANT,
-					COLOUR_FLAT_ITERATED,
-					COLOUR_TEX_ITERATED,
-					COLOUR_TEX_CONSTANT
-				}
-				COLOUR_MODE;
-
-typedef	enum	TEX_MODE
-				{
-					TEX_LOCAL,
-					TEX_NONE
-				}
-				TEX_MODE;
-
-typedef	enum	ALPHA_MODE
-				{
-					ALPHA_ITERATED,
-					ALPHA_CONSTANT
-				}
-				ALPHA_MODE;
-
-typedef struct _renderState
-{
-	REND_ENGINE			rendEngine;
-	BOOL				bHardware;
-	DEPTH_MODE			depthBuffer;
-	BOOL				translucent;
-	BOOL				additive;
-	FOG_CAP				fogCap;
-	BOOL				fogEnabled;
-	BOOL				fog;
-	UDWORD				fogColour;
-	TEX_CAP				texCap;
-	SDWORD				texPage;
-	REND_MODE			rendMode;
-	BOOL				bilinearOn;
-	BOOL				keyingOn;
-	COLOUR_MODE			colourCombine;
-	TEX_MODE			texCombine;
-	ALPHA_MODE			alphaCombine;
-	TRANSLUCENCY_MODE	transMode;
-	UDWORD				colour;
-#ifdef STATES
-	BOOL				textured;
-	UBYTE				lightLevel;
-#endif
-	UBYTE				DDrawDriverName[256];
-	UBYTE				D3DDriverName[256];
-} RENDER_STATE;
-
 /***************************************************************************/
 /*
  *	Local Variables
  */
 /***************************************************************************/
 
-RENDER_STATE	rendStates;
-
 /***************************************************************************/
 /*
  *	Local ProtoTypes
  */
 /***************************************************************************/
-static void pie_SetColourCombine(COLOUR_MODE colCombMode);
-static void pie_SetTexCombine(TEX_MODE texCombMode);
-static void pie_SetAlphaCombine(ALPHA_MODE alphaCombMode);
-static void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode);
-//static void pie_SetAlphaCombine(BOOL trans);
 
 /***************************************************************************/
 /*
  *	Source
  */
 /***************************************************************************/
-void pie_SetDefaultStates(void)//Sets all states
-{
-//		pie_SetFogColour(0x00B08f5f);//nicks colour
-	//fog off
-	rendStates.fogEnabled = FALSE;// enable fog before renderer
-	rendStates.fog = FALSE;//to force reset to false
-	pie_SetFogStatus(FALSE);
-	pie_SetFogColour(0x00000000);//nicks colour
 
-	//depth Buffer on
-	rendStates.depthBuffer = FALSE;//to force reset to true
-	pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
-
-	//set render mode
-	pie_SetTranslucent(TRUE);
-	pie_SetAdditive(TRUE);
-	
-	//basic gouraud textured rendering
-	rendStates.texCombine = TEX_NONE;//to force reset to GOURAUD_TEX
-	pie_SetTexCombine(TEX_LOCAL);
-	rendStates.colourCombine = COLOUR_FLAT_CONSTANT;//to force reset to GOURAUD_TEX
-	pie_SetColourCombine(COLOUR_TEX_ITERATED);
-	rendStates.alphaCombine = ALPHA_ITERATED;//to force reset to GOURAUD_TEX
-	pie_SetAlphaCombine(ALPHA_CONSTANT);
-	rendStates.transMode = TRANS_ALPHA;//to force reset to DECAL
-	pie_SetTranslucencyMode(TRANS_DECAL);
-
-	//chroma keying on black
-	rendStates.keyingOn = FALSE;//to force reset to true
-	pie_SetColourKeyedBlack(TRUE);
-
-	//bilinear filtering
-	rendStates.bilinearOn = FALSE;//to force reset to true
-	pie_SetBilinear(TRUE);
-}
-
-/***************************************************************************/
-/***************************************************************************/
-void pie_ResetStates(void)//Sets all states
-{
-	SDWORD		temp;
-
-//		pie_SetFogColour(0x00B08f5f);//nicks colour
-	rendStates.fog = !rendStates.fog;//to force reset
-	pie_SetFogStatus(!rendStates.fog);
-
-	//depth Buffer on
-	temp = rendStates.depthBuffer;
-	rendStates.depthBuffer = -1;//to force reset
-	pie_SetDepthBufferStatus(temp);
-
-	//set render mode
-//	pie_SetTranslucent(TRUE);
-//	pie_SetAdditive(TRUE);
-	
-	//basic gouraud textured rendering
-	temp = rendStates.texCombine;
-	rendStates.texCombine = -1;//to force reset
-	pie_SetTexCombine(temp);
-
-	temp = rendStates.colourCombine;
-	rendStates.colourCombine = -1;//to force reset
-	pie_SetColourCombine(temp);
-
-	temp = rendStates.alphaCombine;
-	rendStates.alphaCombine = -1;//to force reset
-	pie_SetAlphaCombine(temp);
-
-	temp = rendStates.transMode;
-	rendStates.transMode = -1;//to force reset
-	pie_SetTranslucencyMode(temp);
-
-	//chroma keying on black
-	temp = rendStates.keyingOn;
-	rendStates.keyingOn = -1;//to force reset
-	pie_SetColourKeyedBlack(temp);
-
-	//bilinear filtering
-	temp = rendStates.bilinearOn;
-	rendStates.bilinearOn = -1;//to force reset
-	pie_SetBilinear(temp);
-}
-
-/***************************************************************************/
-/***************************************************************************/
-
-void pie_SetRenderEngine(REND_ENGINE rendEngine) {
-//	printf("renderstate is (old)%d (new)%d\n",rendStates.rendEngine,rendEngine);	//Quick check to see what we using. -Q
-	rendStates.rendEngine = rendEngine;
-}
-
-REND_ENGINE pie_GetRenderEngine(void) {
-//	printf("renderstate is :%d\n",rendStates.rendEngine);		//Quick check to see what we are using -Q
-	return rendStates.rendEngine;
-}
-
-BOOL	pie_Hardware(void) {
-	return TRUE;
-}
-
-/***************************************************************************/
-/***************************************************************************/
-
 void pie_SetDepthBufferStatus(DEPTH_MODE depthMode) {
 	switch(depthMode) {
 		case DEPTH_CMP_LEQ_WRT_ON:
@@ -237,106 +75,6 @@
 
 //***************************************************************************
 //
-// pie_SetTranslucent(BOOL val);
-//
-// Global enable/disable Translucent effects 
-//
-//***************************************************************************
-
-void pie_SetTranslucent(BOOL val)
-{
-	rendStates.translucent = val;
-}
-
-BOOL pie_Translucent(void)
-{
-	return rendStates.translucent;
-}
-
-//***************************************************************************
-//
-// pie_SetAdditive(BOOL val);
-//
-// Global enable/disable Additive effects 
-//
-//***************************************************************************
-
-void pie_SetAdditive(BOOL val)
-{
-	rendStates.additive = val;
-}
-
-BOOL pie_Additive(void)
-{
-	return rendStates.additive;
-}
-
-//***************************************************************************
-//
-// pie_SetCaps(BOOL val);
-//
-// HIGHEST LEVEL enable/disable modes 
-//
-//***************************************************************************
-
-
-void pie_SetFogCap(FOG_CAP val)
-{
-	rendStates.fogCap = val;
-}
-
-FOG_CAP pie_GetFogCap(void)
-{
-	return rendStates.fogCap;
-}
-
-void pie_SetTexCap(TEX_CAP val)
-{
-	rendStates.texCap = val;
-}
-
-TEX_CAP pie_GetTexCap(void)
-{
-	return rendStates.texCap;
-}
-
-//***************************************************************************
-//
-// pie_EnableFog(BOOL val)
-//
-// Global enable/disable fog to allow fog to be turned of ingame 
-//
-//***************************************************************************
-
-void pie_EnableFog(BOOL val)
-{
-	if (rendStates.fogCap == FOG_CAP_NO)
-	{
-		val = FALSE;
-	}
-	if (rendStates.fogEnabled != val)
-	{
-		rendStates.fogEnabled = val;
-		if (val == TRUE)
-		{
-//			pie_SetFogColour(0x0078684f);//(nicks colour + 404040)/2
-			pie_SetFogColour(0x00B08f5f);//nicks colour
-		}
-		else
-		{
-			pie_SetFogColour(0x00000000);//clear background to black
-		}
-
-	}
-}
-
-BOOL pie_GetFogEnabled(void)
-{
-	return  rendStates.fogEnabled;
-}
-
-//***************************************************************************
-//
 // pie_SetFogStatus(BOOL val)
 //
 // Toggle fog on and off for rendering objects inside or outside the 3D world
@@ -350,7 +88,7 @@
 
 	if (rendStates.fogEnabled)
 	{
-		//fog enabled so toggle if required 
+		//fog enabled so toggle if required
 		if (rendStates.fog != val)
 		{
 			rendStates.fog = val;
@@ -376,7 +114,7 @@
 	}
 	else
 	{
-		//fog disabled so turn it off if not off already 
+		//fog disabled so turn it off if not off already
 		if (rendStates.fog != FALSE)
 		{
 			rendStates.fog = FALSE;
@@ -384,41 +122,7 @@
 	}
 }
 
-BOOL pie_GetFogStatus(void)
-{
-	return  rendStates.fog;
-}
 /***************************************************************************/
-void pie_SetFogColour(UDWORD colour)
-{
-	UDWORD grey;
- 	if (rendStates.fogCap == FOG_CAP_GREY)
-	{
-		grey = colour & 0xff;
-		colour >>= 8;
-		grey += (colour & 0xff);
-		colour >>= 8;
-		grey += (colour & 0xff);
-		grey /= 3;
-		grey &= 0xff;//check only
-		colour = grey + (grey<<8) + (grey<<16);
-		rendStates.fogColour = colour;
-	}
-	else if (rendStates.fogCap == FOG_CAP_NO)
-	{
-		rendStates.fogColour = 0;
-	}
-	else
-	{
-		rendStates.fogColour = colour;
-	}
-}
-
-UDWORD pie_GetFogColour(void)
-{
-	return rendStates.fogColour;
-}
-/***************************************************************************/
 void pie_SetTexturePage(SDWORD num)
 {
 #ifndef PIETOOL
@@ -435,81 +139,7 @@
 }
 
 /***************************************************************************/
-void pie_SetRendMode(REND_MODE rendMode)
-{
-	if (rendMode != rendStates.rendMode)
-	{
-		rendStates.rendMode = rendMode;
-		switch (rendMode)
-		{
-			case REND_GOURAUD_TEX:
-				pie_SetColourCombine(COLOUR_TEX_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_DECAL);
-				break;
-			case REND_ALPHA_TEX:
-				pie_SetColourCombine(COLOUR_TEX_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_ADDITIVE_TEX:
-				pie_SetColourCombine(COLOUR_TEX_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ADDITIVE);
-				break;
-			case REND_TEXT:
-				pie_SetColourCombine(COLOUR_TEX_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_DECAL);
-				break;
-			case REND_ALPHA_TEXT:
-				pie_SetColourCombine(COLOUR_TEX_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_ALPHA_FLAT:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_ALPHA_ITERATED:
-				pie_SetColourCombine(COLOUR_FLAT_ITERATED);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ADDITIVE);
-				break;
-		   	case REND_FILTER_FLAT:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_FILTER);
-				break;
-			case REND_FILTER_ITERATED:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_ITERATED);
-				pie_SetTranslucencyMode(TRANS_ALPHA);
-				break;
-			case REND_FLAT:
-				pie_SetColourCombine(COLOUR_FLAT_CONSTANT);
-				pie_SetTexCombine(TEX_LOCAL);
-				pie_SetAlphaCombine(ALPHA_CONSTANT);
-				pie_SetTranslucencyMode(TRANS_DECAL);
-			default:
-				break;
-		}
-	}
-	return;
-}
 
-/***************************************************************************/
-
 void pie_SetColourKeyedBlack(BOOL keyingOn)
 {
 #ifndef PIETOOL
@@ -529,41 +159,19 @@
 }
 
 /***************************************************************************/
-void pie_SetBilinear(BOOL bilinearOn)
+void pie_SetColourCombine(COLOUR_MODE colCombMode)
 {
-#ifndef PIETOOL
-	if (bilinearOn != rendStates.bilinearOn)
-	{
-		rendStates.bilinearOn = bilinearOn;
-		pieStateCount++;
-	}
-#endif
-}
-
-BOOL pie_GetBilinear(void)
-{
-#ifndef PIETOOL
-	return rendStates.bilinearOn;
-#else
-	return FALSE;
-#endif
-}
-
-/***************************************************************************/
-static void pie_SetColourCombine(COLOUR_MODE colCombMode)
-{
 #ifndef PIETOOL	//ffs
 
 	if (colCombMode != rendStates.colourCombine) {
 		rendStates.colourCombine = colCombMode;
 		pieStateCount++;
 		switch (colCombMode) {
-			case COLOUR_TEX_CONSTANT:
-				break;
 			case COLOUR_FLAT_CONSTANT:
 			case COLOUR_FLAT_ITERATED:
 				pie_SetTexturePage(-1);
 				break;
+			case COLOUR_TEX_CONSTANT:
 			case COLOUR_TEX_ITERATED:
 			default:
 				break;
@@ -573,32 +181,8 @@
 }
 
 /***************************************************************************/
-static void pie_SetTexCombine(TEX_MODE texCombMode)
+void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode)
 {
-#ifndef PIETOOL	//ffs
-	if (texCombMode != rendStates.texCombine)
-	{
-		rendStates.texCombine = texCombMode;
-		pieStateCount++;
-	}
-#endif
-}
-
-/***************************************************************************/
-static void pie_SetAlphaCombine(ALPHA_MODE alphaCombMode)
-{
-#ifndef PIETOOL	//ffs
-	if (alphaCombMode != rendStates.alphaCombine)
-	{
-		rendStates.alphaCombine = alphaCombMode;
-		pieStateCount++;
-	}
-#endif
-}
-
-/***************************************************************************/
-static void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode)
-{
 #ifndef PIETOOL
 	if (transMode != rendStates.transMode) {
 		rendStates.transMode = transMode;
@@ -611,7 +195,7 @@
 				glEnable(GL_BLEND);
 				glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 				break;
-			case TRANS_FILTER:						
+			case TRANS_FILTER:
 				glEnable(GL_BLEND);
 				glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR);
 				break;
@@ -641,62 +225,6 @@
 }
 
 /***************************************************************************/
-// get the constant colour used in text and flat render modes
-/***************************************************************************/
-UDWORD pie_GetColour(void)
-{
-	return	rendStates.colour;
-}
-
-/***************************************************************************/
 void pie_SetGammaValue(float val)
 {
 }
-
-/***************************************************************************/
-void pie_DrawMouse(SDWORD x,SDWORD y)
-{
-}
-
-/***************************************************************************/
-UWORD	presentMouseID;
-void pie_SetMouse(IMAGEFILE *psImageFile,UWORD ImageID)
-{
-	presentMouseID = ImageID;
-}
-
-/***************************************************************************/
-UDWORD	pie_GetMouseID( void )
-{
-	return(presentMouseID);
-}
-/***************************************************************************/
-BOOL	pie_SwirlyBoxes( void )
-{
-	return(bSwirls);
-}
-
-void	pie_SetSwirlyBoxes( BOOL val )
-{
-	bSwirls = val;
-}
-
-BOOL	pie_WaveBlit( void )
-{
-	return(bWave);
-}
-
-void	pie_SetWaveBlit( BOOL val )
-{
-	bWave = val;
-}
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
-/***************************************************************************/
Index: lib/ivis_opengl/screen.h
===================================================================
--- lib/ivis_opengl/screen.h	(revision 33)
+++ lib/ivis_opengl/screen.h	(working copy)
@@ -23,7 +23,6 @@
 
 #include "types.h"
 
-
 /* Image structure */
 
 typedef struct {
@@ -33,8 +32,6 @@
 	unsigned char*	data;
 } pie_image;
 
-
-
 /* Free up a COM object */
 #undef RELEASE
 #define RELEASE(x) if ((x) != NULL) {(void)(x)->lpVtbl->Release(x); (x) = NULL;}
Index: lib/ivis_opengl/Makefile.am
===================================================================
--- lib/ivis_opengl/Makefile.am	(revision 33)
+++ lib/ivis_opengl/Makefile.am	(working copy)
@@ -5,7 +5,6 @@
 	bspimd.c \
 	ivi.c \
 	pieblitfunc.c \
-	pieclip.c \
 	piedraw.c \
 	piefunc.c \
 	piematrix.c \
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 33)
+++ src/Makefile.am	(working copy)
@@ -270,7 +270,6 @@
 		../lib/script/libscript.a \
 		../lib/ivis_common/libivis_common.a \
 		../lib/$(RENDERER)/lib$(RENDERER).a \
-		../lib/ivis_common/libivis_common.a \
 		../lib/gamelib/libgamelib.a \
 		../lib/sequence/libsequence.a \
 		../lib/widget/libwidget.a

Attachment: pgpnIji9LyaY2.pgp
Description: PGP signature



Reply via email to