Hi there,
I have been trying to extend the osgppu_viewer to allow resizing of the viewer
window, similarly to the discussion at
http://forum.openscenegraph.org/viewtopic.php?t=3693. However, I'm not making
any progress and already wasted way too much time on this.
The problem is that I cannot set the camera's viewport without everything going
funny. This following code is called by a custom
osg::GraphicsContext::ResizedCallback on every resize:
Code:
void Viewer::resize(const int width, const int height)
{
osgDB::writeObjectFile(*_processor, "pre-resize.ppu");
// resize textures
if(_colorTexture.valid()) _colorTexture->setTextureSize(width, height);
if(_depthTexture.valid()) _depthTexture->setTextureSize(width, height);
// new viewport
Viewport* vp = new Viewport(0, 0, width, height);
// update camera
Camera* camera = getCamera();
double fovy, aspect, znear, zfar;
camera->getProjectionMatrixAsPerspective(fovy, aspect, znear, zfar);
camera->setViewport(vp); // ???
camera->setProjectionMatrixAsPerspective(fovy, width / (double)height, znear,
zfar);
// force processing pipeline to update
_processor->onViewportChange();
_processor->dirtyUnitSubgraph();
_unitOut->setViewport(vp);
// update all units' viewports etc.
NodeVisitor nv(NodeVisitor::TRAVERSE_ALL_CHILDREN);
_processor->accept(nv);
osgDB::writeObjectFile(*_processor, "post-resize.ppu");
}
For testing, I'm using the depth-of-field pipeline from osgpp_dof on cow.osg.
The viewports of all units appear to be resized correctly, as can be verified
by comparing the before/after saved .ppu-files. However, the displayed results
are not correct.
When I comment out the line marked with "???", I get the pipeline to fill the
window (with correct aspect ratio), but only in the original resolution (here:
640x480; "without line.jpg" attachment):
[Image: http://img210.imageshack.us/img210/6479/withoutline.th.jpg ]
(http://img210.imageshack.us/i/withoutline.jpg/)
And when I set the camera's viewport, the viewer only shows the bottom-left
640x480 pixels of _unitOut's texture ("with line.jpg" attachment):
[Image: http://img13.imageshack.us/img13/1299/withline.th.jpg ]
(http://img13.imageshack.us/i/withline.jpg/)
Any help is appreciated :)
Thanks,
Christian.
Edit: message was corrupted.
Edit2: Using imageshack instead of attached images.
PS: Due to several issues while posting the original message, it was not sent
to the mailing list. This is a repeat, so that it's also sent to the mailing
list (hopefully).
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=23768#23768
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org