本文整理汇总了C++中CCRenderTexture类的典型用法代码示例。如果您正苦于以下问题:C++ CCRenderTexture类的具体用法?C++ CCRenderTexture怎么用?C++ CCRenderTexture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCRenderTexture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: glColor4ub
CCSprite *Puzzle::spriteImageMask() {
// 1: Create new CCRenderTexture
CCRenderTexture *rt = CCRenderTexture::renderTextureWithWidthAndHeight(Puzzle::canvasSize.width, Puzzle::canvasSize.height);
// 2: Call CCRenderTexture:begin
rt->beginWithClear(0, 0, 0, 0);
// 3: Draw into the texture
CCPoint vertices[4];
glColor4ub(255, 255, 255, 255);
for (int i = 0; i < numtaken; i++) {
vertices[0] = ccp(taken[i].x, taken[i].y);
vertices[1] = ccp(taken[i].x, taken[i].y + dimY);
vertices[2] = ccp(taken[i].x + dimX, taken[i].y + dimY);
vertices[3] = ccp(taken[i].x + dimX, taken[i].y);
ccDrawPoly(vertices, 4, true, true);
}
// 4: Call CCRenderTexture:end
rt->end();
// 5: Create a new Sprite from the texture
CCSprite *ret = CCSprite::spriteWithTexture(rt->getSprite()->getTexture());
ret->setFlipY(true);
return ret;
}
示例2: renderScreenShot
void RenderTextureZbuffer::renderScreenShot()
{
CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(512, 512);
if (NULL == texture)
{
return;
}
texture->setAnchorPoint(ccp(0, 0));
texture->begin();
this->visit();
texture->end();
CCSprite *sprite = CCSprite::spriteWithTexture(texture->getSprite()->getTexture());
sprite->setPosition(ccp(256, 256));
sprite->setOpacity(182);
sprite->setFlipY(1);
this->addChild(sprite, 999999);
sprite->setColor(ccGREEN);
sprite->runAction(CCSequence::actions(CCFadeTo::actionWithDuration(2, 0),
CCHide::action(),
NULL));
}
示例3: ccp
CCRenderTexture * Utils::fontCreateStroke(CCLabelTTF * label,float size, ccColor3B color){
CCRenderTexture *rt = CCRenderTexture::create((int)label->getTexture()->getContentSize().width, (int)label->getTexture()->getContentSize().height);
CCPoint originalPos = label->getPosition();
ccColor3B originalColor = label->getColor();
bool originalVisibility = label->isVisible();
label->setColor(color);
ccBlendFunc originalBlend = label->getBlendFunc();
label->setBlendFunc((ccBlendFunc){ GL_SRC_ALPHA, GL_ONE });
//CCPoint center = ccp(label->getTexture()->getContentSize().width/2 + size, label->getTexture()->getContentSize().height/2 + size); //shadow effect offset
CCPoint center = ccp(label->getTexture()->getContentSize().width/2, label->getTexture()->getContentSize().height/2);
rt->begin();
for(int i = 0; i<360; i+=30){
label->setPosition(ccp(center.x + sin(CC_DEGREES_TO_RADIANS(i)) * size, center.y + cos(CC_DEGREES_TO_RADIANS(i)) * size));
label->visit();
}
rt->end();
label->setPosition(originalPos);
label->setColor(originalColor);
label->setBlendFunc(originalBlend);
label->setVisible(originalVisibility);
rt->setPosition(originalPos);
return rt;
}
示例4: CCLog
bool GameUtil::resizeImage(const char* szInFile, const char* szOutFile, int width, int height)
{
CCLog("GameUtil::resizeImage - [path:%s] [W:%d] [H:%d]", szInFile, width, height);
CCSprite* pOrg = CCSprite::create(szInFile);
CCSize orgSize = pOrg->getContentSize();
float fScaleX = (float)width / orgSize.width;
float fScaleY = (float)height / orgSize.height;
float fScale = max(fScaleX, fScaleY);
CCPoint ptCenter = ccp(width/2, height/2);
// 세로 사진은 가로로 방향을 변경
if (orgSize.width < orgSize.height) {
pOrg->setRotation(90.0f);
ptCenter = ccp(height/2, width/2);
}
CCRenderTexture * rt = CCRenderTexture::create(width, height);
pOrg->setPosition(ptCenter);
pOrg->setAnchorPoint(ccp(0.5f, 0.5f));
pOrg->setScale(fScale);
rt->begin();
pOrg->visit();
rt->end();
// 파일로 저장
bool bSave = rt->saveToFile(szOutFile);
return bSave;
}
示例5: createWithColor
CCSprite* CCSprite::createWithColor(ccColor4F bgColor, float textureWidth, float textureHeight)
{
CCRenderTexture *rt = CCRenderTexture::create(textureWidth, textureHeight);
rt->beginWithClear(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
rt->end();
return CCSprite::createWithTexture(rt->getSprite()->getTexture());
}
示例6: ptOrg1
CCSprite* GameUtil::mergeSprite(CCSprite* pOrg1, CCSprite* pOrg2)
{
CCPoint ptOrg1(pOrg1->getPosition());
CCPoint ptOrg2(pOrg2->getPosition());
CCRenderTexture * rt = CCRenderTexture::create((int)pOrg1->getContentSize().width, (int)pOrg1->getContentSize().height);
pOrg1->setPosition(ccp(pOrg1->getContentSize().width/2, pOrg1->getContentSize().height/2));
pOrg2->setPosition(ccp(pOrg2->getContentSize().width/2, pOrg2->getContentSize().height/2));
rt->begin();
pOrg1->visit();
pOrg2->visit();
rt->end();
pOrg1->setPosition(ptOrg1);
pOrg2->setPosition(ptOrg2);
CCSprite *retSprite = CCSprite::createWithTexture(rt->getSprite()->getTexture());
retSprite->setFlipY(true);
//CCSize sisze1 = retSprite->getContentSize();
//CCSize size2 = retSprite->getTexture()->getContentSize();
// debugging : 파일로 저장
//string sPath = CCFileUtils::sharedFileUtils()->getWriteablePath();
//sPath.c_str();
//char szSave[MAX_PATH];
//sprintf(szSave, "%ssave.png", sPath.c_str());
//bool bSave = rt->saveToFile(szSave);
return retSprite;
}
示例7: generateTexture
CCTexture2D* Sky::generateTexture()
{
CCRenderTexture* pRenderTexture = CCRenderTexture::create(m_nTextureSize, m_nTextureSize);
pRenderTexture->beginWithClear(0.55f, 0.80f, 0.86f, 1.0f);
//gradient
float alpha = 1.0f;
ccColor4B color1 = {255, 255, 255, 0};
ccColor4B color2 = {255, 255, 255, 255};
CCLayerGradient* pLayerColor = CCLayerGradient::create(color1, color2);
pLayerColor->setContentSize(CCSizeMake(m_nTextureSize, m_nTextureSize));
pLayerColor->setPosition(ccp(0, 0));
pLayerColor->visit();
//noise
CCSprite* pSprite = CCSprite::create("noise.png");
pSprite->setPosition(ccp(m_nTextureSize / 2, m_nTextureSize / 2));
pSprite->setBlendFunc((ccBlendFunc){GL_DST_COLOR, GL_ZERO});
pSprite->setScale(m_nTextureSize / 512.0f);
pSprite->visit();
pRenderTexture->end();
CCTexture2D* pTex = pRenderTexture->getSprite()->getTexture();
ccTexParams params = {GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT};
pTex->setTexParameters(¶ms);
return pTex;
}
示例8: ScreenShoot
static CCString ScreenShoot()
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
//定义一个屏幕大小的渲染纹理
CCRenderTexture* pScreen = CCRenderTexture::create(size.width,size.height, kCCTexture2DPixelFormat_RGBA8888);
//获得当前的场景指针
CCScene* pCurScene = CCDirector::sharedDirector()->getRunningScene();
//渲染纹理开始捕捉
pScreen->begin();
//当前场景参与绘制
pCurScene->visit();
//结束捕捉
pScreen->end();
char szfile[1024]={0};
//string pathToSave = "/sdcard/download/";//
string pathToSave = "ScreenShoot.png";
//sprintf(szfile,"%s%s",pathToSave.c_str(),"share.png");
//保存为png
if(pScreen->saveToFile(pathToSave.c_str(), kCCImageFormatPNG))
{
//CCMessageBox("saveToFile ok!", "saveToFile ok!");
}
pathToSave = CCFileUtils::sharedFileUtils()->getWritablePath()+pathToSave;
//保存为jpg
//pScreen->saveToFile("XXXXXX.jpg", kCCImageFormatJPEG);
CC_SAFE_DELETE(pScreen);
return pathToSave.c_str();
}
示例9: PauseGame
//ÔÝÍ£
void CGameControler::PauseGame(int _type){
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCRenderTexture *renderTexture = CCRenderTexture::create(visibleSize.width,visibleSize.height);
renderTexture->begin();
this->getParent()->visit();
renderTexture->end();
CCDirector::sharedDirector()->pushScene(Gamepause::scene(renderTexture));
}
示例10: initShareMessageBox
void AsMessageBox::initShareMessageBox(int subType){
if(!MainUser->muted)
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("openFrame.wav");
shareImageIndex = subType;
//1.截屏
if (subType == 1) {
CCRenderTexture* pScreen = CCRenderTexture::create(winSize.width,winSize.height);
CCScene* pCurScene = CCDirector::sharedDirector()->getRunningScene();
pScreen->begin();
pCurScene->visit();
pScreen->end();
pScreen->saveToFile("shared.png",kCCImageFormatPNG);
}
//2.黑色底层
cover = CCLayerColor::create(ccc4(0,0,0,200));
cover->setPosition(CCPointZero);
addChild(cover,0);
//3.提示框底层
showbox = CCSprite::createWithSpriteFrameName("shareFrame.png");
showbox->setScaleY(1.1);
showbox->setPosition(ccp(size.width/2,size.height/2+winDif*2*alpha));
cover->addChild(showbox,1);
//4.提示框上的文字
CCSprite* shareWeixinSprite = CCSprite::createWithSpriteFrameName("shareWeixin.png");
CCSprite* shareWeixinSprite_s = CCSprite::createWithSpriteFrameName("shareWeixin-s.png");
CCSprite* shareWeixin1Sprite = CCSprite::createWithSpriteFrameName("shareWeixin1.png");
CCSprite* shareWeixin1Sprite_s = CCSprite::createWithSpriteFrameName("shareWeixin1-s.png");
CCSprite* closeSprite = CCSprite::createWithSpriteFrameName("closeMatchTable.png");
CCSprite* closeSprite_s = CCSprite::createWithSpriteFrameName("closeMatchTable-s.png");
CCMenuItemSprite* closeItem = CCMenuItemSprite::create(closeSprite,closeSprite_s,this,menu_selector(AsMessageBox::closeMessageBox));
CCMenuItemSprite* item1 = CCMenuItemSprite::create(shareWeixinSprite,shareWeixinSprite_s,this,menu_selector(AsMessageBox::goShare));
CCMenuItemSprite* item2 = CCMenuItemSprite::create(shareWeixin1Sprite,shareWeixin1Sprite_s,this,menu_selector(AsMessageBox::goShare));
item1->setTag(10);
item2->setTag(11);
item1->setPosition(ccp(size.width*18/50,size.height*10/20+winDif*2.18*alpha));
item2->setPosition(ccp(size.width*32/50,size.height*10/20+winDif*2.18*alpha));
closeItem->setPosition(ccp(size.width*5.7/7,size.height*11.5/20+winDif*2.18*alpha));
closeMenu = CCMenu::create(item1,item2,closeItem,NULL);
closeMenu->setPosition(CCPointZero);
addChild(closeMenu,2);
//5.文字提示
CCLabelTTF* shareToIndiLabel = CCLabelTTF::create("分享给朋友","Arial Rounded MT Bold",24);
CCLabelTTF* shareToCircleLabel = CCLabelTTF::create("分享到朋友圈","Arial Rounded MT Bold",24);
shareToIndiLabel->setColor(ccc3(55, 55, 55));
shareToCircleLabel->setColor(ccc3(55, 55, 55));
shareToIndiLabel->setPosition(ccp(size.width*18/50,size.height*8/20+winDif*2.18*alpha));
shareToCircleLabel->setPosition(ccp(size.width*32/50,size.height*8/20+winDif*2.18*alpha));
addChild(shareToIndiLabel,7,53);
addChild(shareToCircleLabel,7,54);
}
示例11: createStroke
CCRenderTexture* UILabelTTF::createStroke(CCLabelTTF* label, float size ,ccColor3B cor)
{
float RealSize = size;
if(label == NULL || label->getTexture() == NULL)
{
return NULL;
}
label->setAnchorPoint(ccp(0.5, 0.5));
CCRenderTexture* rt = CCRenderTexture::create(label->getContentSize().width + RealSize*2, label->getContentSize().height + RealSize*2);
rt->setAnchorPoint(ccp(0.0,0.0));
rt->setPosition(0,0);
if(rt->getSprite() && rt->getSprite()->getTexture())
{
rt->getSprite()->getTexture()->setAntiAliasTexParameters();
rt->getSprite()->setOpacityModifyRGB(true);
}
else
{
CCLog("UILabelTTF null texture");
}
CCPoint originalPos = label->getPosition();
ccColor3B originalColor = label->getColor();
bool originalVisibility = label->isVisible();
label->setColor(cor);
label->setVisible(true);
ccBlendFunc originalBlend = label->getBlendFunc();
ccBlendFunc tBlendFunc = {GL_SRC_ALPHA, GL_ONE };
label->setBlendFunc(tBlendFunc);
rt->clear(0, 0, 0, 0);
CCPoint center = ccp(label->getContentSize().width/2 ,label->getContentSize().height /2 );
rt->begin();
label->setPosition(ccp(center.x, center.y - RealSize));
label->visit();
label->setPosition(ccp(center.x + 2*RealSize, center.y - 2*RealSize));
label->visit();
label->setPosition(ccp(center.x + RealSize, center.y));
label->visit();
label->setPosition(ccp(center.x + 2*RealSize, center.y - RealSize));
label->visit();
label->setColor(originalColor);
label->setPosition(ccp(center.x,center.y));
label->visit();
rt->end();
label->setBlendFunc(originalBlend);
label->setVisible(originalVisibility);
label->setPosition(originalPos);
// for test
//char file[100];
//sprintf(file,"../../temp/%s_creat.png",label->getString());
//rt->saveToFile(file,kCCImageFormatPNG);
return rt;
}
示例12: onPause
void GameScene::onPause(cocos2d::CCObject *pSender)
{
pPauseMenu->setVisible(false);
CCRenderTexture *renderTexture = CCRenderTexture::create(SCREEN_WIDTH, SCREEN_HEIGHT);
renderTexture->begin();
this->getParent()->visit();
renderTexture->end(); //这里实际是通过CCRenderTexture保存当前界面(相当于截屏),然后传递给暂停界面,当成背景精灵
pPauseMenu->setVisible(true);
CCDirector::sharedDirector()->pushScene(PauseScene::scene(renderTexture,true));
}
示例13: menu_selector
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
CCSize size = CCDirector::sharedDirector()->getWinSize();
#if 0
CCLayerColor *colorLayer = CCLayerColor::create(ccc4(0,80,80,255));
addChild(colorLayer);
CCSprite *spr_premulti = CCSprite::create("Ball.png");
spr_premulti->setPosition(ccp(16,48));
CCSprite *spr_nonpremulti = CCSprite::create("Ball.png");
spr_nonpremulti->setPosition(ccp(16,16));
CCRenderTexture *rend = CCRenderTexture::create(32, 64, kCCTexture2DPixelFormat_RGBA8888);
if (rend == NULL)
exit(0);
rend->begin();
spr_premulti->visit();
spr_nonpremulti->visit();
rend->end();
addChild(spr_nonpremulti);
addChild(spr_premulti);
addChild(rend);
#endif
scheduleUpdate();
return true;
}
示例14: addChild
RenderTextureIssue937::RenderTextureIssue937()
{
/*
* 1 2
* A: A1 A2
*
* B: B1 B2
*
* A1: premulti sprite
* A2: premulti render
*
* B1: non-premulti sprite
* B2: non-premulti render
*/
CCLayerColor *background = CCLayerColor::layerWithColor(ccc4(200,200,200,255));
addChild(background);
CCSprite *spr_premulti = CCSprite::spriteWithFile("Images/fire.png");
spr_premulti->setPosition(ccp(16,48));
CCSprite *spr_nonpremulti = CCSprite::spriteWithFile("Images/fire.png");
spr_nonpremulti->setPosition(ccp(16,16));
/* A2 & B2 setup */
CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64);
if (NULL == rend)
{
return;
}
// It's possible to modify the RenderTexture blending function by
// [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];
rend->begin();
spr_premulti->visit();
spr_nonpremulti->visit();
rend->end();
CCSize s = CCDirector::sharedDirector()->getWinSize();
/* A1: setup */
spr_premulti->setPosition(ccp(s.width/2-16, s.height/2+16));
/* B1: setup */
spr_nonpremulti->setPosition(ccp(s.width/2-16, s.height/2-16));
rend->setPosition(ccp(s.width/2+16, s.height/2));
addChild(spr_nonpremulti);
addChild(spr_premulti);
addChild(rend);
}
示例15: CCRenderTexture
CCRenderTexture * CCRenderTexture::create(int w ,int h, CCTexture2DPixelFormat eFormat, GLuint uDepthStencilFormat)
{
CCRenderTexture *pRet = new CCRenderTexture();
if(pRet && pRet->initWithWidthAndHeight(w, h, eFormat, uDepthStencilFormat))
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
}