Exemple #1
0
bool CCGridBase::initWithSize(const ccGridSize& gridSize)
{
	CCDirector *pDirector = CCDirector::sharedDirector();
	CCSize s = pDirector->getWinSizeInPixels();

	unsigned int POTWide = (unsigned int) s.width;
	unsigned int POTHigh = (unsigned int) s.height;

	bool needPOT = !g_Render->isRenderTargetNPOTSupported();

	if (needPOT)
	{
		POTWide = PixelFormat::calcNextPot(POTWide);
		POTHigh = PixelFormat::calcNextPot(POTHigh);
	}

	// we only use rgba8888
	CCTexture2DPixelFormat format = kCCTexture2DPixelFormat_RGBA8888;

	CCTexture2D *pTexture = new CCTexture2D();

	if (! pTexture)
	{
		CCLOG("cocos2d: CCGrid: error creating texture");
		delete this;
		return false;
	}

	pTexture->initWithTexture(
		new GLESTexture(POTWide, POTHigh, CCTexture2D::ToNitPixelFormat(format, false)));

	initWithSize(gridSize, pTexture, false);

	pTexture->release();

	return true;
}