cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.21k stars 7.06k forks source link

CCRenderTexture gets black screenshot when using multiple Camera #13374

Open folgerhu opened 9 years ago

folgerhu commented 9 years ago

Cocos 2d-x v3.6

...

_camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 1000);
_camera->setCameraFlag(CameraFlag::USER1);
_layer3D->addChild(_camera, 0,"camera1");
_layer3D->setCameraMask(0x2);

CCRenderTexture* render = RenderTexture::create(size.width/CC_CONTENT_SCALE_FACTOR(), size.height/CC_CONTENT_SCALE_FACTOR());

render->setKeepMatrix(true);
render->beginWithClear(0, 0, 0, 0);
visit();
render->end();
Director::getInstance()->getRenderer()->render();

char jpg2[20];
sprintf(jpg2, "image-%d.jpg", 123);
std::string fullpath1 = FileUtils::getInstance()->getWritablePath() + jpg2;
Image* image1 = render->newImage();
image1->saveToFile(fullpath1, true);
image1->release();

The saved image is black.

zilongshanren commented 9 years ago

@yangws please take a look at it.

xingshh commented 8 years ago

i try to fix this bug by set cameramask, Camera* visitCamera = Camera::getVisitingCameraEx(); Camera::setVisitingCamera(_activeCamera); _rendTexture->setKeepMatrix(true); _rendTexture->setCameraMask(0x2);

   _modelDrawNode->visit();

_rendTexture->end();
_rendTexture->saveToFile(fileNanme);
Director::getInstance()->getRenderer()->render();
Camera::setVisitingCamera(visitCamera);

it can work for draw3d. but for sprite3d, it is failed, there is no 3dmodel displayed in picture file . i find it is caused by meshcammand. if not use meshcammand and use custom render command like this: CustomCommand &cc = std::get<2>(effect); cc.func = CC_CALLBACK_0(MyEffect3D::draw, std::get<1>(effect), transform); renderer->addCommand(&cc); it can work. how to fixed this bug?

I fix this. it cause by commend type. need to add somefunction. set rendertexture begin and end commend type to 3D