Camera* HMDScene::setupCamera(float ratio, bool left) { auto s = Director::getInstance()->getWinSize(); auto sizeInpixels = Director::getInstance()->getWinSizeInPixels(); auto fboSize = Size(sizeInpixels.width * 1.f, sizeInpixels.height * 1.f); auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height); auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height); auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height); fbo->attachRenderTarget(rt); fbo->attachDepthStencilTarget(rtDS); auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture()); sprite->setPosition((left ? s.width * 0.25f : s.width * 0.75f) , s.height * 0.5f); sprite->setRotation3D(Vec3(0.0f, 180.0f, 180.0f)); sprite->setScale(0.5f, 1.0f); Scene::addChild(sprite); auto cam = Camera::createPerspective(60, ratio, 0.01f, 100.0f); cam->setPosition3D(Vec3(0.0f, 0.0f, 0.0f)); cam->setCameraFlag(left ? CameraFlag::USER7 : CameraFlag::USER8); cam->setDepth(-1); cam->setName( (left ? "HMD-Cam-L" : "HMD-Cam-R") ); cam->setFrameBufferObject(fbo); // useful for debugging viewport stuff //fbo->setClearColor(Color4F( (left ? 0.25f : 0.0f) , (left ? 0.0f : 0.25f), 0, 1)); return cam; }
void CameraFrameBufferTest::onEnter() { auto sizeInpixels = Director::getInstance()->getWinSizeInPixels(); auto size = Director::getInstance()->getWinSize(); auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5); auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height); CameraBaseTest::onEnter(); //auto sprite = Sprite::createWithTexture(fbo); //sprite->setPosition(Vec2(100,100)); //std::string filename = "Sprite3DTest/girl.c3b"; //auto sprite = Sprite3D::create(filename); //sprite->setScale(1.0); //auto animation = Animation3D::create(filename); //if (animation) //{ // auto animate = Animate3D::create(animation); // sprite->runAction(RepeatForever::create(animate)); //} //sprite->setPosition(Vec2(100,100)); auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height); auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height); fbo->attachRenderTarget(rt); fbo->attachDepthStencilTarget(rtDS); auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture()); sprite->setScale(0.3); sprite->runAction(RepeatForever::create(RotateBy::create(1, 90))); sprite->setPosition(size.width/2, size.height/2); addChild(sprite); auto sprite2 = Sprite::create(s_pathGrossini); sprite2->setPosition(Vec2(size.width/5,size.height/5)); addChild(sprite2); sprite2->setCameraMask((unsigned short)CameraFlag::USER1); auto move = MoveBy::create(1.0, Vec2(100,100)); sprite2->runAction( RepeatForever::create( Sequence::createWithTwoActions( move, move->reverse()) ) ); auto camera = Camera::create(); camera->setCameraFlag(CameraFlag::USER1); camera->setDepth(-1); camera->setFrameBufferObject(fbo); fbo->setClearColor(Color4F(1,1,1,1)); addChild(camera); }