/*
Tested with LINT
*/
#include <SGL2.H>
#include "init_gli.h"
#include "gli_st.h"
#include "GLI_Defn.h"
#include "light_st.h"
#include "PvObj_st.h"
#include "GLI_interface.h"

int Device = 0;
SGLCONTEXT SGLContext;
SGLCONTEXT2 SGLContext2;
int  stSpecialTexture;
sgl_intermediate_map SGL2_IM_sPecialtexture;

extern short TEXTURETWIDDLED[];

extern GLI_tdstInternalGlobalValuesFor3dEngine *GLI_BIG_GLOBALS;


#ifdef __cplusplus
extern "C" 
{
#endif
    
    // Global initialisation.
    void GLI_DRV_xInitDriver( HWND _hWnd, BOOL _bFullScreen, long _lWidth, long _lHeight, long _lBpp )
    {
        memset(&SGL2_IM_sPecialtexture , 0 , sizeof (sgl_intermediate_map));
        SGL2_IM_sPecialtexture . id[0]  = 'I';
        SGL2_IM_sPecialtexture . id[1]  = 'M';
        SGL2_IM_sPecialtexture . id[2]  = 'A';
        SGL2_IM_sPecialtexture . id[3]  = 'P';
        SGL2_IM_sPecialtexture . pixels = TEXTURETWIDDLED;
        SGL2_IM_sPecialtexture . y_dim = SGL2_IM_sPecialtexture . x_dim = 512;
        Device = sgl_create_screen_device (0, 640, 480, sgl_device_16bit, sgl_double_buffer);
        stSpecialTexture = 
            sgl_create_texture( sgl_map_rgb_565 , sgl_map_512x512 , FALSE , FALSE , &SGL2_IM_sPecialtexture , NULL);
    }
    
    // Temporary function.
    /*
    long GLI_INTERFACE_FUNC(GLI_DRV_lWhatIsGli)(void)
    {
        return GLI_C_VersionGlide;
    }
    */
    
    void GLI_DRV_vCloseDriver ()
    {
    }
    
    // Return version number.
    /*
    long GLI_INTERFACE_FUNC(GLI_lGetNumOfVersion)(void)
    {
        return 0;//g_stCurLLInterface.iMode;
    }
    */
    // Return a pointer on the text version of GLI engine.
    /*unsigned char *GLI_INTERFACE_FUNC(GLI_ucGetTextOfVersion)(void)
    {
        return NULL;//g_stCurLLInterface.ucTextMode;
    }
    */
    
    
    // Erase a rectangular region of Z buffer.
    void GLI_INTERFACE_FUNC(GLI_DRV_vClearZBufferRegion)(long lXStart,long lXEnd,long lYStart,long lYEnd)
    {
        if (!bDrawMirrorSymetric)
            GLI_BIG_GLOBALS->lDisplayMenuIsDetected = 1;
    }
    
    void GLI_INTERFACE_FUNC(GLI_vBeginDrawingTexturedMirrors)(void)
    {
        GLI_BIG_GLOBALS->bDrawMirrorSymetric = 1;
    }
    void GLI_INTERFACE_FUNC(GLI_vBeginDrawingTexturedMirrorsSurfaces)()
    {
        GLI_BIG_GLOBALS->lAMirrorIsDetected = 3;
    }
    void GLI_INTERFACE_FUNC(GLI_vEndDrawingTexturedMirrors)()
    {
        GLI_BIG_GLOBALS->lAMirrorIsDetected &= 1;
        GLI_BIG_GLOBALS->bDrawMirrorSymetric = 0;
    }
    
    //extern long GLI_xIsGliInit();
    void GLI_INTERFACE_FUNC(GLI_DRV_vFlipDevice)(long lNbFrames)
    {
        if (!GLI_MDRV_xIsGliInit()) 
            return;

        GLI_BIG_GLOBALS->lDisplayMenuIsDetected = 0;
        GLI_BIG_GLOBALS->lAMirrorIsDetected = 0;
        sgltri_render   (&SGLContext);
        sgltri_startofframe (&SGLContext);
    }
    void GLI_INTERFACE_FUNC(GLI_DRV_vClearDevice)(BOOL ZBuffer, BOOL ColorBuffer, unsigned long Color)
    {
    }
    
#ifdef __cplusplus
} //extern "C"
#endif
