/****************************************************************************\
*                                                                            *
*  R3D.H - Source Code Header Module                                         *
*                                                                            *
*  (c)Copyright 2001 Indotek, LLC. All Rights Reserved.                      *
*                                                                            *
\****************************************************************************/

#ifndef _R3D_H
#define _R3D_H

#define WIN32_LEAN_AND_MEAN
#ifndef __WINDOWS_H
#include <windows.h>
#endif
#define D3D_OVERLOADS
#include <ddraw.h>
#include <d3d.h>

#define R3D_READ        2
#define R3D_WRITE       4
#define R3D_CREATE      8
#define R3D_TRUNCATE    16
#define R3D_APPEND      32
#define R3D_BEGINNING   2
#define R3D_END         4
#define R3D_CURRENT     8

#define R3D_STDCALL __stdcall

#ifdef __cplusplus
extern "C" {
#endif

extern BOOL R3D_STDCALL r3d_2DBegin(unsigned char **, int *, int *);
extern BOOL R3D_STDCALL r3d_2DBlit(int, int, int, int, int, int, int, int, int, BOOL);
extern BOOL R3D_STDCALL r3d_2DEnd(void);
extern BOOL R3D_STDCALL r3d_2DFadeIn(int, int, int, int, int, int, int, int, int, int);
#define _r3d_Unsupported_MakeColor0(r,g,b) (unsigned short) (((r)>>3)<<11)|(((g)>>2)<<5)|(((b)>>3))
#define _r3d_Unsupported_MakeColor1(r,g,b) (unsigned short) (((r)>>3)<<10)|(((g)>>3)<<5)|(((b)>>3))
#define _r3d_Unsupported_MakeColor2(r,g,b) ((((unsigned long)(r))<<16)|(((unsigned long)(g))<<8)|(unsigned long)(b))
#define _r3d_Unsupported_MakeColor3(r,g,b) ((((unsigned long)(b))<<16)|(((unsigned long)(g))<<8)|(unsigned long)(r))
#define _r3d_Unsupported_MakeColor4(r,g,b) ((((unsigned long)(r))<<16)|(((unsigned long)(g))<<8)|(unsigned long)(b))
#define _r3d_Unsupported_MakeColor5(r,g,b) ((((unsigned long)(b))<<16)|(((unsigned long)(g))<<8)|(unsigned long)(r))
#define _r3d_Unsupported_SetPixelRGB0(pMem,Pitch,x,y,r,g,b) (*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))) = _r3d_Unsupported_MakeColor0(r,g,b))
#define _r3d_Unsupported_SetPixelRGB1(pMem,Pitch,x,y,r,g,b) (*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))) = _r3d_Unsupported_MakeColor1(r,g,b))
#define _r3d_Unsupported_SetPixelRGB2(pMem,Pitch,x,y,r,g,b) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3))) = _r3d_Unsupported_MakeColor2(r,g,b))
#define _r3d_Unsupported_SetPixelRGB3(pMem,Pitch,x,y,r,g,b) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3))) = _r3d_Unsupported_MakeColor3(r,g,b))
#define _r3d_Unsupported_SetPixelRGB4(pMem,Pitch,x,y,r,g,b) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))) = _r3d_Unsupported_MakeColor4(r,g,b))
#define _r3d_Unsupported_SetPixelRGB5(pMem,Pitch,x,y,r,g,b) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))) = _r3d_Unsupported_MakeColor5(r,g,b))
#define _r3d_Unsupported_SetPixelColor0(pMem,Pitch,x,y,MakeColor0) (*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))) = (MakeColor0))
#define _r3d_Unsupported_SetPixelColor1(pMem,Pitch,x,y,MakeColor1) (*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))) = (MakeColor1))
#define _r3d_Unsupported_SetPixelColor2(pMem,Pitch,x,y,MakeColor2) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3))) = (MakeColor2))
#define _r3d_Unsupported_SetPixelColor3(pMem,Pitch,x,y,MakeColor3) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3))) = (MakeColor3))
#define _r3d_Unsupported_SetPixelColor4(pMem,Pitch,x,y,MakeColor4) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))) = (MakeColor4))
#define _r3d_Unsupported_SetPixelColor5(pMem,Pitch,x,y,MakeColor5) (*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))) = (MakeColor5))
#define _r3d_Unsupported_SetPixelR2Safe(pMem,Pitch,x,y,r) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+2)) = (r))
#define _r3d_Unsupported_SetPixelG2Safe(pMem,Pitch,x,y,g) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+1)) = (g))
#define _r3d_Unsupported_SetPixelB2Safe(pMem,Pitch,x,y,b) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3))) = (b))
#define _r3d_Unsupported_SetPixelR3Safe(pMem,Pitch,x,y,r) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3))) = (r))
#define _r3d_Unsupported_SetPixelG3Safe(pMem,Pitch,x,y,g) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+1)) = (g))
#define _r3d_Unsupported_SetPixelB3Safe(pMem,Pitch,x,y,b) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+2)) = (b))
#define _r3d_Unsupported_GetPixelRed0(pMem,Pitch,x,y) (unsigned char)(((*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))))&0xF800)>>8)
#define _r3d_Unsupported_GetPixelRed1(pMem,Pitch,x,y) (unsigned char)(((*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))))&0x7C00)>>7)
#define _r3d_Unsupported_GetPixelRed2(pMem,Pitch,x,y) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+2)))
#define _r3d_Unsupported_GetPixelRed3(pMem,Pitch,x,y) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+0)))
#define _r3d_Unsupported_GetPixelRed4(pMem,Pitch,x,y) (unsigned char)(((*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))))&0x00FF0000)>>16)
#define _r3d_Unsupported_GetPixelRed5(pMem,Pitch,x,y) (unsigned char)((*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))))&0x000000FF)
#define _r3d_Unsupported_GetPixelGreen0(pMem,Pitch,x,y) (unsigned char)(((*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))))&0x07E0)>>3)
#define _r3d_Unsupported_GetPixelGreen1(pMem,Pitch,x,y) (unsigned char)(((*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))))&0x03E0)>>2)
#define _r3d_Unsupported_GetPixelGreen2(pMem,Pitch,x,y) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+1)))
#define _r3d_Unsupported_GetPixelGreen3(pMem,Pitch,x,y) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+1)))
#define _r3d_Unsupported_GetPixelGreen4(pMem,Pitch,x,y) (unsigned char)(((*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))))&0x0000FF00)>>8)
#define _r3d_Unsupported_GetPixelGreen5(pMem,Pitch,x,y) (unsigned char)(((*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))))&0x0000FF00)>>8)
#define _r3d_Unsupported_GetPixelBlue0(pMem,Pitch,x,y) (unsigned char)(((*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))))&0x001F)<<3)
#define _r3d_Unsupported_GetPixelBlue1(pMem,Pitch,x,y) (unsigned char)(((*((unsigned short *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<1))))&0x001F)<<3)
#define _r3d_Unsupported_GetPixelBlue2(pMem,Pitch,x,y) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+0)))
#define _r3d_Unsupported_GetPixelBlue3(pMem,Pitch,x,y) (*(((unsigned char *)(pMem)+((Pitch)*(y))+((x)*3)+2)))
#define _r3d_Unsupported_GetPixelBlue4(pMem,Pitch,x,y) (unsigned char)((*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))))&0x000000FF)
#define _r3d_Unsupported_GetPixelBlue5(pMem,Pitch,x,y) (unsigned char)(((*((unsigned long *)((unsigned char *)(pMem)+((Pitch)*(y))+((x)<<2))))&0x00FF0000)>>16)
extern int _r3d_2DClipMinX, _r3d_2DClipMinY, _r3d_2DClipMaxX, _r3d_2DClipMaxY;
extern unsigned char R3D_STDCALL r3d_2DGetPixelBlue(int, int);
#define r3d_2DGetPixelBlueMacro(result,pMem,Pitch,PixelFormat,x,y) if ((int)(x)>=_r3d_2DClipMinX && (int)(x)<=_r3d_2DClipMaxX && (int)(y)>=_r3d_2DClipMinY && (int)(y)<=_r3d_2DClipMaxY) \
    { \
    switch (PixelFormat) \
    { \
    case 0: \
        result=_r3d_Unsupported_GetPixelBlue0(pMem,Pitch,x,y); \
        break; \
    case 1: \
        result=_r3d_Unsupported_GetPixelBlue1(pMem,Pitch,x,y); \
        break; \
    case 2: \
        result=_r3d_Unsupported_GetPixelBlue2(pMem,Pitch,x,y); \
        break; \
    case 3: \
        result=_r3d_Unsupported_GetPixelBlue3(pMem,Pitch,x,y); \
        break; \
    case 4: \
        result=_r3d_Unsupported_GetPixelBlue4(pMem,Pitch,x,y); \
        break; \
    case 5: \
        result=_r3d_Unsupported_GetPixelBlue5(pMem,Pitch,x,y); \
        break; \
    default: \
        break; \
    } \
    }
extern unsigned char R3D_STDCALL r3d_2DGetPixelGreen(int, int);
#define r3d_2DGetPixelGreenMacro(result,pMem,Pitch,PixelFormat,x,y) if ((int)(x)>=_r3d_2DClipMinX && (int)(x)<=_r3d_2DClipMaxX && (int)(y)>=_r3d_2DClipMinY && (int)(y)<=_r3d_2DClipMaxY) \
    { \
    switch (PixelFormat) \
    { \
    case 0: \
        result=_r3d_Unsupported_GetPixelGreen0(pMem,Pitch,x,y); \
        break; \
    case 1: \
        result=_r3d_Unsupported_GetPixelGreen1(pMem,Pitch,x,y); \
        break; \
    case 2: \
        result=_r3d_Unsupported_GetPixelGreen2(pMem,Pitch,x,y); \
        break; \
    case 3: \
        result=_r3d_Unsupported_GetPixelGreen3(pMem,Pitch,x,y); \
        break; \
    case 4: \
        result=_r3d_Unsupported_GetPixelGreen4(pMem,Pitch,x,y); \
        break; \
    case 5: \
        result=_r3d_Unsupported_GetPixelGreen5(pMem,Pitch,x,y); \
        break; \
    default: \
        break; \
    } \
    }
extern unsigned char R3D_STDCALL r3d_2DGetPixelRed(int, int);
#define r3d_2DGetPixelRedMacro(result,pMem,Pitch,PixelFormat,x,y) if ((int)(x)>=_r3d_2DClipMinX && (int)(x)<=_r3d_2DClipMaxX && (int)(y)>=_r3d_2DClipMinY && (int)(y)<=_r3d_2DClipMaxY) \
    { \
    switch (PixelFormat) \
    { \
    case 0: \
        result=_r3d_Unsupported_GetPixelRed0(pMem,Pitch,x,y); \
        break; \
    case 1: \
        result=_r3d_Unsupported_GetPixelRed1(pMem,Pitch,x,y); \
        break; \
    case 2: \
        result=_r3d_Unsupported_GetPixelRed2(pMem,Pitch,x,y); \
        break; \
    case 3: \
        result=_r3d_Unsupported_GetPixelRed3(pMem,Pitch,x,y); \
        break; \
    case 4: \
        result=_r3d_Unsupported_GetPixelRed4(pMem,Pitch,x,y); \
        break; \
    case 5: \
        result=_r3d_Unsupported_GetPixelRed5(pMem,Pitch,x,y); \
        break; \
    default: \
        break; \
    } \
    }
extern BOOL R3D_STDCALL r3d_2DLine(int, int, int, int, unsigned char, unsigned char, unsigned char);
extern BOOL R3D_STDCALL r3d_2DLineMask(int, int, int, int, unsigned char, unsigned char, unsigned char, int *, int);
extern BOOL R3D_STDCALL r3d_2DSetPixel(int, int, unsigned char, unsigned char, unsigned char, unsigned char);
#define r3d_2DSetPixelMacro(pMem,Pitch,PixelFormat,x,y,r,g,b) if ((int)(x)>=_r3d_2DClipMinX && (int)(x)<=_r3d_2DClipMaxX && (int)(y)>=_r3d_2DClipMinY && (int)(y)<=_r3d_2DClipMaxY) \
    { \
    switch (PixelFormat) \
    { \
    case 0: \
        _r3d_Unsupported_SetPixelRGB0(pMem,Pitch,x,y,r,g,b); \
        break; \
    case 1: \
        _r3d_Unsupported_SetPixelRGB1(pMem,Pitch,x,y,r,g,b); \
        break; \
    case 2: \
        _r3d_Unsupported_SetPixelR2Safe(pMem,Pitch,x,y,r); \
        _r3d_Unsupported_SetPixelG2Safe(pMem,Pitch,x,y,g); \
        _r3d_Unsupported_SetPixelB2Safe(pMem,Pitch,x,y,b); \
        break; \
    case 3: \
        _r3d_Unsupported_SetPixelR3Safe(pMem,Pitch,x,y,r); \
        _r3d_Unsupported_SetPixelG3Safe(pMem,Pitch,x,y,g); \
        _r3d_Unsupported_SetPixelB3Safe(pMem,Pitch,x,y,b); \
        break; \
    case 4: \
        _r3d_Unsupported_SetPixelRGB4(pMem,Pitch,x,y,r,g,b); \
        break; \
    case 5: \
        _r3d_Unsupported_SetPixelRGB5(pMem,Pitch,x,y,r,g,b); \
        break; \
    default: \
        break; \
    } \
    }
extern BOOL R3D_STDCALL r3d_3DVertexToScreenVertex(float, float, float, float *, int *, int *, BOOL *);
extern void R3D_STDCALL r3d_AlphaPolygonSort(int **, D3DVERTEX **, int **);
extern BOOL R3D_STDCALL r3d_Attach3DModels(long, long, float *);
extern void R3D_STDCALL r3d_ConcatenateMatrices(float *, float *, float *);
extern BOOL R3D_STDCALL r3d_DDSurfaceBlit(LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4, int, int, int, int, int, int, int, int, int, int, int, int, BOOL, BOOL);
extern BOOL R3D_STDCALL r3d_DDSurfaceCreateFromSurface(int *, int, int);
extern BOOL R3D_STDCALL r3d_DDSurfaceDestroy(int);
extern BOOL R3D_STDCALL r3d_DDSurfaceDestroyAll(void);
extern LPDIRECTDRAWSURFACE4 R3D_STDCALL r3d_DDSurfaceGet(int);
extern int R3D_STDCALL r3d_DDSurfaceGetHeight(int);
extern int R3D_STDCALL r3d_DDSurfaceGetWidth(int);
extern BOOL R3D_STDCALL r3d_Detach3DModels(long, long, float *);
extern BOOL R3D_STDCALL r3d_EnableFog(BOOL);
extern BOOL R3D_STDCALL r3d_EnableSpecular(BOOL);
extern BOOL R3D_STDCALL r3d_Enumerate(char[32][40], char[32][32][40], char[32][32][32][40]);
extern BOOL R3D_STDCALL r3d_EnumerateSpecific(char[32][40], char[32][32][40], char[32][32][32][40], BOOL, BOOL, BOOL, BOOL);
extern BOOL R3D_STDCALL r3d_FileClose(HANDLE);
extern HANDLE R3D_STDCALL r3d_FileOpen(char *, int);
extern BOOL R3D_STDCALL r3d_FileRead(HANDLE, void *, unsigned long);
extern BOOL R3D_STDCALL r3d_FileSeek(HANDLE, long, int);
extern unsigned long R3D_STDCALL r3d_FileSize(HANDLE);
extern BOOL R3D_STDCALL r3d_FileWrite(HANDLE, void *, unsigned long);
extern void R3D_STDCALL r3d_Finished(void);
extern void R3D_STDCALL r3d_ForceAlphaRendering(BOOL);
extern BOOL R3D_STDCALL r3d_Get3DModelMaterialCount(int, int *);
extern BOOL R3D_STDCALL r3d_Get3DModelMaterialGeometry(int, int, BOOL **, unsigned long **, D3DVERTEX **, unsigned long **, unsigned short **);
extern BOOL R3D_STDCALL r3d_Get3DModelMaterialHandle(int, int, int *);
extern LPDIRECTDRAWSURFACE4 R3D_STDCALL r3d_GetBackBufferSurface(void);
extern BOOL R3D_STDCALL r3d_GetBoundingBoxCoords(long, float *, float *, float *, float *, float *, float *, float *);
extern BOOL R3D_STDCALL r3d_GetBoundingSphereRadius(long, float *);
extern unsigned long R3D_STDCALL r3d_GetCurrentTick(void);
extern LPDIRECT3DDEVICE3 R3D_STDCALL r3d_GetDevice(void);
extern LPD3DDEVICEDESC R3D_STDCALL r3d_GetDeviceDesc(void);
extern LPDIRECT3D3 R3D_STDCALL r3d_GetDirect3D(void);
extern LPDIRECTDRAW4 R3D_STDCALL r3d_GetDirectDraw(void);
extern void R3D_STDCALL r3d_GetDisplayMode(int *, int *, unsigned long *, unsigned long *, unsigned long *, unsigned long *, int *);
extern LPDIRECTDRAWSURFACE4 R3D_STDCALL r3d_GetFrontBufferSurface(void);
extern char *R3D_STDCALL r3d_GetLastErrorString(void);
extern LPDIRECT3DLIGHT R3D_STDCALL r3d_GetLight(void);
extern int R3D_STDCALL r3d_GetMaxTextureWidthHeight(void);
extern int R3D_STDCALL r3d_GetMinTextureWidthHeight(void);
extern BOOL R3D_STDCALL r3d_GetSelectionInfo(int, int, int, int *, int *, unsigned long *, BOOL *);
extern void R3D_STDCALL r3d_GetVersion(int *, int *, int *);
extern LPDIRECT3DVIEWPORT3 R3D_STDCALL r3d_GetViewport(void);
extern LPDIRECTDRAWSURFACE4 R3D_STDCALL r3d_GetZBufferSurface(void);
extern BOOL R3D_STDCALL r3d_Initialize(void *, float, float, int, int, int);
extern BOOL R3D_STDCALL r3d_LightRemoveDefault(void);
extern BOOL R3D_STDCALL r3d_LightSetAmbient(float r, float g, float b);
extern BOOL R3D_STDCALL r3d_ListAdd3DModel(char *, BOOL);
extern BOOL R3D_STDCALL r3d_ListAddMaterial(float, float, float, float, float, float, float, float, float, float, float, BOOL, char *, BOOL, char *, BOOL);
extern BOOL R3D_STDCALL r3d_ListLoad(long *, long *);
extern BOOL R3D_STDCALL r3d_ListUnload(void);
extern void R3D_STDCALL r3d_MakeIdentityMatrix(float *);
extern int R3D_STDCALL r3d_MessageBox(LPCTSTR, LPCTSTR, UINT);
extern BOOL R3D_STDCALL r3d_PageFlip(BOOL, BOOL);
extern BOOL R3D_STDCALL r3d_PreLight3DModel(long);
extern BOOL R3D_STDCALL r3d_Render3DModel(long, float *);
extern BOOL R3D_STDCALL r3d_RenderBegin(float *);
extern BOOL R3D_STDCALL r3d_RenderEnd(long *);
extern BOOL R3D_STDCALL r3d_RestoreSurfaces(void);
extern BOOL R3D_STDCALL r3d_RotateMatrixByQuaternion(float *, float, float, float, float);
extern void R3D_STDCALL r3d_Set2DClipRegion(int, int, int, int);
extern BOOL R3D_STDCALL r3d_SetBackgroundColor(float, float, float);
extern BOOL R3D_STDCALL r3d_SetCurrentTick(unsigned long);
extern BOOL R3D_STDCALL r3d_SetFilteringAndMipMapOptions(int);
extern BOOL R3D_STDCALL r3d_SetFogAttributes(float, float, float, float, float);
extern BOOL R3D_STDCALL r3d_SetLightLocationColor(float, float, float, float, float, float);
extern BOOL R3D_STDCALL r3d_SetMaterial(int);
extern BOOL R3D_STDCALL r3d_SetMatrix(float *);
extern BOOL R3D_STDCALL r3d_SetRenderArea(BOOL, BOOL, int, int, int, int);
extern BOOL R3D_STDCALL r3d_SetViewMatrix(float *);
extern BOOL R3D_STDCALL r3d_SurfaceBlit(int, int, int, int, int, int, int, int, int, int, BOOL);
#define r3d_SurfaceColorGetA(dwColor) (unsigned char)(((dwColor)>>24)&0x000000FF)
#define r3d_SurfaceColorGetB(dwColor) (unsigned char)(((dwColor)>>16)&0x000000FF)
#define r3d_SurfaceColorGetG(dwColor) (unsigned char)(((dwColor)>>8)&0x000000FF)
#define r3d_SurfaceColorGetR(dwColor) (unsigned char)((dwColor)&0x000000FF)
#define r3d_SurfaceColorMakeRGBA(r,g,b,a) ((((unsigned long)(a))<<24)|(((unsigned long)(b))<<16)|(((unsigned long)(g))<<8)|(unsigned long)(r))
extern BOOL R3D_STDCALL r3d_SurfaceCreate(int *, int, int);
extern BOOL R3D_STDCALL r3d_SurfaceCreateFromBackBuffer(int *);
extern BOOL R3D_STDCALL r3d_SurfaceCreateFromBMP(int *, char *);
extern BOOL R3D_STDCALL r3d_SurfaceDestroy(int);
extern BOOL R3D_STDCALL r3d_SurfaceDestroyAll(void);
extern BOOL R3D_STDCALL r3d_SurfaceExportToBMP(int, char *);
extern unsigned long *R3D_STDCALL r3d_SurfaceGet(int);
extern int R3D_STDCALL r3d_SurfaceGetHeight(int);
extern int R3D_STDCALL r3d_SurfaceGetWidth(int);
extern BOOL R3D_STDCALL r3d_SurfaceSetAlphaFromBMP(int, char *);
extern BOOL R3D_STDCALL r3d_SurfaceSetColorKey(int, unsigned char, unsigned char, unsigned char);
extern BOOL R3D_STDCALL r3d_SurfaceStretchSmooth(int, int);
extern BOOL R3D_STDCALL r3d_TextureAnimateScroll(int, int, float, float);
extern BOOL R3D_STDCALL r3d_TextureAnimateSurfaceBlit(int, int, int, unsigned char *, int, int, int, int, int, int, int, int, int);
extern BOOL R3D_STDCALL r3d_TextureAnimateSurfaceLock(int, int *, int *, unsigned char **, int *);
#define r3d_TextureAnimateSurfaceTexel0(pSurf,Pitch,u,v,a,r,g,b) ( *( (unsigned short *)( pSurf + (Pitch*(v))) + ((u)) ) = ((unsigned short)(((r)>>3)<<11)|(((g)>>2)<<5)|(((b)>>3))) )
#define r3d_TextureAnimateSurfaceTexel1(pSurf,Pitch,u,v,a,r,g,b) ( *( (unsigned short *)( pSurf + (Pitch*(v))) + ((u)) ) = ((unsigned short)(((a)>>7)<<15)|(((r)>>3)<<10)|(((g)>>3)<<5)|(((b)>>3))) )
#define r3d_TextureAnimateSurfaceTexel2(pSurf,Pitch,u,v,a,r,g,b) ( *( (unsigned short *)( pSurf + (Pitch*(v))) + ((u)) ) = ((unsigned short)(((a)>>4)<<12)|(((r)>>4)<<8)|(((g)>>4)<<4)|(((b)>>4))) )
#define r3d_TextureAnimateSurfaceTexel3(pSurf,Pitch,u,v,a,r,g,b) ( *( (unsigned long *)( pSurf + (Pitch*(v))) + ((u)) ) = ((unsigned long)((a)<<24)|((r)<<16)|((g)<<8)|(b)) )
#define r3d_TextureAnimateSurfaceTexel4(pSurf,Pitch,u,v,a,r,g,b) ( *( (unsigned short *)( pSurf + (Pitch*(v))) + ((u)) ) = ((unsigned short)(((b)>>3)<<11)|(((g)>>2)<<5)|(((r)>>3))) )
#define r3d_TextureAnimateSurfaceTexel5(pSurf,Pitch,u,v,a,r,g,b) ( *( (unsigned short *)( pSurf + (Pitch*(v))) + ((u)) ) = ((unsigned short)(0x8000)|(((r)>>3)<<10)|(((g)>>3)<<5)|(((b)>>3))) )
extern BOOL R3D_STDCALL r3d_TextureAnimateSurfaceUnlock(int);
extern BOOL R3D_STDCALL r3d_TextureAnimateSwap(int, int, int);
extern BOOL R3D_STDCALL r3d_ViewportClear(BOOL, BOOL);
extern void R3D_STDCALL r3d_WindowInit(RECT, RECT);
extern void R3D_STDCALL r3d_WindowMove(short, short);
extern int R3D_STDCALL r3d_WindowSize(RECT, RECT);
extern BOOL R3D_STDCALL r3d_ZBlit3DModel1(long, float *);
extern BOOL R3D_STDCALL r3d_ZBlit3DModel2(long, float *);

#ifdef __cplusplus
}
#endif
#endif