#include <d3d.h>
#include <ddraw.h>
 
/*
 =======================================================================================
    Vertex Access Macros 
 =======================================================================================
 */
 
/* GET*/
#define GetX(a) a.sx
#define GetY(a) a.sy
#define GetZ(a) a.rhw
#define GetPackedColor(a) a.color
#define GetPackedSpecular(a) a.specular
#define GetU(a) a.tu
#define GetV(a) a.tv
/* SET*/
#define SetX(a,b) a.sx = b
#define SetY(a,b) a.sy = b
#define SetZ(a,b) a.sz = a.rhw = b
#define SetPackedColor(a,b) a.color = b
#define SetPackedSpecular(a,b) a.specular = b
#define SetU(a,b) a.tu = b
#define SetV(a,b) a.tv = b
#define SetU_Cpy(a,b) a.tu = b
#define SetV_Cpy(a,b) a.tv = b
 
/*
 =======================================================================================
    Globals
 =======================================================================================
 */
 
/*
double fNumberOfTexels = 0;
double fNumberMinOfTexels = 1e30;
double fNumberMaxOfTexels = 0;
*/
 
/*
 * Draw primitive flag
 */
#define GLI_C_dwDPFlag_NoClip   D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT
#define GLI_C_dwDPFlag_Clip     D3DDP_DONOTLIGHT
 
DWORD   dwDrawPrimitiveFlag = GLI_C_dwDPFlag_NoClip;
 
 
/*
 * D3D vertex buffer
 */
#define GLI_tdScreenVertx D3DTLVERTEX
 
GLI_tdScreenVertx   ga_stVertexBuffer[ 3000 ];
GLI_tdScreenVertx   *CurrentDestXYZ = ga_stVertexBuffer;
 
/*
 =======================================================================================
    External
 =======================================================================================
 */
extern LPDIRECT3DDEVICE3		g_pd3dDevice;
 
extern void GLI_DRV_xSendSpriteToClip_TRIANGLES( GLI_tdstAligned2DVector *a4_st2DVertex, GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT);
 
/*
 =======================================================================================
    Function & macros
 =======================================================================================
 */
 
#define GLI_M_RestoreCW()
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : called before a complex object is drawn
                complex object is several faces with same material
 ----------------------------------------------------------------------------------------
 */
void GLI_BeforeDraw()
{
    CurrentDestXYZ = ga_stVertexBuffer;
};
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : called after complex object is send
 ----------------------------------------------------------------------------------------
 */
void GLI_AfterDraw()
{
    long lVertexNumber;
 
    if ((lVertexNumber = CurrentDestXYZ - ga_stVertexBuffer) != 0)
    {
/*        if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
            return;
*/
       
        /* Draw the triangles*/
	    g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_TRIANGLELIST, D3DFVF_TLVERTEX, ga_stVertexBuffer, lVertexNumber, dwDrawPrimitiveFlag );
	
        /* End the scene.*/
/*        g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice); */
    }
 
    /* bench : count texels*/
    /*
    if ( GLI_BIG_GLOBALS->p_stCurrentTexture != NULL)
    {
        GLI_tdScreenVertx   *p_stCurVertex = ga_stVertexBuffer;
        unsigned long       ulSizeOfTexture = GLI_BIG_GLOBALS->p_stCurrentTexture->lHeight * GLI_BIG_GLOBALS->p_stCurrentTexture->lWidth / 2;
        float               fLocalNumberOfTexels, fSizeInPixel;
 
        while (p_stCurVertex != CurrentDestXYZ)
        {
            fLocalNumberOfTexels = fabs( ( p_stCurVertex[0].tu - p_stCurVertex[1].tu ) * fabs( p_stCurVertex[0].tv - p_stCurVertex[2].tv ) * ulSizeOfTexture);
            fSizeInPixel = fabs( ( p_stCurVertex[0].sx - p_stCurVertex[1].sx ) * fabs( p_stCurVertex[0].sy - p_stCurVertex[2].sy ) * 0.5f);
 
            if (fSizeInPixel > fLocalNumberOfTexels)
                fLocalNumberOfTexels = fSizeInPixel;
 
            fNumberOfTexels += fLocalNumberOfTexels;
 
            p_stCurVertex += 3;
        }
    }
    */
};
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : Draw single triangle stored in CurrentDestXYZ array
 ----------------------------------------------------------------------------------------
 */
