/* ======================================================================================= Name : GLIText.c Author : vincent lhullier Date :12/10/98 Description : function to display text on screen ======================================================================================= ======================================================================================= !!!! Warning : In retail version this file is empty !!!! ======================================================================================= ======================================================================================= */ #ifndef RETAIL /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include #include #include "DllInter.h" #include "FIL.h" #include "TEX.h" #include "..\..\gld\devvpt.h" #include "mater_st.h" /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* ======================================================================================= Structures ======================================================================================= */ typedef struct tdstLetterPosition_ { short wX; short wY; } tdstLetterPosition; /* ======================================================================================= Globals ======================================================================================= */ unsigned char *GLI_g_pvPoliceBitmap = NULL; long GLI_g_lPolicePitch = 0; //ACP_tdxHandleOfMaterial gh_PoliceMaterial; GLI_tdstMaterial GLITEXT_st_PoliceMaterial; ACP_tdxHandleOfTexture GLITEXT_gh_PoliceTexture = NULL; long GLITEXT_l_ProportionalMode = 1; long GLITEXT_l_AlreadyInit = 0; tdstLetterPosition GLI_ga_stLetterPos[ 128 ] = { { -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1}, { -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1}, { -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1}, { -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1}, { 320, 14},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ 176, 47},{ -1, -1},{ -1, -1}, { 288, 47},{ 304, 47},{ 96, 47},{ 112, 47},{ 48, 47},{ 128, 47},{ 32, 47},{ 80, 47}, { 0, 14},{ 16, 14},{ 32, 14},{ 48, 14},{ 64, 14},{ 80, 14},{ 96, 14},{ 112, 14}, { 128, 14},{ 144, 14},{ 144, 47},{ 64, 47},{ 240, 47},{ -1, -1},{ 256, 47},{ -1, -1}, { -1, -1},{ 2, 0},{ 18, 0},{ 34, 0},{ 50, 0},{ 66, 0},{ 82, 0},{ 98, 0}, { 114, 0},{ 130, 0},{ 146, 0},{ 162, 0},{ 178, 0},{ 194, 0},{ 210, 0},{ 226, 0}, { 242, 0},{ 258, 0},{ 274, 0},{ 290, 0},{ 306, 0},{ 322, 0},{ 338, 0},{ 354, 0}, { 370, 0},{ 386, 0},{ 402, 0},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ 320, 47}, { -1, -1},{ 0, 31},{ 16, 31},{ 32, 31},{ 48, 31},{ 64, 31},{ 80, 31},{ 96, 31}, { 112, 31},{ 128, 31},{ 144, 31},{ 160, 31},{ 176, 31},{ 192, 31},{ 208, 31},{ 224, 31}, { 240, 31},{ 256, 31},{ 272, 31},{ 288, 31},{ 304, 31},{ 320, 31},{ 336, 31},{ 352, 31}, { 368, 31},{ 384, 31},{ 400, 31},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1},{ -1, -1} }; /* ======================================================================================= Function ======================================================================================= */ /* ---------------------------------------------------------------------------------------- Description : Load Police bitmap ---------------------------------------------------------------------------------------- */ void GLI_fn_vLoadPolice( void ) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ struct FIL_tdstGF_ stHeader; unsigned char *p_ucTgaBitmap; unsigned short *p_uwPoliceBitmap, *p_uwLast; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* * load TGA file */ FIL_fn_vTGALoadFromFileWithInvertPicture( "", "polices.tga", &stHeader ); if (stHeader.stFileHeader.ucBpp == 0) return; /* * convert data */ MMG_fn_vAddMemoryInfo(MMG_C_lTypeGLI , MMG_C_lSubTypePolice , NULL); GEO_M_CPAMalloc(GLI_g_pvPoliceBitmap,unsigned char *,stHeader.stFileHeader.ulWidth * stHeader.stFileHeader.ulHeight * 2, E_uwGEONotEnoughtMemory ); p_ucTgaBitmap = stHeader.p_ucBitMap; p_uwPoliceBitmap = (unsigned short *) GLI_g_pvPoliceBitmap; p_uwLast = p_uwPoliceBitmap + stHeader.stFileHeader.ulWidth * stHeader.stFileHeader.ulHeight; GLI_g_lPolicePitch = stHeader.stFileHeader.ulWidth * 2; for ( ; p_uwPoliceBitmap < p_uwLast ; p_uwPoliceBitmap++, p_ucTgaBitmap += 3) { *(p_uwPoliceBitmap) = (((unsigned short)(*(p_ucTgaBitmap) & 0xF8) )<<8 ) + (((unsigned short)(*(p_ucTgaBitmap + 1) & 0xF8) )<<3 ) + (((unsigned short)(*(p_ucTgaBitmap + 2) & 0xF8) )>>3); } FIL_fn_vTGAFree( &stHeader.p_ucBitMap ); } /* ---------------------------------------------------------------------------------------- Description : init text data ---------------------------------------------------------------------------------------- */ void GLITEXT_fnv_Init( void ) { if (GLITEXT_l_AlreadyInit) return; GLITEXT_l_AlreadyInit = 1; if (GLI_g_pvPoliceBitmap == NULL) GLI_fn_vLoadPolice(); /* GLI_xLoadTexture( &GLITEXT_gh_PoliceTexture, NULL, "polices.tga", 0, 0); if ( GLITEXT_gh_PoliceTexture ) TEX_vSetTextureQualityLevel(GLITEXT_gh_PoliceTexture, (char)TEX_C_QHIGH); else */ GLITEXT_l_ProportionalMode = 0; //GLI_xSetMaterialTexture( &GLITEXT_st_PoliceMaterial, GLITEXT_gh_PoliceTexture); } /* ---------------------------------------------------------------------------------------- Description : init text data ---------------------------------------------------------------------------------------- */ void GLITEXT_fnv_Close( void ) { GLITEXT_l_AlreadyInit = 0; GLITEXT_gh_PoliceTexture = NULL; } /* ---------------------------------------------------------------------------------------- Description : write letter bitmap into backbuffer ---------------------------------------------------------------------------------------- */ void GLI_fn_vWriteLetterInBackBuffer(long X, long Y, long l, long h, unsigned char *p_ucSrc, long SrcPitch , void *_p_cBackBuffer, long _lPitch ) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ long *p_sourceptr , *p_sourceptrLast , *p_destptr ,lYCounterLocal; short *p_Src; unsigned long *p_ulDest; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ //chbani platange si on depasse la taille du viewport if( (Y+h)>480 ) Y =480-h-1; if( (X+l)>640 ) X =640-l-1; p_Src = (unsigned short *)p_ucSrc; _lPitch = _lPitch/4; p_ulDest = (unsigned long *) _p_cBackBuffer; for (lYCounterLocal = 0; lYCounterLocal < h ; lYCounterLocal++) { p_destptr = (p_ulDest) + (X>>1) + _lPitch * (Y + lYCounterLocal); p_sourceptr = ((unsigned long *)p_Src + lYCounterLocal * (SrcPitch >>2)) ; p_sourceptrLast = p_sourceptr + (l>>1); for (;p_sourceptr < p_sourceptrLast ;p_sourceptr ++,p_destptr ++) *p_destptr = *p_sourceptr ; } } /* ---------------------------------------------------------------------------------------- Description : display a string in screen ---------------------------------------------------------------------------------------- */ void GLI_fn_vDisplayPolices(unsigned char *d_ucFileName, long lX, long lY, void *_p_cBuffer, long _lPitch ) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ long lPosInTexture; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ if (GLI_g_pvPoliceBitmap == NULL) return; while ((*d_ucFileName) != 0) { if ( (*d_ucFileName < 128) && (GLI_ga_stLetterPos[*d_ucFileName].wY != -1) ) { lPosInTexture = ((long) GLI_ga_stLetterPos[*d_ucFileName].wY) * GLI_g_lPolicePitch + ((long) GLI_ga_stLetterPos[*d_ucFileName].wX); GLI_fn_vWriteLetterInBackBuffer( lX, lY, 8, 16, GLI_g_pvPoliceBitmap + lPosInTexture, GLI_g_lPolicePitch, _p_cBuffer, _lPitch); } d_ucFileName++; lX+=8; } } /* ---------------------------------------------------------------------------------------- Description : new function to display a string in screen ---------------------------------------------------------------------------------------- */ extern GLD_tdpstDevice g_pstGLDDevices[ C_NB_MAX_DEVICES ]; extern void GLI_vDraw2DSpriteWithUV( GLD_tdstViewportAttributes *p_stVpt, MTH_tdxReal xXMin, MTH_tdxReal xXMax, MTH_tdxReal xYMin, MTH_tdxReal xYMax, MTH_tdxReal xUMin, MTH_tdxReal xUMax, MTH_tdxReal xVMin, MTH_tdxReal xVMax, ACP_tdxHandleOfMaterial hMaterial ); void GLITEXT_DisplayString( unsigned char *_sz_String, long lX, long lY ) { float x, dx, y1, y2; float u, v; GLD_tdstViewportAttributes *pst_VptAttrib; pst_VptAttrib = &g_pstGLDDevices[ 0 ]->pstViewports[ 0 ]->stViewAttrib; if (pst_VptAttrib == NULL) return; y1 = ( (float) lY / 480.0f) * pst_VptAttrib->dwHeight; y2 = y1 + ( (16.0f / 480.0f) * pst_VptAttrib->dwHeight ); x = ( (float) lX / 640.0f) * pst_VptAttrib->dwWidth; dx = (8.0f / 640.0f) * pst_VptAttrib->dwWidth; while ( ( *_sz_String ) != 0) { if ( (*_sz_String < 128) && (GLI_ga_stLetterPos[*_sz_String].wY != -1) ) { u = ((float) (GLI_ga_stLetterPos[*_sz_String].wX >> 1) + 1.0f) / 256.0f; v = 1.0f - (((float) (GLI_ga_stLetterPos[*_sz_String].wY ) +1.0f) / 64.0f); GLI_vDraw2DSpriteWithUV( pst_VptAttrib, x, x + dx, y1, y2, u, u + 0.03125f, v, v - 0.25f, &GLITEXT_st_PoliceMaterial ); } _sz_String++; x += dx; } } /* ---------------------------------------------------------------------------------------- Description : Main function -> lock device, display police in virtual screen and unlock buffer ---------------------------------------------------------------------------------------- */ void GLI_vDisplayPolices(unsigned char *d_ucFileName, long lX, long lY) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ long lPitch; void *p_cBackBuffer; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ if (GLITEXT_l_ProportionalMode) { if (GLITEXT_gh_PoliceTexture) GLITEXT_DisplayString( d_ucFileName, lX, lY ); } else { if ( GLI_DRV_bLockDevice( &p_cBackBuffer, &lPitch ) ) { GLI_fn_vDisplayPolices( d_ucFileName, lX, lY, p_cBackBuffer, lPitch ); GLI_DRV_bUnlockDevice(); } } } /* ---------------------------------------------------------------------------------------- Description : access function to display mode var ---------------------------------------------------------------------------------------- */ void GLITEXT_fnv_SetProportionalMode( long _l_Mode ) { GLITEXT_l_ProportionalMode = _l_Mode; } long GLITEXT_fnl_GetProportionalMode( void ) { return (GLITEXT_l_ProportionalMode); } #endif