Example #1
0
CIwMaterial* ResourceManager::load(const char* name, int* w, int* h) {
	int width = 0, height = 0;
	char res[MAX_RES_NAME] = {0};
	sprintf(res, "images/%s/%s", desktop.getDevPath(), name);
	IIter p = imgs->find(res);
	if (p != imgs->end()) {
		if (w != NULL) {
			*w = p->second.width;
		}
		if (h != NULL) {
			*h = p->second.height;
		}
		return p->second.mat;
	}
	CIwTexture* texture = new CIwTexture;
    CIwImage image;
    s3eFile* pFile = s3eFileOpen(res, "rb");
    if (pFile) {
        image.ReadFile(pFile);
		width = image.GetWidth();
		height = image.GetHeight();
        s3eFileClose(pFile);
        texture->CopyFromImage(&image);
        texture->Upload();
    } else {
		delete texture;
		texture = NULL;
	}
	CIwMaterial* mat = new CIwMaterial;
	mat->SetTexture(texture);
	SImg s;
	s.texture = texture;
	s.mat = mat;
	s.width = width;
	s.height = height;
	imgs->insert(IPair(string(res), s));
	if (w != NULL) {
		*w = width;
	}
	if (h != NULL) {
		*h = height;
	}
	return mat;
}
CzTexture CzPlatformImaging::CreateTexture(void* memory_file, int memory_file_size)
{
	CzFile file;
	if (file.Open(memory_file, memory_file_size))
	{
		// Load the image
		CIwImage* image = new CIwImage();
		image->ReadFile((s3eFile*)file.getFileHandle());

		CIwTexture* texture = new CIwTexture();
		texture->_SetFlags( CIwTexture::NO_CHROMA_KEY_F );
		texture->CopyFromImage(image);

		delete image;

		return (CzTexture)texture;
	}

	return NULL;
}
CzTexture CzPlatformImaging::CreateTexture(CzTexture source, CzImage::eFormat format)
{
	CIwImage::Format f = toMarmImageFormat(format);
	if (f == CIwImage::FORMAT_UNDEFINED)
		return NULL;
	CIwTexture* t = static_cast<CIwTexture*>(source);

	CIwImage* image = new CIwImage();
	image->SetFormat(f);
	image->SetWidth(t->GetWidth());
	image->SetHeight(t->GetHeight());
	t->GetImage().ConvertToImage(image);

	CIwTexture* texture = new CIwTexture();
	texture->_SetFlags( CIwTexture::NO_CHROMA_KEY_F );
	texture->SetMipMapping(t->GetMipMapping());
	texture->SetFiltering(t->GetFiltering());
	texture->SetModifiable(t->GetModifiable());
	texture->CopyFromImage(image);

	delete image;

	return (CzTexture)texture;
}