[osg-users] How to resize when using PIXEL_BUFFER?

Greg Danaha osgforum at tevs.eu
Fri Feb 5 06:30:32 PST 2016


greg_nhi1 wrote:
> Hi,
> 
> Our application (Windows x64) writes to a memory buffer rather than a window.  The app using OSG runs as a hidden console app and streams the rendered images via named pipe to a client app.  (Even if we weren't using a separate process for OSG we need to render using PIXEL_BUFFER since our app is WPF and doesn't provide a usable window handle.)
> 
> When I resize the display window I send a message to my processor so it can resize the OSG components.  However, I cannot find a way to do this that works.  I get the following results by trying different methods.
> 
> I've searched the sample code and forums and can't find anything (other than the methods I have tried based on sample code).  Any help would be appreciated.
> 
> 
> For reference (I'm using an earth image to check proportions and coordinates - I get the same results using models):
> 
> The last image (SmallEarthEventQueue) was generated using this source code to resize.
> 
> double eventTime = m_nhiViewer->getEventQueue()->getTime();
> 			m_nhiViewer->getEventQueue()->windowResize(0, 0, m_width, m_height, eventTime);
> 
> 
> The next up (SmallEarth-NoProjChange) was generated using this source code to resize.
> 
> gc->resized(0, 0, m_width, m_height);
> 
> camera->resize(m_width, m_height, osg::Camera::ResizeMask::RESIZE_ATTACHMENTS | osg::Camera::ResizeMask::RESIZE_VIEWPORT);
> 
> 
> The next up (SmallEarth-ProjChange) was generated using this source code.
> 
> osg::Camera * camera = m_nhiViewer->getCamera();
> if (camera != nullptr)
> {
> 	osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext();
> 	if (gc != nullptr)
> 	{
> 		osg::Matrixd origCamProjMatrix = camera->getProjectionMatrix();
> 
> 		gc->resized(0, 0, m_width, m_height);
> 
> 		double widthChangeRatio = double(m_width) / double(m_lastWidth);
> 		double heightChangeRatio = double(m_height) / double(m_lastHeight);
> 		double aspectRatioChange = widthChangeRatio / heightChangeRatio;
> 
> 		if (aspectRatioChange != 1.0)
> 		{
> 			switch (camera->getProjectionResizePolicy())
> 			{
> 			case(osg::Camera::HORIZONTAL) :
> 			case(osg::Camera::VERTICAL) :
> 				origCamProjMatrix *= osg::Matrix::scale(1.0 / aspectRatioChange, 1.0 / aspectRatioChange, 1.0);
> 				origCamProjMatrix *= osg::Matrix::translate(-(1.0 - widthChangeRatio), -(1.0 - heightChangeRatio), 0.0);
> 				break;
> 
> 			default: 
> 				break;
> 			}
> 		}
> 
> 		camera->resize(m_width, m_height, osg::Camera::ResizeMask::RESIZE_ATTACHMENTS | osg::Camera::ResizeMask::RESIZE_VIEWPORT);
> 
> 		camera->setProjectionMatrix(origCamProjMatrix);
> 	}
> }
> 
> 
> 
> ... 
> 
> Thank you!
> 
> Cheers,
> Greg


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66225#66225








More information about the osg-users mailing list