<div dir="ltr"><div><div><div>Hi Romulo,<br><br></div>There is a lot of code in there which I wouldn't expect to affect the modelview and project matrices, my recommendation would be to create a small test example to test loading your data and setting your view and projection matrices as required without any of the frame capture code that will be getting in the way of working out what might be amiss.<br><br></div>You code also nothing about your scene graph, as this might well be the source of the issue there isn't much more we can guess at.</div><div><br></div><div>The best thing you can do at this point is go test your models against a standard example like osgviewer.  If the error occurs there then posting this so others can try and reproduce the problem.<br></div><div><br></div>Robert.<br><div><div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 September 2017 at 16:10, Rômulo Cerqueira <span dir="ltr"><<a href="mailto:romulogcerqueira@gmail.com" target="_blank">romulogcerqueira@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok Robert,<br>
<br>
this is my current code (only .cpp):<br>
<br>
<br>
Code:<br>
<br>
#include "ImageViewerCaptureTool.hpp"<br>
#include <iostream><br>
#include <unistd.h><br>
#include <osgDB/WriteFile><br>
<br>
namespace normal_depth_map {<br>
<br>
ImageViewerCaptureTool::<wbr>ImageViewerCaptureTool(uint width, uint height) {<br>
<br>
// initialize the hide viewer;<br>
initializeProperties(width, height);<br>
}<br>
<br>
ImageViewerCaptureTool::<wbr>ImageViewerCaptureTool( double fovY, double fovX, uint value, bool isHeight) {<br>
uint width, height;<br>
<br>
if (isHeight) {<br>
height = value;<br>
width = height * tan(fovX * 0.5) / tan(fovY * 0.5);<br>
} else {<br>
width = value;<br>
height = width * tan(fovY * 0.5) / tan(fovX * 0.5);<br>
}<br>
<br>
double aspectRatio = width * 1.0 / height;<br>
<br>
initializeProperties(width, height);<br>
_viewer->getCamera()-><wbr>setComputeNearFarMode(osg::<wbr>CullSettings::DO_NOT_COMPUTE_<wbr>NEAR_FAR);<br>
<br>
_viewer->getCamera()-><wbr>setProjectionMatrixAsPerspecti<wbr>ve(fovY * 180.0 / M_PI, aspectRatio, 0.1, 1000);<br>
}<br>
<br>
void ImageViewerCaptureTool::<wbr>initializeProperties(uint width, uint height) {<br>
// initialize the hide viewer;<br>
_viewer = new osgViewer::Viewer;<br>
osg::Camera *camera = this->_viewer->getCamera();<br>
osg::ref_ptr<osg::<wbr>GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;<br>
traits->width = width;<br>
traits->height = height;<br>
traits->pbuffer = true;<br>
traits->readDISPLAY();<br>
osg::ref_ptr<osg::<wbr>GraphicsContext> gc = osg::GraphicsContext::<wbr>createGraphicsContext(traits.<wbr>get());<br>
camera->setGraphicsContext(gc)<wbr>;<br>
camera->setDrawBuffer(GL_<wbr>FRONT);<br>
camera->setViewport(new osg::Viewport(0, 0, width, height));<br>
<br>
// initialize the class to get the image in float data resolution<br>
_capture = new WindowCaptureScreen(gc);<br>
_viewer->getCamera()-><wbr>setFinalDrawCallback(_capture)<wbr>;<br>
}<br>
<br>
osg::ref_ptr<osg::Image> ImageViewerCaptureTool::<wbr>grabImage(osg::ref_ptr<osg::<wbr>Node> node ) {<br>
<br>
_viewer->setSceneData(node);<br>
_viewer->frame();<br>
return _capture->captureImage();;<br>
}<br>
<br>
osg::ref_ptr<osg::Image> ImageViewerCaptureTool::<wbr>getDepthBuffer() {<br>
return _capture->getDepthBuffer();<br>
}<br>
<br>
<br>
void ImageViewerCaptureTool::<wbr>setCameraPosition( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up) {<br>
_viewer->getCamera()-><wbr>setViewMatrixAsLookAt(eye, center, up);<br>
}<br>
<br>
void ImageViewerCaptureTool::<wbr>getCameraPosition( osg::Vec3d& eye,osg::Vec3d& center, osg::Vec3d& up) {<br>
_viewer->getCamera()-><wbr>getViewMatrixAsLookAt(eye, center, up);<br>
}<br>
<br>
void ImageViewerCaptureTool::<wbr>setBackgroundColor(osg::Vec4d color) {<br>
_viewer->getCamera()-><wbr>setClearColor(color);<br>
}<br>
<br>
//////////////////////////////<wbr>//<br>
////WindowCaptureScreen METHODS<br>
//////////////////////////////<wbr>//<br>
<br>
WindowCaptureScreen::<wbr>WindowCaptureScreen(osg::ref_<wbr>ptr<osg::GraphicsContext> gc) {<br>
_mutex = new OpenThreads::Mutex();<br>
_condition = new OpenThreads::Condition();<br>
_image = new osg::Image();<br>
_depth_buffer = new osg::Image();<br>
<br>
// checks the GraficContext from the camera viewer<br>
if (gc->getTraits()) {<br>
<br>
GLenum pixelFormat;<br>
if (gc->getTraits()->alpha) pixelFormat = GL_RGBA;<br>
else pixelFormat = GL_RGB;<br>
<br>
int width = gc->getTraits()->width;<br>
int height = gc->getTraits()->height;<br>
<br>
// allocates the image memory space<br>
_image->allocateImage(width, height, 1, pixelFormat, GL_FLOAT);<br>
_depth_buffer->allocateImage(<wbr>width, height, 1, GL_DEPTH_COMPONENT, GL_FLOAT);<br>
}<br>
}<br>
<br>
WindowCaptureScreen::~<wbr>WindowCaptureScreen() {<br>
delete (_condition);<br>
delete (_mutex);<br>
}<br>
<br>
osg::ref_ptr<osg::Image> WindowCaptureScreen::<wbr>captureImage() {<br>
<br>
//wait to finish the capture image in call back<br>
_condition->wait(_mutex);<br>
return _image;<br>
}<br>
<br>
osg::ref_ptr<osg::Image> WindowCaptureScreen::<wbr>getDepthBuffer() {<br>
return _depth_buffer;<br>
}<br>
<br>
<br>
void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {<br>
osg::ref_ptr<osg::<wbr>GraphicsContext> gc = renderInfo.getState()-><wbr>getGraphicsContext();<br>
if (gc->getTraits()) {<br>
_mutex->lock();<br>
_image->readPixels( 0, 0, _image->s(), _image->t(), _image->getPixelFormat(), GL_FLOAT);<br>
_depth_buffer->readPixels(0, 0, _image->s(), _image->t(), _depth_buffer->getPixelFormat(<wbr>), GL_FLOAT);<br>
<br>
//grants the access to image<br>
_condition->signal();<br>
_mutex->unlock();<br>
<span class="">}<br>
}<br>
<br>
}<br>
<br>
<br>
<br>
<br>
<br>
...<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Rômulo<br>
<br>
</span><span class="">------------------<br>
Read this topic online here:<br>
</span><a href="http://forum.openscenegraph.org/viewtopic.php?p=71593#71593" rel="noreferrer" target="_blank">http://forum.openscenegraph.<wbr>org/viewtopic.php?p=71593#<wbr>71593</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</div></div></blockquote></div><br></div>