void ResourceManagerClass::LoadTextures()
{
	for (std::vector< TexturePair >::iterator it = textures.begin(); it != textures.end(); ++it)
	{
		CIwTexture* texture = new CIwTexture;
		texture->LoadFromFile(it->first.c_str());
		texture->Upload();
		it->second = new Texture;
		it->second->SetData((void*)texture);
	}
}
CIwTexture* Transitions2D::CaptureScreen()
{
	int w = IwGxGetDeviceWidth();
	int h = IwGxGetDeviceHeight();
	int length = w * h * 4;

	uint8* buffer = new uint8[length];

	glReadPixels(0, 0, w, h, 0x1908, 0x1401, buffer);

	uint8* buffer2 = new uint8[length];

	int lineSize = w * 4;
	uint8* b1 = buffer;
	uint8* b2 = buffer2 + h * lineSize;;
	for(int y = h; y > 0; y--)
	{
		b2 -= lineSize;
		for(int x = w; x > 0; x--)
		{
			*b2++ = *b1++;
			*b2++ = *b1++;
			*b2++ = *b1++;
			*b2++ = *b1++;
		}
		b2 -= lineSize;
	}

	CIwTexture* texture = new CIwTexture;
	CIwImage& img = texture->GetImage();

	img.SetFormat(CIwImage::ABGR_8888);
	img.SetWidth(w);
	img.SetHeight(h);
	img.SetBuffers(buffer2, length);
	//img.SaveBmp("screenshot.bmp");

	texture->SetMipMapping(false);
	texture->Upload();

	delete buffer;
	delete buffer2;

	return texture;
}
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;
}
void CzPlatformImaging::UploadTexture(CzTexture texture)
{
	CIwTexture* t = static_cast<CIwTexture*>(texture);
	t->Upload();
}