示例#1
0
HelpState::HelpState(GameEngine *engine) : GameState(engine)
{
	b1xMin = b1xMax = b1yMin = b1yMax = 0;

	data[0] = ReadTGA("./assets/menu/retour.tga");
	data[1] = ReadTGA("./assets/menu/helpBackground.tga");
}
示例#2
0
ErrorCode Image::ReadTGA(const char *pchFileName)
{
	File file;
	if( !file.Open(pchFileName) )
		return "Failed to open the file!";
	return ReadTGA(file);
}
示例#3
0
CBitmap* CBackgroundManager::LoadCustomBackground (void)
{
if (m_background [0]|| (gameStates.app.bNostalgia || !MODERN_STYLE))
	return m_background [0];

CBitmap* bmP;

gameOpts->menus.altBg.bHave = 0;
if (!(bmP = CBitmap::Create (0, 0, 0, 1)))
	return NULL;
if (!ReadTGA (gameOpts->menus.altBg.szName, 
#ifdef __linux__
				  gameFolders.szCacheDir,
#else
				  NULL, 
#endif
				  bmP, 
				 (gameOpts->menus.altBg.alpha < 0) ? -1 : (int) (gameOpts->menus.altBg.alpha * 255), 
				 gameOpts->menus.altBg.brightness, gameOpts->menus.altBg.grayscale, 0)) {
	delete bmP;
	gameOpts->menus.altBg.bHave = -1;
	return NULL;
	}
gameOpts->menus.altBg.bHave = 1;
return bmP;
}
示例#4
0
文件: hoard.c 项目: paud/d2x-xl
int InitMonsterball (int nBitmap)
{
	grsBitmap			*bmP, *altBmP;
	tVideoClip					*vcP;
	powerupType_info	*ptP;
	int					i;

memcpy (&gameData.hoard.monsterball, &gameData.hoard.orb, sizeof (tHoardItem));
gameData.hoard.monsterball.nClip = gameData.eff.nClips [0]++;
memcpy (&gameData.eff.vClips [0][gameData.hoard.monsterball.nClip], 
		  &gameData.eff.vClips [0][gameData.hoard.orb.nClip],
		  sizeof (tVideoClip));
if (!ReadTGA ("monsterball.tga", gameFolders.szTextureDir [0], &gameData.hoard.monsterball.bm, -1, 1.0, 0, 0)) {
	altBmP = (grsBitmap *) d_malloc (sizeof (grsBitmap));
	if (altBmP && 
		(ReadTGA ("mballgold#0.tga", gameFolders.szTextureDir [0], &gameData.hoard.monsterball.bm, -1, 1.0, 0, 0) ||
		 ReadTGA ("mballred#0.tga", gameFolders.szTextureDir [0], &gameData.hoard.monsterball.bm, -1, 1.0, 0, 0))) {
		vcP = &gameData.eff.vClips [0][gameData.hoard.monsterball.nClip];
		for (i = 0; i < gameData.hoard.orb.nFrames; i++, nBitmap++) {
			Assert (nBitmap < MAX_BITMAP_FILES);
			vcP->frames [i].index = nBitmap;
			InitHoardBitmap (&gameData.pig.tex.bitmaps [0][nBitmap], 
									gameData.hoard.monsterball.nWidth, 
									gameData.hoard.monsterball.nHeight, 
									BM_FLAG_TRANSPARENT, 
									NULL);
			}
		vcP->flags |= WCF_ALTFMT;
		bmP = gameData.pig.tex.bitmaps [0] + vcP->frames [0].index;
		BM_OVERRIDE (bmP) = altBmP;
		*altBmP = gameData.hoard.monsterball.bm;
		altBmP->bmType = BM_TYPE_ALT;
		altBmP->bm_data.alt.bm_frameCount = altBmP->bm_props.h / altBmP->bm_props.w;
		}
	}
//Create monsterball powerup
ptP = gameData.objs.pwrUp.info + POW_MONSTERBALL;
ptP->nClipIndex = gameData.hoard.monsterball.nClip;
ptP->hitSound = -1; //gameData.objs.pwrUp.info [POW_SHIELD_BOOST].hitSound;
ptP->size = (gameData.objs.pwrUp.info [POW_SHIELD_BOOST].size * extraGameInfo [1].monsterball.nSizeMod) / 2;
ptP->light = gameData.objs.pwrUp.info [POW_SHIELD_BOOST].light;
return nBitmap;
}
示例#5
0
文件: hudicons.cpp 项目: paud/d2x-xl
int LoadObjTallyIcons (void)
{
	int	i;

if (bHaveObjTallyBms > -1)
	return bHaveObjTallyBms;
memset (bmObjTally, 0, sizeof (bmObjTally));
for (i = 0; i < 2; i++)
	if (!ReadTGA (pszObjTallyIcons [i], gameFolders.szDataDir, bmObjTally + i, -1, 1.0, 0, 0)) {
		while (i)
			GrFreeBitmapData (bmObjTally + --i);
		return bHaveObjTallyBms = 0;
		}
return bHaveObjTallyBms = 1;
}
示例#6
0
LDraw::Bitmap* BitmapLoader::Load(IO::ISequentialByteStream* stream)
{
	int n;
	for (n = 0; n < 5; n++)
	{
		int ret = -1;

		switch (n)
		{
		case 0:
			{
				ret = ReadJPEG(this, stream);
			}
			break;

		case 1:
			{
				ret = ReadGIF(this, stream);
			}
			break;

		case 2:
			{
				ret = ReadPNG(this, stream);
			}
			break;

		case 3:
			{
				ret = ReadBMP(this, stream);
			}
			break;

		case 4:
			{
				ret = ReadTGA(this, stream);
			}
			break;
		}

		if (ret == 0)
			break;

		stream->Seek(0, System::IO::STREAM_SEEK_SET);
	}

	return m_bitmap;
}
//*************************************************************************************
//	
//*************************************************************************************
CTexture *	CTextureManager::Create( const CString & filename, bool warn )
{
	CTexture *		p_texture( NULL );
	CFile * const	p_file( CFileSystem::Open( filename, "rb" ) );

	if ( p_file != NULL )
	{
		const CString	extension( p_file->GetExtension() );

		if ( extension == "png" || extension == "PNG" )
		{
			p_texture = ReadPNG( p_file );
		}
		else if ( extension == "tga" || extension == "TGA" )
		{
			p_texture = ReadTGA( p_file );
		}
		else if ( extension == "jpg" || extension == "JPG" )
		{
			p_texture = ReadJPG( p_file );
		}
		else if ( extension == "bmp" || extension == "BMP" )
		{
			p_texture = ReadBMP( p_file );
		}
		else
		{
			TRACE( "Unrecognised image extension %s\n", extension.GetPtr() );
			ASSERT( 0, "" );
		}

		CFileSystem::Close( p_file );
	}

	if ( p_texture == NULL )
	{
		if ( warn == true )
		{
			TRACE( "Failed to load image %s\n", filename.GetPtr() );
			ASSERT( 0, "" );
		}
	}

	return p_texture;
}
示例#8
0
int PageInBitmap (CBitmap *bmP, const char *bmName, int nIndex, int bD1, bool bHires)
{
	CBitmap			*altBmP = NULL;
	int				nFile, nSize, nOffset, nFrames, nShrinkFactor, nBestShrinkFactor,
						bRedone = 0, bTGA;
	sbyte				nFlags;
	bool				bDefault = false;
	CFile				cf, *cfP = &cf;
	char				fn [6][FILENAME_LEN];

#if DBG
if (!bmName)
	return 0;
if ((nDbgTexture > 0) && (nIndex == nDbgTexture))
	nDbgTexture = nDbgTexture;
#endif
if (bmP->Buffer ())
	return 1;

StopTime ();
nShrinkFactor = 8 >> min (gameOpts->render.textures.nQuality, gameStates.render.nMaxTextureQuality);
if (nShrinkFactor < 4) {
	if (nShrinkFactor == 1)
		nShrinkFactor = 2;	// cap texture quality at 256x256 (x frame#)
	else if (IsPowerup (bmName) || IsWeapon (bmName))	// force downscaling of powerup hires textures
		nShrinkFactor <<= 1;
	}
nSize = (int) bmP->FrameSize ();
if (nIndex >= 0)
	GetFlagData (bmName, nIndex);
#if DBG
if (strstr (bmName, "metl139"))
	bmName = bmName;
#endif
if (gameStates.app.bNostalgia)
	gameOpts->render.textures.bUseHires [0] = 0;

bTGA = 0;
nFlags = (nIndex < 0) ? 0 : gameData.pig.tex.bitmapFlags [bD1][nIndex];
if (bmP->Texture ())
	bmP->Texture ()->Release ();
bmP->SetBPP (1);

if ((*bmName && /*!gameStates.app.bDemoData &&*/ ((nIndex < 0) || IsCockpit (bmName) || bHires || gameOpts->render.textures.bUseHires [0])) &&
	 !(gameOpts->render.powerups.b3D && IsWeapon (bmName) && !gameStates.app.bHaveMod)) {
#if 0
	if ((nIndex >= 0) && ReadS3TC (gameData.pig.tex.altBitmaps [bD1] + nIndex, gameFolders.szTextureCacheDir [bD1], bmName)) {
		altBmP = gameData.pig.tex.altBitmaps [bD1] + nIndex;
		altBmP->nType = BM_TYPE_ALT;
		bmP->SetOverride (altBmP);
		BM_FRAMECOUNT (altBmP) = 1;
		nFlags &= ~BM_FLAG_RLE;
		nFlags |= BM_FLAG_TGA;
		bmP = altBmP;
		altBmP = NULL;
		}
	else
#endif
	if (*gameFolders.szTextureDir [2]) {
		char szLevelFolder [FILENAME_LEN];
		if (gameData.missions.nCurrentLevel < 0)
			sprintf (szLevelFolder, "slevel%02d", -gameData.missions.nCurrentLevel);
		else
			sprintf (szLevelFolder, "level%02d", gameData.missions.nCurrentLevel);
		sprintf (gameFolders.szTextureDir [3], "%s/%s", gameFolders.szTextureDir [2], szLevelFolder);
		sprintf (gameFolders.szTextureCacheDir [3], "%s/%s", gameFolders.szTextureCacheDir [2], szLevelFolder);
		}
	else
		*gameFolders.szTextureDir [3] =
		*gameFolders.szTextureCacheDir [3] = '\0';
	MakeBitmapFilenames (bmName, gameFolders.szTextureDir [3], gameFolders.szTextureCacheDir [3], fn [1], fn [0], nShrinkFactor);
	MakeBitmapFilenames (bmName, gameFolders.szTextureDir [2], gameFolders.szTextureCacheDir [2], fn [3], fn [2], nShrinkFactor);
	MakeBitmapFilenames (bmName, gameFolders.szTextureDir [bD1], gameFolders.szTextureCacheDir [bD1], fn [5], fn [4], nShrinkFactor);

	if (0 <= (nFile = OpenBitmapFile (fn, cfP))) {
		cfP->Close ();
		PrintLog ("loading hires texture '%s' (quality: %d)\n", fn [nFile], min (gameOpts->render.textures.nQuality, gameStates.render.nMaxTextureQuality));
		if (nFile < 2)	//was level specific mod folder
			MakeTexSubFolders (gameFolders.szTextureCacheDir [3]);
		if (nIndex < 0)
			altBmP = &gameData.pig.tex.addonBitmaps [-nIndex - 1];
		else
			altBmP = &gameData.pig.tex.altBitmaps [bD1][nIndex];
		if (!ReadTGA (fn [nFile], "", altBmP)) {
			altBmP = NULL;
			if (!bDefault)
				cfP->Close ();
			throw (EX_OUT_OF_MEMORY);
			}
		else {
			bTGA = 1;
			if (strstr (fn [nFile], "omegblob#") && strstr (fn [nFile], "/mods/"))
				gameStates.render.bOmegaModded = 1;
			altBmP->SetType (BM_TYPE_ALT);
			bmP->SetOverride (altBmP);
			bmP = altBmP;
			bmP->DelFlags (BM_FLAG_RLE);
			nSize = bmP->Size ();
			nFrames = (bmP->Height () % bmP->Width ()) ? 1 : bmP->Height () / bmP->Width ();
			bmP->SetFrameCount (ubyte (nFrames));
			nOffset = -1;
			if (nIndex >= 0) {
				nFlags = bmP->Flags ();
				if (bmP->Height () > bmP->Width ()) {
					tEffectClip	*ecP = NULL;
					tWallClip *wcP;
					tVideoClip *vcP;
					while ((ecP = FindEffect (ecP, nIndex))) {
						//e->vc.nFrameCount = nFrames;
						ecP->flags |= EF_ALTFMT;
						//ecP->vClipInfo.flags |= WCF_ALTFMT;
						}
					if (!ecP) {
						if ((wcP = FindWallAnim (nIndex))) {
						//w->nFrameCount = nFrames;
							wcP->flags |= WCF_ALTFMT;
							}
						else if ((vcP = FindVClip (nIndex))) {
							//v->nFrameCount = nFrames;
							vcP->flags |= WCF_ALTFMT;
							}
						else {
							PrintLog ("   couldn't find animation for '%s'\n", bmName);
							}
						}
					}
				}
			}
		}
	}

if (!altBmP) {
	if (nIndex < 0) {
		StartTime (0);
		return 0;
		}
	cfP = cfPiggy + bD1;
	if (!cfP->File ())
		PiggyInitPigFile (NULL);
	nOffset = bitmapOffsets [bD1][nIndex];
	bDefault = true;
	}

bRedone = 1;
if ((nOffset >= 0) && cfP->Seek (nOffset, SEEK_SET)) {
	if (!bDefault)
		cfP->Close ();
	throw (EX_IO_ERROR);
	}
#if 1//DBG
bmP->SetName (bmName);
#endif
#if TEXTURE_COMPRESSION
if (bmP->Compressed ())
	UseBitmapCache (bmP, bmP->CompressedSize ());
else
#endif
	{
	if (bTGA || bmP->CreateBuffer ())
		UseBitmapCache (bmP, nSize);
	}
if (!bmP->Buffer () || (bitmapCacheUsed > bitmapCacheSize)) {
	if (!bDefault)
		cfP->Close ();
	throw (EX_OUT_OF_MEMORY);
	}
if (!bTGA && (nIndex >= 0))
	bmP->SetFlags (nFlags);
bmP->SetId (nIndex);
#if DBG
if (nIndex == nDbgTexture)
	nDbgTexture = nDbgTexture;
#endif
int i = ReadBitmap (bmP, nSize, cfP, bDefault, bD1 != 0, bHires);
if (i) {
	if (i < 0) {
		if (!bDefault)
			cfP->Close ();
		throw (EX_IO_ERROR);
		}
	}
else
#if TEXTURE_COMPRESSION
if (!bmP->Compressed ())
#endif
	{
	bmP->SetType (BM_TYPE_ALT);
	bmP->SetTranspType (-1);
	if (IsOpaqueDoor (nIndex)) {
		bmP->DelFlags (BM_FLAG_TRANSPARENT);
		bmP->TransparentFrames () [0] &= ~1;
		}
#if TEXTURE_COMPRESSION
	if (CompressTGA (bmP))
		bmP->SaveS3TC (gameFolders.szTextureCacheDir [(nFile < 2) ? 3 : (nFile < 4) ? 2 : bD1], bmName);
	else {
#endif
		nBestShrinkFactor = BestShrinkFactor (bmP, nShrinkFactor);
		if ((nBestShrinkFactor > 1) && ShrinkTGA (bmP, nBestShrinkFactor, nBestShrinkFactor, 1)) {
			nSize /= (nBestShrinkFactor * nBestShrinkFactor);
			if (gameStates.app.bCacheTextures) {
				tTgaHeader	h;

				memset (&h, 0, sizeof (h));
				h.bits = bmP->BPP () * 8;
				h.width = bmP->Width ();
				h.height = bmP->Height ();
				h.imageType = 2;
				// nFile < 2: mod level texture folder
				// nFile < 4: mod texture folder
				// otherwise standard D1 or D2 texture folder
				SaveTGA (bmName, gameFolders.szTextureCacheDir [(nFile < 2) ? 3 : (nFile < 4) ? 2 : bD1], &h, bmP);
				}
			}
		}
#if TEXTURE_COMPRESSION
	}
#endif

#if DBG
nPrevIndex = nIndex;
strcpy (szPrevBm, bmName);
#endif
tRgbColorf color;
if (0 <= (bmP->AvgColor (&color)))
	bmP->SetAvgColorIndex (ubyte (bmP->Palette ()->ClosestColor (&color)));
StartTime (0);
if (!bDefault)
	cfP->Close ();
return 1;
}
示例#9
0
//*********************************************************************************
// Parse materials library file
//
static void ParseMaterialLibrary(SCENE *pS, const char *sSceneFile, const char *sMatLib, BOOL bParseOnly)
{
	FILE *pMat;
	char pcLine[512], pcPath[MAX_PATH], *pcPtr;
	const char *pcArgs;
	TAG_NAME Tag;

	if (!sMatLib)
		return;

	//--- Extract base path

	strcpy_s(pcPath, sSceneFile);
	pcPtr = pcPath + strlen(pcPath)-1;
	while ((pcPtr > pcPath) && (*(pcPtr-1) != '\\') && (*(pcPtr-1) != '/') && (*(pcPtr-1) != ':'))
		--pcPtr;

	*pcPtr = 0;
	strcat_s(pcPath, sMatLib);

	pcPtr = pcPath;
	while (*pcPtr)
	{
		if (*pcPtr == '/')
			*pcPtr = '\\';
		
		pcPtr++;
	}

	//--- Open scene file

	fopen_s(&pMat, pcPath, "r");
	if (!pMat)
		return;

	//--- Parse scene file, first pass

	while (fgets(pcLine, sizeof(pcLine), pMat))
	{
		//--- Parse file line

		pcArgs = TokenizeFileLine(pcLine, &Tag);

		//--- Process file line

		switch (Tag)
		{
		case TAGNAME_MATERIAL:
			//--- Retrieve new material name

			if (!bParseOnly)
			{
				ExtractParameters(Tag, pcArgs, pS->pMaterials[pS->u32MaterialsCount].pcName);

				pS->pMaterials[pS->u32MaterialsCount].pfAmbient[0] = pS->pMaterials[pS->u32MaterialsCount].pfAmbient[1] = pS->pMaterials[pS->u32MaterialsCount].pfAmbient[2] = pS->pMaterials[pS->u32MaterialsCount].pfAmbient[3] = 0;
				pS->pMaterials[pS->u32MaterialsCount].pfDiffuse[0] = pS->pMaterials[pS->u32MaterialsCount].pfDiffuse[1] = pS->pMaterials[pS->u32MaterialsCount].pfDiffuse[2] = 0;
				pS->pMaterials[pS->u32MaterialsCount].pfDiffuse[3] = 1;
				pS->pMaterials[pS->u32MaterialsCount].pfSpecular[0] = pS->pMaterials[pS->u32MaterialsCount].pfSpecular[1] = pS->pMaterials[pS->u32MaterialsCount].pfSpecular[2] = pS->pMaterials[pS->u32MaterialsCount].pfSpecular[3] = 0;
				pS->pMaterials[pS->u32MaterialsCount].pfEmission[0] = pS->pMaterials[pS->u32MaterialsCount].pfEmission[1] = pS->pMaterials[pS->u32MaterialsCount].pfEmission[2] = pS->pMaterials[pS->u32MaterialsCount].pfEmission[3] = 0;
				pS->pMaterials[pS->u32MaterialsCount].fShininess = 128;
				pS->pMaterials[pS->u32MaterialsCount].pcTextureFile[0] = 0;
				pS->pMaterials[pS->u32MaterialsCount].pDiffuse = NULL;
				pS->pMaterials[pS->u32MaterialsCount].u32RenderFlags = 0;
			}

			pS->u32MaterialsCount++;
			break;

		case TAGNAME_OPACITY:
			//--- Retrieve opacity properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, &pS->pMaterials[pS->u32MaterialsCount-1].pfDiffuse[3]);
			break;

		case TAGNAME_SHININESS:
			//--- Retrieve shininess properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, &pS->pMaterials[pS->u32MaterialsCount-1].fShininess);
			if (pS->pMaterials[pS->u32MaterialsCount-1].fShininess < 1)
				pS->pMaterials[pS->u32MaterialsCount-1].fShininess = 1;
			else if (pS->pMaterials[pS->u32MaterialsCount-1].fShininess > 128)
				pS->pMaterials[pS->u32MaterialsCount-1].fShininess = 128;
			break;

		case TAGNAME_ILLUMINATION:
			//--- Retrieve lighting properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, &pS->pMaterials[pS->u32MaterialsCount-1].u32RenderFlags);
			break;

		case TAGNAME_AMBIENT:
			//--- Retrieve ambient properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, pS->pMaterials[pS->u32MaterialsCount-1].pfAmbient);
			break;

		case TAGNAME_DIFFUSE:
			//--- Retrieve diffuse properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, pS->pMaterials[pS->u32MaterialsCount-1].pfDiffuse);
			break;

		case TAGNAME_SPECULAR:
			//--- Retrieve specular properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, pS->pMaterials[pS->u32MaterialsCount-1].pfSpecular);
			break;

		case TAGNAME_EMISSION:
			//--- Retrieve emission properties

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, pS->pMaterials[pS->u32MaterialsCount-1].pfEmission);
			break;

		case TAGNAME_TEXTURE:
			//--- Retrieve texture filename

			if (bParseOnly)
				break;

			ExtractParameters(Tag, pcArgs, pS->pMaterials[pS->u32MaterialsCount-1].pcTextureFile);

			//--- Extract base path

			strcpy_s(pcPath, sSceneFile);
			pcPtr = pcPath + strlen(pcPath)-1;
			while ((pcPtr > pcPath) && (*(pcPtr-1) != '\\') && (*(pcPtr-1) != '/') && (*(pcPtr-1) != ':'))
				--pcPtr;

			*pcPtr = 0;
			strcat_s(pcPath, pS->pMaterials[pS->u32MaterialsCount-1].pcTextureFile);

			pcPtr = pcPath;
			while (*pcPtr)
			{
				if (*pcPtr == '/')
					*pcPtr = '\\';
				
				pcPtr++;
			}

			//--- Load texture file

			pS->pMaterials[pS->u32MaterialsCount-1].pDiffuse = ReadTGA(pcPath);
			break;
		}
	}

	//-- Close library file

	fclose(pMat);
}