Example #1
0
	bool Texture2DLoader::loadDefault(IResource * outResource)
	{
		Texture2D * texPtr = (Texture2D*)outResource;
		assert(texPtr != nullptr);

		Texture2DDescriptor* desc = (Texture2DDescriptor*)texPtr->getDescriptor();
		desc->isMipmapped = false;
		desc->wrapMode = TextureWrapMode::WM_REPEAT;
		desc->magFilterMode = TextureFilterMode::FM_NEAREST;
		desc->minFilterMode = TextureFilterMode::FM_MIPMAP_NEAREST;

		CIwImage image;
		image.SetFormat(CIwImage::Format::RGB_888);

		image.SetWidth(defaultTexture.width);
		image.SetHeight(defaultTexture.height);

		image.SetBuffers((uint8*)defaultTexture.pixel_data,
			defaultTexture.bytes_per_pixel * 
			defaultTexture.width * 
			defaultTexture.height);


		return texPtr->uploadToGPU(image);
	}
Example #2
0
void MapBackground::CreateMapTileImage(MapTile* pMapTile, void* gResult, uint32 gResultLen, bool isJpg)
{
	if (!IsTileVisible(pMapTile))
	{
		return;
	}
	CIwImage image;
	if (!isJpg)
	{
		//pMapTile->pTexture = g_pNotFoundTexture;
		s3eFile* tempfile = s3eFileOpenFromMemory((void*)gResult, gResultLen);
		image.ReadFile(tempfile);

		//image.LoadFromFile("tiles/r0302322130033033130.png");

		if (image.GetWidth())
		{
			pMapTile->pTexture = new CIwTexture;
			pMapTile->pTexture->CopyFromImage(&image);
			pMapTile->pTexture->Upload();
		}

		s3eFileClose(tempfile);
	}
	else
	{
		JPEGImage(gResult, gResultLen, image);
		pMapTile->pTexture = new CIwTexture;
		pMapTile->pTexture->CopyFromImage(&image);
		pMapTile->pTexture->Upload();
	}
}
void PatteRunGameEngine::Init(void* pGameStateVoid)
{
	IGameHandler* pGameState = (IGameHandler*)pGameStateVoid;
	/*
	g_pBall = new CBall(pGameState);
	g_pUserPaddle = new CGPSPaddle(pGameState);
	//g_pUserPaddle = new CCompPaddle(this, g_pBall, false);
	g_pCompPaddle = new CCompPaddle(pGameState, g_pBall, true);

	g_pBall->PushPaddle(g_pUserPaddle);
	g_pBall->PushPaddle(g_pCompPaddle);
	*/
	g_pUser = new CGPSUser(pGameState);
	g_pGameHandler = pGameState;
	g_pFontHuge = (CIwGxFont*)IwGetResManager()->GetResNamed("font_huge", "CIwGxFont");
	g_pFont = (CIwGxFont*)IwGetResManager()->GetResNamed("font_medium", "CIwGxFont");
	g_pFontSmall = (CIwGxFont*)IwGetResManager()->GetResNamed("font_small", "CIwGxFont");
	
	CIwImage imgTile;
	imgTile.LoadFromFile("images/patterun/tile.png");

	g_pTile = new CIwTexture();
	g_pTile->CopyFromImage(&imgTile);
	g_pTile->Upload();
}
Example #4
0
	bool Texture2DLoader::loadFromFile(IResource * outResource, const std::string & fileName)
	{
		Texture2D * texPtr = (Texture2D*)outResource;
		assert(texPtr != nullptr);

		CIwImage image;
		image.LoadFromFile(fileName.c_str());

		return texPtr->uploadToGPU(image);
	}
Example #5
0
CIwImage* CIwGameImage::ConvertToFormat(CIwImage& source, CIwImage::Format format)
{
	CIwImage* img = new CIwImage();
	img->SetFormat(format);
	img->SetWidth(source.GetWidth());
	img->SetHeight(source.GetHeight());
	//img->SetPitch(source.GetPitch());
	source.ConvertToImage(img);

	return img;
}
Example #6
0
	bool Texture2DLoader::loadFromMemory(IResource * outResource, uint64 size, const void* data)
	{
		Texture2D * texPtr = (Texture2D*)outResource;
		assert(texPtr != nullptr);

		CIwImage image;
		s3eFile * f = s3eFileOpenFromMemory((void*)data, (size_t)size);
		image.ReadFile(f);
		s3eFileClose(f);

		return texPtr->uploadToGPU(image);
	}