GLI_FuncNodeBegin(GLI_vDrawTriangle)
{
    CurrentDestXYZ += 3;
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : Add a single triangle in Z sorted list
 ----------------------------------------------------------------------------------------
 */
GLI_FuncNodeBegin(GLI_vZSortTriangle)
{
	float ZMax;
	
	if ((unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint > (unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_TableOfPoints + ((3L << GLI_MaxZListeTrianglesPO2)* sizeof (GLI_tdScreenVertx)) - 3L * sizeof(GLI_tdScreenVertx))
        return;
 
	memcpy(GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint , CurrentDestXYZ , sizeof(GLI_tdScreenVertx) * 3L);
    if (*(unsigned long *)&GetZ(CurrentDestXYZ[0]) < *(unsigned long *)&GetZ(CurrentDestXYZ[1]))
        *(unsigned long *)&ZMax = *(unsigned long *)&GetZ(CurrentDestXYZ[0]);
    else
        *(unsigned long *)&ZMax = *(unsigned long *)&GetZ(CurrentDestXYZ[1]);
    if (*(unsigned long *)&ZMax > *(unsigned long *)&GetZ(CurrentDestXYZ[2]))
        *(unsigned long *)&ZMax = *(unsigned long *)&GetZ(CurrentDestXYZ[2]);
    GLI_v_AddNodeInZList(ZMax);
    
	(unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint += sizeof(GLI_tdScreenVertx) * 3L;
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : Add a single triangle in Z sorted list
 ----------------------------------------------------------------------------------------
 */
GLI_FuncNodeBegin(GLI_vDrawWiredTriangle)
{
/*    if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
		return;
*/
        
    /* Draw the triangle using a DrawPrimitive() call. */
    CurrentDestXYZ[3] = CurrentDestXYZ[0];
	g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINESTRIP, D3DFVF_TLVERTEX, CurrentDestXYZ, 4, GLI_C_dwDPFlag_Clip );
 
    /* End the scene.*/
/*    g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice); */
}
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : draw a quad stored in CurrentDestXYZ array or add it in Z list
                    
                     1-----0
                      |  /|     Send two triangle : 0 1 2 and 3 2 0
                      | / |     
                      |/  |
                     2-----3
 ----------------------------------------------------------------------------------------
 */
void GLI_DrawQuad(void)
{
    /* draw 2 triangles */
    /*
	CurrentDestXYZ[0].color = 0xFFFFFFFF;
	CurrentDestXYZ[1].color = 0xFFFFFFFF;
	CurrentDestXYZ[2].color = 0xFFFFFFFF;
	CurrentDestXYZ[3].color = 0xFFFFFFFF;
	*/
    
    if ( GLI_BIG_GLOBALS -> lClippingModeMask & GLI_C_TrianglesMustBeSorted )
    {
        GLI_BIG_GLOBALS -> lCurrentDrawMask &= ~GLI_C_lIsGouraud;
        if ((unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint > (unsigned long)GLI_BIG_GLOBALS -> p_TheZListe -> p_TableOfPoints + ((3L << GLI_MaxZListeTrianglesPO2)* sizeof (GLI_tdScreenVertx)) - 4L * sizeof(GLI_tdScreenVertx))
            return;
        memcpy(GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint , CurrentDestXYZ , sizeof(GLI_tdScreenVertx) * 4L);
        GLI_v_AddNodeInZList(GetZ(CurrentDestXYZ[0]));
        (unsigned long) GLI_BIG_GLOBALS -> p_TheZListe -> p_CurrentPoint += sizeof(GLI_tdScreenVertx) * 4L;
    } 
	else
    {
        CurrentDestXYZ[4] = CurrentDestXYZ[2];
        CurrentDestXYZ[5] = CurrentDestXYZ[0];
        CurrentDestXYZ += 6;
    }
 
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : Draw a line
 ----------------------------------------------------------------------------------------
 */
void GLI_DrawLine(void)
{
/*    if( FAILED( g_pd3dDevice->lpVtbl->BeginScene(g_pd3dDevice) ) )
		return;
*/
        
    /* Draw the triangle using a DrawPrimitive() call. */
	
	g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINELIST, D3DFVF_TLVERTEX, CurrentDestXYZ, 2, GLI_C_dwDPFlag_Clip );
	//g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, CurrentDestXYZ, 2, GLI_C_dwDPFlag_Clip );
    /* End the scene.*/
/*    g_pd3dDevice->lpVtbl->EndScene(g_pd3dDevice); */
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : draw Zsorted triangle
 ----------------------------------------------------------------------------------------
 */
 
void GLI_vDrawZSortedTriangle(void *p_3Point)
{
    memcpy( CurrentDestXYZ, p_3Point, 3 * sizeof(GLI_tdScreenVertx) );
    CurrentDestXYZ += 3;
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : draw ZSorted quad
 ----------------------------------------------------------------------------------------
 */
void GLI_vDrawZSortedQuad(void *p_3Point)
{
    memcpy( CurrentDestXYZ, p_3Point, 4 * sizeof(GLI_tdScreenVertx) );
    CurrentDestXYZ[4] = *((GLI_tdScreenVertx *) p_3Point + 2);
    CurrentDestXYZ[5] = *((GLI_tdScreenVertx *) p_3Point);
    CurrentDestXYZ += 6;
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : choose good drawing function
 ----------------------------------------------------------------------------------------
 */
void GLI_vAddDrawFunc()
{
    if (GLI_BIG_GLOBALS -> lClippingModeMask & GLI_C_TrianglesMustBeSorted)
    {
        GLI_M_AddFunc(GLI_vZSortTriangle);
    }
#ifdef _DEBUG
    else if ( (GLI_BIG_GLOBALS->lCurrentDrawMask & GLI_C_lIsNotWired) == 0 )
	{
		GLI_M_AddFunc(GLI_vDrawWiredTriangle);
	}
#endif
    else
    {
    GLI_M_AddFunc(GLI_vDrawTriangle);
    }
}
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : compute clipping mask
 ----------------------------------------------------------------------------------------
 */
void GLI_ReComputeClippingMask()
{
    *(float *)&fX_CMP_Optimize = GLI_BIG_GLOBALS->fXMaxClipping;
	*(float *)&fY_CMP_Optimize = GLI_BIG_GLOBALS->fYMaxClipping;
	*(float *)&fXMin_CLIP_Optimize = GLI_BIG_GLOBALS->fXMinClipping;
	*(float *)&fYMin_CLIP_Optimize = GLI_BIG_GLOBALS->fYMinClipping;
	*(float *)&fXMax_CLIP_Optimize = GLI_BIG_GLOBALS->fXMaxClipping;
    *(float *)&fYMax_CLIP_Optimize = GLI_BIG_GLOBALS->fYMaxClipping;
 
    GLI_BIG_GLOBALS->lClippingModeMask |= (GLI_BIG_GLOBALS->lClippingModeMask & GLI_C_lCLIP_ALL) << 4;
    /*
    if (GLI_BIG_GLOBALS->lClippingModeMask & GLI_C_lCLIP_ALL == 0)
    {
        dwDrawPrimitiveFlag = GLI_C_dwDPFlag_NoClip;
    }
    else
    {
        dwDrawPrimitiveFlag = GLI_C_dwDPFlag_Clip;
    }
    */
}
 
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : clip a sprite
 ----------------------------------------------------------------------------------------
 */
void GLI_DRV_vSendSpriteToClip
	(
		GLI_tdstAligned2DVector *a4_st2DVertex ,
		MTH_tdxReal				xZ ,
		GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT
	)
{
	float           fClipYMax, fClipYMin, fClipXMax, fClipXMin;
    unsigned long   ulColor;
 
    GLI_BeforeDraw();
 
    if (a4_st2DVertex[0].xY == a4_st2DVertex[1].xY) /* Aligned sprite */
    {
        GLI_ReComputeClippingMask();
 
        if ( ( *(long *) &a4_st2DVertex[0].xY > fYMax_CLIP_Optimize) || (*(long *) &a4_st2DVertex[2].xY < fYMin_CLIP_Optimize) || (*(long *) &a4_st2DVertex[0].xX < fXMin_CLIP_Optimize) || (*(long *) &a4_st2DVertex[1].xX > fXMax_CLIP_Optimize) )
		    return;
 
        /*
	     * clip xMax
	     */
	    if ( *(long *) &a4_st2DVertex[0].xX > fXMax_CLIP_Optimize )
	    {
		    fClipXMax = (GLI_BIG_GLOBALS->fXMaxClipping - a4_st2DVertex[1].xX) / ( a4_st2DVertex[0].xX - a4_st2DVertex[1].xX );
		    a4_st2DVertex[0].xX = a4_st2DVertex[3].xX = GLI_BIG_GLOBALS->fXMaxClipping;
	    }
	    else
		    fClipXMax = 1.0f;
 
	    /*
	     * clip xMin
	     */
	    if ( *(long *) &a4_st2DVertex[1].xX < fXMin_CLIP_Optimize )
	    {
		    fClipXMin = (fClipXMax * ( GLI_BIG_GLOBALS->fXMinClipping - a4_st2DVertex[1].xX) ) / ( a4_st2DVertex[0].xX - a4_st2DVertex[1].xX );
		    a4_st2DVertex[1].xX = a4_st2DVertex[2].xX = GLI_BIG_GLOBALS->fXMinClipping;
	    }
	    else 
		    fClipXMin = 0.0f;
	
	    /*
	     * clip yMin
	     */
	    if ( *(long *) &a4_st2DVertex[0].xY < fYMin_CLIP_Optimize )
	    {
		    fClipYMin = (GLI_BIG_GLOBALS->fYMinClipping - a4_st2DVertex[2].xY) / ( a4_st2DVertex[0].xY - a4_st2DVertex[2].xY );
		    a4_st2DVertex[0].xY = a4_st2DVertex[1].xY = GLI_BIG_GLOBALS->fYMinClipping;
	    }
	    else
		    fClipYMin = 1.0f;
 
	    /*
	     * clip yMax
	     */
	    if ( *(long *) &a4_st2DVertex[2].xY > fYMax_CLIP_Optimize )
	    {
		    fClipYMax = (fClipYMin * ( GLI_BIG_GLOBALS->fYMaxClipping - a4_st2DVertex[2].xY ) ) / ( a4_st2DVertex[0].xY - a4_st2DVertex[2].xY );
		    a4_st2DVertex[2].xY = a4_st2DVertex[3].xY = GLI_BIG_GLOBALS->fYMaxClipping;
	    }
	    else 
		    fClipYMax = 0.0f;
    }
    else
    {
        if ( *(long *) &GLI_BIG_GLOBALS->xWaterPlaneDistance != 0 );
        {
            GLI_DRV_xSendSpriteToClip_TRIANGLES( a4_st2DVertex, p_stGlobaleMT);
            return;
        }
 
	    if ( (a4_st2DVertex [0] . xY < 0.0f) || (a4_st2DVertex [1] . xY < 0.0f) || (a4_st2DVertex [2] . xY < 0.0f) || (a4_st2DVertex [3] . xY < 0.0f) ) return;
        if ( (a4_st2DVertex [0] . xX < 0.0f) || (a4_st2DVertex [1] . xX < 0.0f) || (a4_st2DVertex [2] . xX < 0.0f) || (a4_st2DVertex [3] . xX < 0.0f) ) return;
        if ( (a4_st2DVertex [0] . xY > 480.0f) || (a4_st2DVertex [1] . xY > 480.0f) || (a4_st2DVertex [2] . xY > 480.0f) || (a4_st2DVertex [3] . xY > 480.0f) ) return;
        if ( (a4_st2DVertex [0] . xX > 640.0f) || (a4_st2DVertex [1] . xX > 640.0f) || (a4_st2DVertex [2] . xX > 640.0f) || (a4_st2DVertex [3] . xX > 640.0f) ) return;
        fClipXMin = fClipYMax = 0.0f;
        fClipYMin = fClipXMax = 1.0f;
    }
 
    GLI_M_InitSprite();
 
    ulColor = (p_stGlobaleMT->xTextureDontAcceptFog) ? 0xFF000000 : p_stGlobaleMT->ulSpecularColorForSprite;
    SetPackedSpecular( CurrentDestXYZ[0], ulColor );
    SetPackedSpecular( CurrentDestXYZ[1], ulColor );
    SetPackedSpecular( CurrentDestXYZ[2], ulColor );
    SetPackedSpecular( CurrentDestXYZ[3], ulColor );
	
	SetU(CurrentDestXYZ[0], fClipXMax );
	SetV(CurrentDestXYZ[0], fClipYMin );
    SetU(CurrentDestXYZ[1], fClipXMin );
	SetV(CurrentDestXYZ[1], fClipYMin );
	SetU(CurrentDestXYZ[2], fClipXMin );
	SetV(CurrentDestXYZ[2], fClipYMax );
    SetU(CurrentDestXYZ[3], fClipXMax );
	SetV(CurrentDestXYZ[3], fClipYMax );
 
    GLI_DrawQuad();
    GLI_AfterDraw();
 
}
 
/*
 ----------------------------------------------------------------------------------------
  Description   : clip a sprite that have UV coordinates (it seems to be unused)
 ----------------------------------------------------------------------------------------
 */
void GLI_DRV_vSendSpriteToClipWithUV
(
 GLI_tdstAligned2DVector *a4_st2DVertex ,
 MTH_tdxReal *a8_stUVVertex,
 MTH_tdxReal xZ ,
 GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT)
{
    unsigned long   ulColor;

    GLI_BeforeDraw();
    GLI_M_InitSprite();
 
    if (a4_st2DVertex [0] . xY < 0.0f) return;
    if (a4_st2DVertex [1] . xY < 0.0f) return;
    if (a4_st2DVertex [2] . xY < 0.0f) return;
    if (a4_st2DVertex [3] . xY < 0.0f) return;
    if (a4_st2DVertex [0] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
    if (a4_st2DVertex [1] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
    if (a4_st2DVertex [2] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
    if (a4_st2DVertex [3] . xY > GLI_BIG_GLOBALS->fYMaxClipping) return;
 
    ulColor = (p_stGlobaleMT->xTextureDontAcceptFog) ? 0xFF000000 : p_stGlobaleMT->ulSpecularColorForSprite;
    SetPackedSpecular( CurrentDestXYZ[0], ulColor );
    SetPackedSpecular( CurrentDestXYZ[1], ulColor );
    SetPackedSpecular( CurrentDestXYZ[2], ulColor );
    SetPackedSpecular( CurrentDestXYZ[3], ulColor );
 
    if ( p_stGlobaleMT->p_stCurrentTexture->lIncrementIsEnable )
    {
        float fAddU, fAddV;
        fAddU = p_stGlobaleMT-> p_stCurrentTexture -> fAddU;
        fAddV = p_stGlobaleMT-> p_stCurrentTexture -> fAddV;
        SetU(CurrentDestXYZ[2], a8_stUVVertex[4] + fAddU );
        SetV(CurrentDestXYZ[2], a8_stUVVertex[4 + 1] + fAddV);
        SetU(CurrentDestXYZ[3], a8_stUVVertex[6] + fAddU);
        SetV(CurrentDestXYZ[3], a8_stUVVertex[6 + 1] + fAddV);
        SetU(CurrentDestXYZ[0], a8_stUVVertex[0] + fAddU);
        SetV(CurrentDestXYZ[0], a8_stUVVertex[0 + 1] + fAddV);
        SetU(CurrentDestXYZ[1], a8_stUVVertex[2] + fAddU);
        SetV(CurrentDestXYZ[1], a8_stUVVertex[2 + 1] + fAddV);
    }
    else
    {
        SetU(CurrentDestXYZ[2], a8_stUVVertex[4]);
        SetV(CurrentDestXYZ[2], a8_stUVVertex[4 + 1]);
        SetU(CurrentDestXYZ[3], a8_stUVVertex[6]);
        SetV(CurrentDestXYZ[3], a8_stUVVertex[6 + 1]);
        SetU(CurrentDestXYZ[0], a8_stUVVertex[0]);
        SetV(CurrentDestXYZ[0], a8_stUVVertex[0 + 1]);
        SetU(CurrentDestXYZ[1], a8_stUVVertex[2]);
        SetV(CurrentDestXYZ[1], a8_stUVVertex[2 + 1]);
    }
    GLI_DrawQuad();
    GLI_AfterDraw();
}
 
 
/*
 ----------------------------------------------------------------------------------------
  Description   : clip a line (not implemented)
 ----------------------------------------------------------------------------------------
 */
#if 0
void GLI_DRV_vSendSingleLineToClip
	(
		GLD_tdstViewportAttributes *p_stVpt ,
        GLI_tdstAligned3DVector *p_stVertex1 ,
        GLI_tdstAligned2DVector *p_st2DVertex1 ,
        GLI_tdstAligned3DVector *p_stVertex2 ,
        GLI_tdstAligned2DVector *p_st2DVertex2 ,
        GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT,
        long lDrawModeMask, GEO_tdstColor *p_stColor
	)
{
	
	  p_st2DVertex1->ulPackedColor =0xFFFFFFFF;
	  p_st2DVertex2->ulPackedColor =0xFFFFFFFF;
 
    GLI_M_InitLine();
	GLI_DrawLine();
}
#else

void GLI_DRV_vSendSingleLineToClip
	(
		GLD_tdstViewportAttributes *p_stVpt ,
        GLI_tdstAligned3DVector           *p_stVertex1 ,
        GLI_tdstAligned2DVector    *p_st2DVertex1 ,
        GLI_tdstAligned3DVector           *p_stVertex2 ,
        GLI_tdstAligned2DVector    *p_st2DVertex2 ,
		 GLI_tdstInternalGlobalValuesFor3dEngine *p_stGlobaleMT,
        long lDrawModeMask, GEO_tdstColor *p_stColor
	)
{


    DWORD dwRenderState;   
	
	g_pd3dDevice->lpVtbl->GetRenderState(g_pd3dDevice, D3DRENDERSTATE_ZENABLE,&dwRenderState);
	g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice, D3DRENDERSTATE_ZENABLE, FALSE);
	g_pd3dDevice->lpVtbl->SetTexture(g_pd3dDevice,0, NULL );

	SetX(CurrentDestXYZ[0],p_st2DVertex1->xX);
	SetY(CurrentDestXYZ[0],p_st2DVertex1->xY);
	SetX(CurrentDestXYZ[1],p_st2DVertex2->xX);
	SetY(CurrentDestXYZ[1],p_st2DVertex2->xY);
	SetZ(CurrentDestXYZ[0],p_st2DVertex1->xOoZ );
	SetZ(CurrentDestXYZ[1],p_st2DVertex2->xOoZ );
	SetPackedColor(CurrentDestXYZ[0],p_st2DVertex1->ulPackedColor  );
	SetPackedColor(CurrentDestXYZ[1],p_st2DVertex2->ulPackedColor  );

	g_pd3dDevice->lpVtbl->DrawPrimitive( g_pd3dDevice, D3DPT_LINELIST, D3DFVF_TLVERTEX, CurrentDestXYZ, 2, GLI_C_dwDPFlag_Clip );

	g_pd3dDevice->lpVtbl->SetRenderState(g_pd3dDevice, D3DRENDERSTATE_ZENABLE, (BOOL)dwRenderState);

}

#endif
