Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Missing texture

Missing texture

Black Knight
Under a ShadowyTree · · 2 min read
1,840 2
I added something that I wanted to do for a long time to Dark Age.I store all my textures in a std::map with the file name as the key.And when models,terrain etc are loaded they ask the texture manager for a texture file and the texture manager returns a reference to the texture.Previously when a texture was missing form the game folder the game was displaying a pop up window telling the name of the texture file which was not found and then continuing as nothing has happened which was causing the game crash when the texture was being used.For example you could go in the textures folder and delete snow.png and the game would crash :)

Anways first I thought I could add a checked texture to the textures folder and load it when game starts and whenever a texture is not found I could return a reference to the checker texture,but then again someone might delete the checker texture too.So instead of putting the texture to the data folder I created it programatically and added it to the texture manager :

STE::TexturePtr newTexture = renderer->createTexture(64,64,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED);	unsigned char* data = new unsigned char[64*64*4];	for(unsigned int i=0; i<64; ++i)		for(unsigned int k=0; k<64; ++k)		{			int index = k*4+i*64*4;			unsigned char color = 0;			if ((i<32 && k<32) || (i>=32 &&k>=32))				color = 0;			else				color =255;			data[index] = data[index+1] = data[index+2] = color;			data[index+3] = 255;		}	renderer->fillTexture(data,newTexture,64,64,4);	delete[] data;	renderer->addTexture(newTexture,renderer->TEXTURES[TexID::MISSING]);


The usage is pretty simple,when someone request a texture from the renderer it calls, renderer->getTexture(TexID::GRASS) the renderer asks the texture manager and returns the texture if its loaded or the missing texture if it can't find the wanted texture.

While I was testing I first filled the texture with random stuff below are two screenshots showing the random image and then the checkers.I just deleted some textures randomly in the game folder and everything seems to be working fine.





Discussion

Loading comments...