Re: [osg-users] How to set camera focal length
just found where the problem is: Viewer.cpp, line 1023: inside viewer.updateTraversals if (_cameraManipulator.valid()) { setFusionDistance( getCameraManipulator()-getFusionDistanceMode(), getCameraManipulator()-getFusionDistanceValue() ); _camera-setViewMatrix(_cameraManipulator-getInverseMatrix()); } So, at each frame the camera's matrix is overwritten by a new matrix which is taken from MatrixManipulator. I still wonder why viewer doesn't render anything at all (black image) if no MatrixManipulator is set. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34702#34702 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to set camera focal length
Skylark wrote: Most likely your view matrix calculation has an error. Yes, just found out the view matrix was wrong and the image was black because the camera was inside some object or something, and i first thought i am reading from a wrong buffer. Sorry guys for bothering you with such simple stuff. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34710#34710 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to set camera focal length
[quote=robertosfield]HI Igor, an osg::Camera nor GL camera don't have a concept of a focal length. [quote] Under Focal length I mean the distance from the camera's lens to it's focus. This distance can be different for x and y, for example, if the camera's lens is oval in shape. I have to write a function which receives, among other parameters, these 2 values (x focal length and y focal length) and have to pass it somehow to the OSG viewer. Is there a way to do this at all? If this is important, in the library for which i have to do this, the x axis goes from left to right of the screen, y axis goes form top to bottom of the screen and z axis goes away from the viewer. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34660#34660 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to set camera focal length
Thanks for help! I am setting the focal lense x and y with the following calls now and it seems to work fine: double fovy = 2 * atan(this-_height / 2.0 / dFocalLengthY); double aspectRatio = this-_nWidth / this-_nHeight * dFocalLengthY / dFocalLengthX; double zNear = 0.1, zFar = 100.0; _viewer.getCamera()-setProjectionMatrix(::osg::Matrix::perspective(fovy, aspectRatio, zNear, zFar)); But i still can't set up the position and rotation of the viewer's camera. this-_viewer.getCamera()-setReferenceFrame(::osg::Transform::ABSOLUTE_RF); this-_viewer.getCamera()-setViewMatrix(::osg::Matrix::translate(0.5, 0.3, 0.1)); this does nothing. My guess is becase i also have to call: ::osg::ref_ptr ::osgGA::KeySwitchMatrixManipulator keyswitchManipulator = new ::osgGA::KeySwitchMatrixManipulator; keyswitchManipulator-addMatrixManipulator( '1', Trackball, new ::osgGA::TrackballManipulator() ); this-_viewer.setCameraManipulator( keyswitchManipulator.get() ); or the offscreen capture doesn't render the scene, just an empty background. It looks like viewer needs a camera manipulator or it won't render the scene. Is it at all possible to move the camera programmatically after a camera manipulator has been set for the viewer? Or can i avoid creating a camera manipulator? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34672#34672 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Threads-related bug in screen capture?
Hi guys, I am writing a wrapper for screen capturing logic. I used osgscreencapture example as a start, and it works. However, I am experiencing strange bugs: 1. if you order the viewer to change the background color viewer.getCamera()-setClearColor(::osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f); and then call viewer.frame() ther is a chance (not 100%!) that the screenshot will still have the old color. After you call viewer.frame() again, the screenshot has the new color. 2. If you first call viewer.setSceneData(NULL); and then viewer.setSceneData(pNode); where pNode is a valid pointer to OSG scene, you sometimes (again, not 100%!) still get an empty image (with no scene) if you call viewer.frame(). I suspect these bugs are related and show a more generic bug with threading. My guess would be that although .frame() call goes after the change to viewer's setting, somehow the frame() call uses old values. I built up a small example which shows when these bugs appear by me. Thank you! Cheers, Igor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34573#34573 Attachments: http://forum.openscenegraph.org//files/screencapture_threading_test_106.cpp ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Threads-related bug in screen capture?
Hmm, after some testing I found out that the Images don't get their background updates only if END_FRAME is passed to WindowCaptureCallback. With START_FRAME it works ok. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34588#34588 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osgscreencapture sample doesn't work
Thanks a lot, guys! Yesterday i though i'd go mad, it was like hitting the head against a wall.. But yes, i checked out the current subversion tomorrow morning and managed to write an image successfully under Windows with osgscreencapture. Now it should be (hopefully) trivial to use it in my project. Thanks for help and for the fix! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34408#34408 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to render the OSG scene to an image file?
OK, the problem was with the bug in the Windows implementation of the PixelBuffer implementation. Checked out the latest version from SVN trunk (development one) and got osgscreencapture working under Windows. Will use it now in my project. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34409#34409 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] osgscreencapture sample doesn't work
Hi, I am trying to render the scene to an image without opening any windows. After doing a lot of searching and looking thru source code of OSG classes, I still get a completely white image. In many places people say one should use the same code as there is in osgscreencapture which renders to a pbuffer is --pbuffer-only option is passed. But the fact is that osgscreencapture doesn't work itself! osgscreencapture.exe axes.osg --pbuffer-only 640 480 must produce an image without opening any windows. When running this on my laptop (WindowsXP home) i get the following error message: PixelBufferWin32::init(), Error: Couldn't find a suitable pixel format Pixel buffer has not been created successfully. Windows Error #2000: Win32WindowingSystem::OpenGLContext() - Unable to restore current OpenGL rendering context. Reason: Pixel format is invalid. after that the axes.osg file is just opened in a full-screen viwer window, no image file is created. When running this on my Desktop PC (WindowsXP Pro) i get the following error message: Pixel buffer has been created successfully. PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die angeforderte Ressource wird bereits verwendet. (The requested resource is already being used) Error: OpenGL version test failed, requires valid graphics context. After that the program crashes and attempt to open Visual Studio debugger. On both machines OSG is correctly installed, e.g. i can easily open the osg files in viewer by double clicking. Do I at least call the osgscreenviewer correctly? ... Thank you! Cheers, Igor -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=34307#34307 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to render the OSG scene to an image file?
The following piece of code writes the same error to the console: Code: !!! pbuffer is VALID! PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die angeforde rte Ressource wird bereits verwendet. Error: OpenGL version test failed, requires valid graphics context. PixelBufferWin32::realizeImplementation, wglShareLists error: Die angeforderte R essource wird bereits verwendet. PixelBufferWin32::makeCurrentImplementation, wglMakeCurrent error: Die angeforde rte Ressource wird bereits verwendet. so, wglMakeCurrent(_hdc, _hglrc) fails in bool PixelBufferWin32::makeCurrentImplementation() see http://www.openscenegraph.org/svn/osg/OpenSceneGraph/tags/OpenSceneGraph-2.6.1/src/osgViewer/PixelBufferWin32.cpp May this be a Windows bug or OSG's implementation for Windows bug? ::osgViewer::Viewer * viewer = new ::osgViewer::Viewer(); viewer-setSceneData(pGeode); ::osg::ref_ptrSnapImageDrawCallback snapImageDrawCallback = new SnapImageDrawCallback(); viewer-getCamera()-setFinalDrawCallback (snapImageDrawCallback.get()); snapImageDrawCallback-setFileName(1.bmp); snapImageDrawCallback-setSnapImageOnNextFrame(true); ::osg::ref_ptr ::osg::GraphicsContext pbuffer; ::osg::ref_ptr ::osg::GraphicsContext::Traits traits = new ::osg::GraphicsContext::Traits; traits-x = 0; traits-y = 0; traits-width = 640; traits-height = 480; traits-red = 8; traits-green = 8; traits-blue = 8; traits-alpha = 8; traits-windowDecoration = false; traits-pbuffer = true; traits-doubleBuffer = true; traits-sharedContext = 0; pbuffer = ::osg::GraphicsContext::createGraphicsContext(traits.get()); if (!pbuffer.valid()) { ::std::cout \n\n!!! pbuffer is invalid!\n\n std::endl; return; } else { ::std::cout \n\n!!! pbuffer is VALID!\n\n std::endl; } viewer-getCamera()-setGraphicsContext(pbuffer.get()); viewer-getCamera()-setViewport(new osg::Viewport(0,0,640,480)); GLenum buffer = pbuffer-getTraits()-doubleBuffer ? GL_BACK : GL_FRONT; viewer-getCamera()-setDrawBuffer(buffer); viewer-getCamera()-setReadBuffer(buffer); viewer-getCamera()-setRenderTargetImplementation(::osg::CameraNode::FRAME_BUFFER_OBJECT); viewer-frame(); -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=33995#33995 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to render the OSG scene to an image file?
Thanks a lot for you replies! I tried to use the code but so far without success. At most I get a completely black image, but sometimes the SnapImageDrawcallback's operator() is never even called.. Here is my code. What exactly am I doing wrong here? class SnapImageDrawCallback : public ::osg::CameraNode::DrawCallback { public: SnapImageDrawCallback() { _snapImageOnNextFrame = false; } void setFileName(const std::string filename) { _filename = filename; } const std::string getFileName() const { return _filename; } void setSnapImageOnNextFrame(bool flag) { _snapImageOnNextFrame = flag; } bool getSnapImageOnNextFrame() const { return _snapImageOnNextFrame; } virtual void operator () (const ::osg::CameraNode camera) const { ::osg::notify(::osg::NOTICE) Saving screen image to '_filename' std::endl; if (!_snapImageOnNextFrame) return; int x,y,width,height; x = camera.getViewport()-x(); y = camera.getViewport()-y(); width = camera.getViewport()-width(); height = camera.getViewport()-height(); ::osg::ref_ptr ::osg::Image image = new ::osg::Image(); image-readPixels(x,y,width,height,GL_RGB,GL_UNSIGNED_BYTE); if (::osgDB::writeImageFile(*image,_filename)) { std::cout Saved screen image to '_filename' std::endl; } _snapImageOnNextFrame = false; } protected: ::std::string _filename; mutable bool _snapImageOnNextFrame; }; void renderSceneToImage(::osg::Node* pRoot, const ::std::string sFileName_) { int nWidth = 640, nHeight = 480; ::osgViewer::Viewer * viewer = new ::osgViewer::Viewer(); viewer-setSceneData(pRoot); viewer-getCamera()-setRenderTargetImplementation(::osg::CameraNode::FRAME_BUFFER_OBJECT); ::osg::ref_ptrSnapImageDrawCallback snapImageDrawCallback = new SnapImageDrawCallback(); viewer-getCamera()-setPostDrawCallback (snapImageDrawCallback.get()); snapImageDrawCallback-setFileName(sFileName_); snapImageDrawCallback-setSnapImageOnNextFrame(true); ::osg::ref_ptr ::osg::GraphicsContext pbuffer; ::osg::ref_ptr ::osg::GraphicsContext::Traits traits = new ::osg::GraphicsContext::Traits; traits-x = 0; traits-y = 0; traits-width = nWidth; traits-height = nHeight; traits-red = 8; traits-green = 8; traits-blue = 8; traits-alpha = 8; traits-windowDecoration = false; traits-pbuffer = true; traits-doubleBuffer = true; traits-sharedContext = 0; pbuffer = ::osg::GraphicsContext::createGraphicsContext(traits.get()); if (pbuffer.valid()) { ::osg::ref_ptr ::osg::Camera camera2 = new ::osg::Camera(); camera2-setGraphicsContext(pbuffer.get()); GLenum buffer = pbuffer-getTraits()-doubleBuffer ? GL_BACK : GL_FRONT; camera2-setDrawBuffer(buffer);
[osg-users] How to render the OSG scene to an image file?
I have to write a series of classes wrapping OSG model, which loads OSG graph from an .osg file, uses some data from it, saves the scene back to .osg file etc. I can't find out how (if it's possible) to render an OSG graph into an image file. So, what i am trying to do is: void renderSceneToImage(::osg::Node* pNode, const ::std::string sFileName_, some camera parameteres here) The function should take the root node of the OSG scene, render it ONCE to an image (::osg::Image?) and then save the image into the file. I don't need to open any windows. From what I found on the net so far: // ::osg::Image* capImage = new ::osg::Image(); capImage-allocateImage(nWidth, nHeight, 1, GL_RGBA, GL_FLOAT); capImage-setInternalTextureFormat(GL_RGBA16F_ARB); ::osg::ref_ptr ::osg::Camera camera = new ::osg::Camera(); camera-setRenderTargetImplementation(::osg::CameraNode::FRAME_BUFFER_OBJECT); camera-setRenderOrder(::osg::Camera::PRE_RENDER); camera-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera-setViewport(0, 0, nWidth, nHeight); camera-attach(::osg::CameraNode::COLOR_BUFFER, capImage); // temporarily wrap the whole scene with camera camera-addChild(pScene-root()); ::osg::ref_ptr ::osg::Group tempRoot = new ::osg::Group(); tempRoot-addChild(camera.get()); // HOW TO ORDER THE CAMERA TO RENDER? ::osgDB::writeImageFile(*capImage, sFileName_); //- So, i can't find any way to order the camera to render once. All examples show how to make the camera render to a texture, but when it renders is decided by OpenGL (?). I don't need all that, i just need to grab the picture once and return. Is this possible with OSG? Thanks! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=33809#33809 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org