Example #7
0
/**
* Constructor
* @param pPos the position of the door
* @param pFrames number of frames in the animation
* @param pImageName the image to use for the animation
* @param pScale the render scale
*/
Effect::Effect(CIwSVec2 pPos, int pFrames, const char* pImageName, float pScale):
	mPos(pPos),
	mFrameCount(pFrames),
	mCurFrame(0),
	mFrameDelay(0),
	mMaxFrameDelay(3),
	mFinished(false),
	mScale(pScale) {

		CIwImage img;
		img.LoadFromFile(pImageName);
		mImage = Iw2DCreateImage(img);
}
Example #8
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;
}
bool CCImage::_initWithPngData(void * pData, int nDatalen)
{
	IW_CALLSTACK("CCImage::_initWithPngData");
	
    bool bRet = false;
	
	s3eFile* pFile = s3eFileOpenFromMemory(pData, nDatalen);
	
	IwAssert(GAME, pFile);
	
	CIwImage    *image		= NULL;
	image = new CIwImage;
	
	image->ReadFile( pFile);
	
    s3eFileClose(pFile);
	
	// init image info
	m_bPreMulti	= true;
	m_bHasAlpha = image->HasAlpha();
	
	unsigned int bytesPerComponent = 3;
	if (m_bHasAlpha)
	{
		bytesPerComponent = 4;
	} 
	m_nHeight = (unsigned int)image->GetHeight();
	m_nWidth = (unsigned int)image->GetWidth();
	m_nBitsPerComponent = (unsigned int)image->GetBitDepth()/bytesPerComponent;
	
	tImageSource imageSource;
	
	imageSource.data    = (unsigned char*)pData;
	imageSource.size    = nDatalen;
	imageSource.offset  = 0;
	
	m_pData = new unsigned char[m_nHeight * m_nWidth * bytesPerComponent];
	
	unsigned int bytesPerRow = m_nWidth * bytesPerComponent;

	if(m_bHasAlpha)
	{
		unsigned char *src = NULL;
		src = (unsigned char *)image->GetTexels();
		
		unsigned char *tmp = (unsigned char *) m_pData;
		
		for(unsigned int i = 0; i < m_nHeight*bytesPerRow; i += bytesPerComponent)
		{
			*(tmp + i + 0)	=  (*(src + i + 0) * *(src + i + 3) + 1) >> 8;
			*(tmp + i + 1)	=  (*(src + i + 1) * *(src + i + 3) + 1) >> 8;					
			*(tmp + i + 2)	=  (*(src + i + 2) * *(src + i + 3) + 1) >> 8;
			*(tmp + i + 3)	=   *(src + i + 3);
		}
		
	}
	else
	{
		for (int j = 0; j < (m_nHeight); ++j)
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;
}
Example #11
0
void MapBackground::CreateMapTileImage2(MapTile* pMapTile, char* szPath, bool isJpg)
{
	if (!IsTileVisible(pMapTile))
	{
		return;
	}
	CIwImage image;
	if (!isJpg)
	{
		image.LoadFromFile(szPath);
		if (image.GetWidth())
		{
			pMapTile->pTexture = new CIwTexture;
			pMapTile->pTexture->CopyFromImage(&image);
			pMapTile->pTexture->Upload();
		}
	}
	else
	{
		s3eFile* pFile = s3eFileOpen(szPath, "r");

		if (pFile)
		{
			uint32 gResultLen = s3eFileGetSize(pFile);
			void* gResult = (void*)s3eMalloc(gResultLen + 1);

			uint32 test = s3eFileRead(gResult, sizeof(char), gResultLen, pFile);
			gResultLen = test;
			s3eFileClose(pFile);

			JPEGImage(gResult, gResultLen, image);
			pMapTile->pTexture = new CIwTexture;
			pMapTile->pTexture->CopyFromImage(&image);
			pMapTile->pTexture->Upload();

			delete gResult;
		}
	}
}
Example #12
0
void MapBackground::Init()
{
	g_pThisAndTile = new ThisAndTile;
	((ThisAndTile*)g_pThisAndTile)->pThis = this;

	gError = S3E_RESULT_SUCCESS;
	gResult = NULL;
	gResultLen = 0;
	pImage = 0;
	g_cursorIter = 1;
	g_bInProgress = false;
	g_bInitialLoad = true;
	g_bIsAnimating = false;
	g_latPerPixel = 1;
	g_lonPerPixel = 1;
	g_iTileCacheCount = 0;

	gLocation.m_Latitude = 47.7710083;
	gLocation.m_Longitude = -122.1588533;

	g_bLocationChanged = true;

	g_viewMatrix.SetIdentity();
	g_viewMatrix.t.x = -0x200;

	g_bScaledMode = false;
	g_bShowCursor = true;

	gResult = NULL;

	CIwImage img;
	img.LoadFromFile("cursor.png");
	bool a = img.UsesAlpha();

	gCursor = Iw2DCreateImage(img);

	gScaler = new CoordinateScaler(Iw2DGetSurfaceWidth(), Iw2DGetSurfaceHeight(), NULL, 0, false);
	gScaledModeScaler = new CoordinateScaler(Iw2DGetSurfaceWidth(), Iw2DGetSurfaceHeight(), NULL, 0, true);
}
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;
}
Example #14
0
bool CIwGameImage::Init(void* memory_file, int memory_file_size)
{
	CIwGameFile file;
	if (file.Open(memory_file, memory_file_size))
	{
		// Load the image
		CIwImage image;
		image.ReadFile((s3eFile*)file.getFileHandle());

		// if required format is different then convert it
		if (FormatSet && image.GetFormat() != Format)
		{
			CIwImage* new_image = ConvertToFormat(image, Format);
			Image2D = Iw2DCreateImage(*new_image);
			delete new_image;
		}
		else
			Image2D = Iw2DCreateImage(image);

		if (FilterSet)
			setFilter(Filter);

		if (Image2D == NULL || image.GetFormat() == CIwImage::FORMAT_UNDEFINED)
		{
#if defined(_DEBUG)
			CIwGameError::LogError("Error: CIwGameImage::Init() - Could not create image!");
#endif	// _DEBUG
			return false;
		}
		else
		{
			Width = Image2D->GetWidth();
			Height = Image2D->GetHeight();
#if defined(_DEBUG)
			CIwGameError::LogError("Info: CIwGameImage::Init() - Size = ", CIwGameString(memory_file_size).c_str());
			CIwGameError::LogError("Info: CIwGameImage::Init() - Width = ", CIwGameString(Width).c_str());
			CIwGameError::LogError("Info: CIwGameImage::Init() - Height = ", CIwGameString(Height).c_str());
			CIwGameError::LogError("Info: CIwGameImage::Init() - Bit depth = ", CIwGameString(image.GetBitDepth()).c_str());
			CIwGameError::LogError("Info: CIwGameImage::Init() - Format = ", CIwGameString(image.GetFormat()).c_str());
#endif	// _DEBUG
		}
	}

	// Sanity check
	if (Width <= 0 || Height <= 0 || Width > 16384 || Height > 16384)
		return false;

	State = State_Loaded;

	return true;
}
Example #15
0
	void saveImage(const ImageData &im, const char *path, const char *format)
	{
#ifdef __S3E__
		CIwImage image;
		image.SetFormat(CIwImage::ABGR_8888);
		image.SetWidth(im.w);
		image.SetHeight(im.h);
		image.SetBuffers(im.data, im.h * im.pitch);

		if (!strcmp(format, "tga"))
			image.SaveTga(path);
		else
			if (!strcmp(format, "jpg"))
				image.SaveJpg(path);
			else
				if (!strcmp(format, "png"))
					image.SavePng(path);

#else
		assert(0);
#endif
	}