#include "3dglodef.h"
/************************************************************************************
*					some global 3d variables go here
************************************************************************************/

	int edge_id=0, edge_debug=0;

	float wibble_table[WIBBLE_SIZE]; 
	sint32 wibble_offset=0, water_effect=0;
	sint32 rand_table[WIBBLE_SIZE], shade_effect=0;
	sint16 shade_table[WIBBLE_SIZE];

	sint32		ls_adder;
	sint32		ls_divider;

	int	   		perspective_distance = ((3*1024)<<W2V_SHIFT);
//	int			mipmap_flag=0;

	float		phd_leftfloat;  		// Left Clipping Value
	float		phd_rightfloat;         // Right Clipping Value
	float		phd_topfloat;           // Top Clipping Value
	float		phd_bottomfloat;        // Bottom Clipping Value

	char		*phd_winptr;        	/* Pointer to Window */
	sint32		phd_left;  				/* Left Clipping Value */
	sint32		phd_right;              /* Right Clipping Value */
	sint32		phd_top;                /* Top Clipping Value */
	sint32		phd_bottom;             /* Bottom Clipping Value */
	sint16		phd_winxmin;
	sint16		phd_winymin;
	sint16		phd_winxmax;        	/* Maximum Window X coord*/
	sint16		phd_winymax;        	/* Maximum Window Y coord*/
	sint32		phd_winwidth;       	/* Window Width*/
	sint32		phd_winheight;      	/* Window Height*/
	sint32		phd_centerx;        	/* Vanishing point X*/
	sint32		phd_centery;        	/* Vanishing point Y*/
	sint32		phd_znear;          	/* Distance to near clip plane in View.Frame*/
	sint32		phd_zfar;           	/* Distance to far clip plane in View.Frame*/
	sint32		phd_viewdist;       	/* Distance you can see in World.Frame*/
	sint32		phd_scrwidth;       	/* Width of Screen ie. 320 or 640*/
	sint32		phd_scrheight;       	/* Height of Screen ie. 200 or 480*/
	sint32		phd_persp;				/* perspective thang*/
	sint32		*phd_mxptr;				/* matrix pointer....*/
	sint32		phd_oopersp;


	float		f_znear;			// phd_znear
	float		f_zfar;				// phd_zfar
	float		f_oneoznear;		// one / phd_znear
	float		f_persp;			// phd_persp
	float		f_oneopersp;		// one / phs_persp
	float		f_perspoznear;		// phd_persp / phd_znear
	float		f_centerx;			// phd_centrex
	float		f_centery;			// phd_centrey
	float		f_invzfar;			// 1.0/phd_zfar (actually 65535/65536 at the moment)
	float		f_oneozfar;			// one/phd_zfar
	float		f_a,f_b,f_boo;		// a/b factors for z buffering (f_boo=f_b/one)

	sint32		w2v_matrix[12];				   		/* Copy Of W2V matrix...*/
	sint32		matrix_stack[MAX_MATRICES*12]; 		/* matrix stack..*/

	PHD_VECTOR	ls_vector_view;			   			// light vector in View Frame
	PHD_ANGLE	phd_ls_pitch,phd_ls_yaw;   			// Angles Of Any Light Source

	sint32		surfacenum;				   			// number of surfaces in output list
	sint16		*info3dptr;                			// current pointer to info section
	sint32		*sort3dptr;                			// current pointer to Sort section

	sint32		*sort3dptrfb;						// Front To Back Sort Ptr
	sint16		*info3dptrfb;					
	
	sint32		*sort3dptrbf;						// Back To Front Sort Ptr
	sint16		*info3dptrbf;
	
	sint32		surfacenumfb;
	sint32		surfacenumbf;

	sint32		sort3d_bufferbf[MAX_POLYGONS][10];

	sint16		info3d_bufferfb[MAX_POLYGONS*30];		
	sint16		info3d_bufferbf[MAX_POLYGONS*30];		



	char		*texture_page_ptrs[MAX_TEXTPAGES];  // Texture page pointers
	XBUF_PERSP 	xbuffer[MAX_SCANLINES];         	// Edge buffer for Polygon Draw
	PHD_VBUF	vbuf[MAX_VERTICES];					// Buffer for points
	sint32		sort3d_buffer[MAX_POLYGONS][2];		// buffer for sort info
	sint16		info3d_buffer[MAX_POLYGONS*30];		// buffer for print info
	PHDTEXTURESTRUCT phdtextinfo[MAX_TEXTURES]; 	// pointers to Object textures
	PHDSPRITESTRUCT  phdsprinfo[MAX_SPRITES];		// pointers to Scaley Sprites
	char		depthq_table[33][256];			 	// depth cueing tables..
	char		gouraud_table[256][32];          	// Gouraud shade table..

/*** pointers to polygon insertion routines ***/
sint16*	(*InsertObjectGT3)	(sint16* objptr,int number,enum sort_type sort_routine);
sint16*	(*InsertObjectGT4)	(sint16* objptr,int number,enum sort_type sort_routine);
sint16*	(*InsertObjectG3)	(sint16* objptr,int number,enum sort_type sort_routine);
sint16*	(*InsertObjectG4)	(sint16* objptr,int number,enum sort_type sort_routine);

sint16*	(*RoomInsertObjectGT3)	(sint16* objptr,int number,enum sort_type sort_routine);
sint16*	(*RoomInsertObjectGT4)	(sint16* objptr,int number,enum sort_type sort_routine);

void	(*InsertSprite)		(float fZDepth,int nX1,int nY1,int nX2,int nY2,int nSprite,int nShade,int nShade1,int drawtype,int offset);
void	(*InsertFlatRect)	(sint32 min_x, sint32 min_y, sint32 max_x, sint32 max_y,int nZDepth,int colour);
void	(*InsertLine)		(sint32 x1,sint32 y1,sint32 x2,sint32 y2,sint32 z,char color);
void	(*InsertTrans8)		(PHD_VBUF* vbuf,sint16 shade);
void	(*InsertTransQuad)	(sint32 sx,sint32 sy,sint32 w,sint32 h,sint32 z);

/*** pointers to internal renderer's poly draw routines ***/
void	(*poly_draw_routines[])(sint16*)=
	{
	draw_poly_gtmap,			 // Gouraud-Shaded Texture-mapped polygon
	draw_poly_wgtmap,			 // Gouraud-Shaded Texture-mapped Transparent polygon
	draw_poly_gtmap_persp, 		 // Perspective Gouraud-Shaded Texture-mapped polygon
	draw_poly_wgtmap_persp,		 // Perspective	Gouraud-Shaded Texture-mapped Transparent polygon
	draw_poly_line,				 // Line draw
    draw_poly_flat,         	 // flat-shaded polygon
	draw_poly_gouraud,      	 // gouraud-shaded polygon
	draw_poly_trans,             // Transparent Shadow polygon
	draw_scaled_spriteC,         // Scaled Sprite Draw
	};


double chop_temp;				// Temporary Variable For FTOL
bool bBlueEffect;				// Underwater Effect Flag

