[osg-users] How to resize when using PIXEL_BUFFER?
Greg Danaha
osgforum at tevs.eu
Thu Feb 11 14:58:15 PST 2016
Hi,
Here's a follow-up. I have it about 95% working (finally!).
Here's my code to resize the pixel-buffer models.
Code:
osg::Camera * camera = m_nhiViewer->getCamera();
if (camera != nullptr)
{
osg::ref_ptr<osg::GraphicsContext> gc = camera->getGraphicsContext();
if (gc != nullptr)
{
if (gc->releaseContext())
{
gc->close(); // will release PixelBufferWin32 and resources
// create new graphics context
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = m_width;
traits->height = m_height;
traits->red = 8;
traits->green = 8;
traits->blue = 8;
traits->depth = 24;
traits->pbuffer = true;
traits->doubleBuffer = true;
traits->readDISPLAY();
traits->supportsResize = true;
gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc != nullptr)
{
gc->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
gc->setClearColor(m_background);
camera->setGraphicsContext(gc.get());
osg::ref_ptr<osg::Image> image = nullptr;
std::map<osg::Camera::BufferComponent, osg::Camera::Attachment> bam = camera->getBufferAttachmentMap();
if (!bam.empty())
{
osg::Camera::BufferAttachmentMap::iterator iter = bam.find(osg::Camera::COLOR_BUFFER);
if (iter != bam.end())
image = iter->second._image;
}
if (image != nullptr)
{
image->allocateImage(m_width, m_height, image->r(), image->getPixelFormat(), image->getDataType(),
image->getPacking());
}
m_nhiViewer->realize();
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) :
camera->getProjectionMatrix() *= osg::Matrix::scale(1.0 / aspectRatioChange, 1.0, 1.0);
break;
case(osg::Camera::VERTICAL) :
camera->getProjectionMatrix() *= osg::Matrix::scale(1.0, aspectRatioChange, 1.0);
break;
default:
break;
}
}
camera->setViewport(0, 0, m_width, m_height);
double eventTime = m_nhiViewer->getEventQueue()->getTime();
m_nhiViewer->getEventQueue()->windowResize(0, 0, m_width, m_height, eventTime);
}
}
}
}
But the real problem was that when I set up the rendering when the model loaded, I specified
camera->setRenderTargetImplementation(osg::Camera::PIXEL_BUFFER);
That seemed to throw everything off. Now it is defaulting to FRAME_BUFFER and using traits->pbuffer = true; to set up the pixel buffering.
I still have one problem though. It works great with models (e.g. .flt) but when I resize an earth file it doesn't render properly. I also get an error 'invalid enumerant' after RenderBin::draw() in osgUtil RenderBin.cpp. The error value is 1280. The earth image looks as below after I resize it (or it comes up black). If I resize it again the globe is black.
Any additional help would be greatly appreciated.
...
Thank you!
Cheers,
Greg[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66275#66275
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EarthQuarters.png
Type: image/png
Size: 100819 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160211/31b60139/attachment-0003.png>
More information about the osg-users
mailing list