|
楼主 |
发表于 2013-8-20 14:50:45
|
显示全部楼层
谢谢!我已经实现了在MyGUI::Canvas中嵌入RttTexture。和Array您的方法类似,中间需要TextureObject,不过id的创建和使用是反过来的。具体如下:
【思路】
用MyGUI::Canvas创建MyGUI::OpenGLTexture对象,然后再将Texture的id放入到TextrueObject中,再将TextureObject放入到osg::Texture2D中,最后通过camera::attach的方法将Camera和Canvas相关联。
【关键代码片段】
- // 创建Canvas,并创建Texture
- MyGUI::Canvas* canvas = root->createWidget<MyGUI::Canvas>("Canvas", MyGUI::IntCoord(0, 0, 512, 512), MyGUI::Align::Stretch, "Canvas1");
- canvas->createTexture(MyGUI::IntSize(512, 512), MyGUI::Canvas::TextureResizeMode::TRM_PT_VIEW_ALL);
- MyGUI::OpenGLTexture * openglTexture = dynamic_cast<MyGUI::OpenGLTexture*>(canvas->getTexture());
- // 创建Texture2D
- _texture = new osg::Texture2D;
- _texture->setWrap(osg::Texture2D::WrapParameter::WRAP_S,osg::Texture2D::WrapMode::CLAMP_TO_BORDER);
- _texture->setWrap(osg::Texture2D::WrapParameter::WRAP_T,osg::Texture2D::WrapMode::CLAMP_TO_BORDER);
- _texture->setInternalFormat( GL_RGBA );
- _texture->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR );
- _texture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
- _texture->setTextureSize(512,512);
- // MyGUI::ITextrue::ID => TextureID => TextureObject => Texture2D
- osg::ref_ptr<osg::Texture::TextureObject> to = new osg::Texture::TextureObject(_texture, openglTexture->getTextureID(), GL_TEXTURE_2D);
- _texture->setTextureObject(0, to);
- // 增加子Camera
- _camera = new osg::Camera;
- _camera->setViewport(0, 0, 512, 512);
- _camera->setAllowEventFocus(false);
- _camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- _camera->setClearColor(osg::Vec4(0.2, 0.2, 0.2, 0.2));
- _camera->setRenderOrder( osg::Camera::PRE_RENDER );
- _camera->setProjectionMatrix( osg::Matrix::ortho2D(-20, 120, -20, 120) );
- _camera->setViewMatrix(osg::Matrix::translate(osg::Vec3(.0, -100.0, 0.0)) * osg::Matrix::rotate(osg::DegreesToRadians(180.0), osg::Vec3(1., 0., 0.)) * osg::Matrix::identity());
- _camera->setCullMask(0x01);
- _camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- _camera->setRenderTargetImplementation(osg::Camera::RenderTargetImplementation::FRAME_BUFFER_OBJECT);
复制代码
【图释 】下图中将同一个Texture2D,在MyGUI::Canvas和一个osg平面上显示。
【新的问题】
1、在将RttCamera的内容放入到Canvas中显示时发现图像需要一个沿x轴的180翻转,否则图片显示的是反的。
2、放到Canvas中,无法Camera中的内容无法接收鼠标、键盘的响应,估计需要将MyGUI的鼠标键盘消息再重新映射到osg的消息处理中,这个是否是Array您说的结构设计不好?
|
|