Re: [osg-users] Disappearing text
robertosfield wrote: > Hi Ronny, > > > Where the problem lies will likely be how you are managing the viewer as well > as the graphics context. My hunch is that you've created the problem with > your "custom" means of managing things. > > > If you can try running your application with a straight osgViewer::Viewer > with it creating a single window for you rather than hand wiring things > yourself, even if this doesn't give you exactly what you want for your final > application it will at least give you a sanity test to compare results > against. If this works then you know that the issue stems from your won > custom set up. > > While it possible to hand wire things up it's more complicated with more > options for screwing things up if your don't know how all the various > elements fully work together. > > > Robert. Thanks for the feedback, I will try to do that. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66868#66868 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Disappearing text
Hi Ronny, Where the problem lies will likely be how you are managing the viewer as well as the graphics context. My hunch is that you've created the problem with your "custom" means of managing things. If you can try running your application with a straight osgViewer::Viewer with it creating a single window for you rather than hand wiring things yourself, even if this doesn't give you exactly what you want for your final application it will at least give you a sanity test to compare results against. If this works then you know that the issue stems from your won custom set up. While it possible to hand wire things up it's more complicated with more options for screwing things up if your don't know how all the various elements fully work together. Robert. On 18 April 2016 at 16:30, Ronny Hattelandwrote: > > > That should not be needed at all, and indicative that something > somewhere in your application or it's usage of the OSG is messing up the GL > object management. > > > > > > The resizeGLObjbectBuffer() is only needed when graphics context are > created or destroyed. > > > > > > > > As to what is going wrong your case I can't say - something *very* odd > is happening. Are you creating your own graphics context / modifying the > viewer? > > > > > > Robert. > > > Yes I am creating my own GraphicsContext: > > Code: > // Local Variable to hold window size data > RECT rect; > > // Get the current window size > ::GetWindowRect(m_hWnd, ); > > // Init the GraphicsContext Traits > osg::ref_ptr traits = new > osg::GraphicsContext::Traits; > > // Init the Windata Variable that holds the handle for the Window to > display OSG in. > osg::ref_ptr windata = new > osgViewer::GraphicsWindowWin32::WindowData(m_hWnd); > > // Setup the traits parameters > traits->x = 0; > traits->y = 0; > traits->width = (rect.right - rect.left); > traits->height = ( rect.bottom - rect.top); > > traits->windowDecoration = true; // CHECK DIFFERENCE > traits->doubleBuffer = false; > traits->setInheritedWindowPixelFormat = true; > traits->inheritedWindowData = windata; > traits->samples = samples; > traits->vsync = false; > GraphicsContext* gc = > osg::GraphicsContext::createGraphicsContext(traits.get()); > traits->x = 0; > traits->y = 0; > return gc; > > > which afterwards is used as follows: > > > Code: > m_defaultGraphicsContext->clear(); > > m_defaultGraphicsContext->setName("DefaultViewGraphicsContext"); > m_defaultGraphicsContext->getState()->setUseModelViewAndProjectionUniforms(true); > //ADDED FOR SHADER > m_defaultGraphicsContext->getState()->setUseVertexAttributeAliasing(true); > > if (m_defaultGraphicsContext->valid()) > { > defaultCamera = mViewer->getCamera(); > defaultCamera->setCullMask(0x04); > defaultCamera->getOrCreateStateSet()->setMode(GL_LIGHTING, > osg::StateAttribute::OFF ); > > defaultCamera->getOrCreateStateSet()->setMode(osg::StateAttribute::SCISSOR > , osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); > > defaultCamera->getOrCreateStateSet()->removeAttribute(osg::StateAttribute::MATERIAL); > defaultCamera->getView()->setLightingMode(osg::View::NO_LIGHT); > defaultCamera->setGraphicsContext(m_defaultGraphicsContext); > defaultCamera->setViewport(new > osg::Viewport(m_defaultGraphicsContext->getTraits()->x, > m_defaultGraphicsContext->getTraits()->y, > m_defaultGraphicsContext->getTraits()->width, > m_defaultGraphicsContext->getTraits()->height)); > } > > double fovy, aspectRatio; > > mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, > defaultCameraNear, defaultCameraFar); > aspectRatio = double(m_defaultGraphicsContext->getTraits()->width) / > double(m_defaultGraphicsContext->getTraits()->height); > mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio, > 0.01f, defaultCameraFar); > > initOpenGL(m_defaultGraphicsContext, maxNumUniforms, maxUniformBlockSize); > > > > > Code: > > void initOpenGL(osg::ref_ptr context, GLint& > maxNumUniforms, GLint& maxUniformBlockSize) { > context->realize(); > context->makeCurrent(); > maxNumUniforms = 0; > glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, ); > maxUniformBlockSize = 0; > glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, ); > > // init glew > ///glewExperimental = GL_TRUE; > /// if (GLEW_ARB_vertex_buffer_object == FALSE || > GLEW_ARB_vertex_array_object == FALSE) return; > #ifdef USE_INSTANCED_DRAWING > glewInit(); > #endif > context->releaseContext(); > > // ATI driver 11.6 didn't return right number of uniforms which > lead to a crash, when the vertex shader was compiled(WTF?!) > #ifdef ATI_FIX > maxNumUniforms = 576; > maxUniformBlockSize = 16384; > #endif > } > > > > Maybe you can spot something that is clearly wrong here, otherwise it > could be related to the glewInit()? > > -- > Read this topic
Re: [osg-users] Disappearing text
> That should not be needed at all, and indicative that something somewhere in > your application or it's usage of the OSG is messing up the GL object > management. > > > The resizeGLObjbectBuffer() is only needed when graphics context are created > or destroyed. > > > > As to what is going wrong your case I can't say - something *very* odd is > happening. Are you creating your own graphics context / modifying the viewer? > > > Robert. Yes I am creating my own GraphicsContext: Code: // Local Variable to hold window size data RECT rect; // Get the current window size ::GetWindowRect(m_hWnd, ); // Init the GraphicsContext Traits osg::ref_ptr traits = new osg::GraphicsContext::Traits; // Init the Windata Variable that holds the handle for the Window to display OSG in. osg::ref_ptr windata = new osgViewer::GraphicsWindowWin32::WindowData(m_hWnd); // Setup the traits parameters traits->x = 0; traits->y = 0; traits->width = (rect.right - rect.left); traits->height = ( rect.bottom - rect.top); traits->windowDecoration = true; // CHECK DIFFERENCE traits->doubleBuffer = false; traits->setInheritedWindowPixelFormat = true; traits->inheritedWindowData = windata; traits->samples = samples; traits->vsync = false; GraphicsContext* gc = osg::GraphicsContext::createGraphicsContext(traits.get()); traits->x = 0; traits->y = 0; return gc; which afterwards is used as follows: Code: m_defaultGraphicsContext->clear(); m_defaultGraphicsContext->setName("DefaultViewGraphicsContext"); m_defaultGraphicsContext->getState()->setUseModelViewAndProjectionUniforms(true); //ADDED FOR SHADER m_defaultGraphicsContext->getState()->setUseVertexAttributeAliasing(true); if (m_defaultGraphicsContext->valid()) { defaultCamera = mViewer->getCamera(); defaultCamera->setCullMask(0x04); defaultCamera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF ); defaultCamera->getOrCreateStateSet()->setMode(osg::StateAttribute::SCISSOR , osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); defaultCamera->getOrCreateStateSet()->removeAttribute(osg::StateAttribute::MATERIAL); defaultCamera->getView()->setLightingMode(osg::View::NO_LIGHT); defaultCamera->setGraphicsContext(m_defaultGraphicsContext); defaultCamera->setViewport(new osg::Viewport(m_defaultGraphicsContext->getTraits()->x, m_defaultGraphicsContext->getTraits()->y, m_defaultGraphicsContext->getTraits()->width, m_defaultGraphicsContext->getTraits()->height)); } double fovy, aspectRatio; mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, defaultCameraNear, defaultCameraFar); aspectRatio = double(m_defaultGraphicsContext->getTraits()->width) / double(m_defaultGraphicsContext->getTraits()->height); mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio, 0.01f, defaultCameraFar); initOpenGL(m_defaultGraphicsContext, maxNumUniforms, maxUniformBlockSize); Code: void initOpenGL(osg::ref_ptr context, GLint& maxNumUniforms, GLint& maxUniformBlockSize) { context->realize(); context->makeCurrent(); maxNumUniforms = 0; glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, ); maxUniformBlockSize = 0; glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, ); // init glew ///glewExperimental = GL_TRUE; /// if (GLEW_ARB_vertex_buffer_object == FALSE || GLEW_ARB_vertex_array_object == FALSE) return; #ifdef USE_INSTANCED_DRAWING glewInit(); #endif context->releaseContext(); // ATI driver 11.6 didn't return right number of uniforms which lead to a crash, when the vertex shader was compiled(WTF?!) #ifdef ATI_FIX maxNumUniforms = 576; maxUniformBlockSize = 16384; #endif } Maybe you can spot something that is clearly wrong here, otherwise it could be related to the glewInit()? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66864#66864 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Disappearing text
Hi Ronny, On 18 April 2016 at 15:29, Ronny Hattelandwrote: > The issue was fixed using the following after every ->setText(): > > > Code: > > mViewer->getSceneData()->resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); > > > which is called inside of setSceneData(). However, this obviously has a > huge performance impact and I cannot do this on mouse move. Any suggestions? > That should not be needed at all, and indicative that something somewhere in your application or it's usage of the OSG is messing up the GL object management. The resizeGLObjbectBuffer() is only needed when graphics context are created or destroyed. As to what is going wrong your case I can't say - something *very* odd is happening. Are you creating your own graphics context / modifying the viewer? Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Disappearing text
The issue was fixed using the following after every ->setText(): Code: mViewer->getSceneData()->resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); which is called inside of setSceneData(). However, this obviously has a huge performance impact and I cannot do this on mouse move. Any suggestions? Thank you! Cheers, Ronny -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66862#66862 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Disappearing text
Hi Ronny, Without seeing the artificats first hand is not possible to know what is going on. The best I can suggest is that you look at the near/far planes of the scene, could it be that the near/far planes are clipping the text? Also look at the possibility of state leaking into the text for some reason. Do you have custom OpenGL code? Finally, which OSG version are you using? The latest OSG version will likely have the most bug fixes so there is small chance that this might address issues. Robert. On 17 April 2016 at 17:58, Ronny Hattelandwrote: > Hi, > > By coincidence I made some progress to an issue that has been bugging me > for two years, where the osgText disappears in a certain case. I am using > VBO hardware instancing for another object, and when only the text and the > VBO hardware instanced objects are visible (using a Switch node), the text > disappears. > > Previously, I though it was related to the bounding box of the VBO > instances, as the text would appear again if other objects were shown at > the same time. However, today I noticed that when the text was not updated > on cursor move, the original text that was set on the creation of the > osgText::Text object would be visible as expected. > > The text is updated using txtObject->SetText(text) with the cursor > position on a grid on the xz plane, with a text looking like this "(%d, > %d)". Below is the code for the initialization of the text objects: > > > Code: > > txtSelectedCell = new osgText::Text; > txtSelectedCell->setDataVariance(Object::DYNAMIC); > txtSelectedCell->setFont(consolasBold); > txtSelectedCell->setFontResolution(128, 128); > txtSelectedCell->setCharacterSizeMode(osgText::TextBase::OBJECT_COORDS); > txtSelectedCell->setLineSpacing(0.10f); > txtSelectedCell->setPosition(osg::Vec3(0.0, /*-0.001*/0.0, 0.0)); > txtSelectedCell->setCharacterSize(0.0015f); > txtSelectedCell->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); > txtSelectedCell->setBackdropType(osgText::Text::OUTLINE); > txtSelectedCell->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); > txtSelectedCell->setBackdropOffset(0.10f, 0.10f); > txtSelectedCell->setAxisAlignment(osgText::Text::XZ_PLANE); > txtSelectedCell->setAlignment(osgText::Text::CENTER_CENTER); > txtSelectedCell->setText("(X,Y)"); > > ref_ptr infoCellText = new osg::Geode; > infoCellText->setDataVariance(Object::DYNAMIC); > infoCellText->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, > osg::StateAttribute::OFF); > infoCellText->getOrCreateStateSet()->setMode(GL_LIGHTING, > osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); > infoCellText->getOrCreateStateSet()->setMode(GL_BLEND, > osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); > infoCellText->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, > osg::StateAttribute::OFF); > text_program = LoadShaderProgram("textMaterial.vert", > "textMaterial.frag");; > infoCellText->getOrCreateStateSet()->setAttributeAndModes(text_program.get(), > osg::StateAttribute::ON); > osgUtil::GLObjectsVisitor > glov(osgUtil::GLObjectsVisitor::TRAVERSE_ALL_CHILDREN | > osgUtil::GLObjectsVisitor::SWITCH_OFF_DISPLAY_LISTS | > osgUtil::GLObjectsVisitor::SWITCH_ON_VERTEX_BUFFER_OBJECTS); > ref_ptr state = new osg::State(); glov.setState(state); > infoCellText.get()->accept(glov); > infoCellText->setCullingActive(false); > infoCellText->addDrawable(txtSelectedCell.get()); > ref_ptr mtSelectedCell->addChild(infoCellText); // > Updated on mouse move > > > > > Exploring this further, I created a new text object each time position on > the grid was updated, that I added to the infoCellText geode. This would > work only if I did not remove the original txtSelectedCell child. However, > it would not work if txtSelectedCell->SetText was initialized to "" instead > of "(X,Y)". If the txtSelectedCell text was changed with setText at the > same time as a new osgText was added to the infoCellText geode, the text > would not show. > > I suspect this has something to do with the bounding box of the text, > however, I am not entirely sure if it is related to the osgText::Text > object or the Geode with the text as a child. I tried to call > computeBound() on txtSelectedCell as well as infoCellText after updating > the text with setText(), but without any luck. In many cases when the text > is not displayed I get weird artifacts with planes cutting through the > view. Any suggestions would be extremely appreciated. > > Thank you! > > Cheers, > Ronny > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=66845#66845 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Disappearing text
Hi, By coincidence I made some progress to an issue that has been bugging me for two years, where the osgText disappears in a certain case. I am using VBO hardware instancing for another object, and when only the text and the VBO hardware instanced objects are visible (using a Switch node), the text disappears. Previously, I though it was related to the bounding box of the VBO instances, as the text would appear again if other objects were shown at the same time. However, today I noticed that when the text was not updated on cursor move, the original text that was set on the creation of the osgText::Text object would be visible as expected. The text is updated using txtObject->SetText(text) with the cursor position on a grid on the xz plane, with a text looking like this "(%d, %d)". Below is the code for the initialization of the text objects: Code: txtSelectedCell = new osgText::Text; txtSelectedCell->setDataVariance(Object::DYNAMIC); txtSelectedCell->setFont(consolasBold); txtSelectedCell->setFontResolution(128, 128); txtSelectedCell->setCharacterSizeMode(osgText::TextBase::OBJECT_COORDS); txtSelectedCell->setLineSpacing(0.10f); txtSelectedCell->setPosition(osg::Vec3(0.0, /*-0.001*/0.0, 0.0)); txtSelectedCell->setCharacterSize(0.0015f); txtSelectedCell->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); txtSelectedCell->setBackdropType(osgText::Text::OUTLINE); txtSelectedCell->setBackdropColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); txtSelectedCell->setBackdropOffset(0.10f, 0.10f); txtSelectedCell->setAxisAlignment(osgText::Text::XZ_PLANE); txtSelectedCell->setAlignment(osgText::Text::CENTER_CENTER); txtSelectedCell->setText("(X,Y)"); ref_ptr infoCellText = new osg::Geode; infoCellText->setDataVariance(Object::DYNAMIC); infoCellText->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); infoCellText->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); infoCellText->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); infoCellText->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); text_program = LoadShaderProgram("textMaterial.vert", "textMaterial.frag");; infoCellText->getOrCreateStateSet()->setAttributeAndModes(text_program.get(), osg::StateAttribute::ON); osgUtil::GLObjectsVisitor glov(osgUtil::GLObjectsVisitor::TRAVERSE_ALL_CHILDREN | osgUtil::GLObjectsVisitor::SWITCH_OFF_DISPLAY_LISTS | osgUtil::GLObjectsVisitor::SWITCH_ON_VERTEX_BUFFER_OBJECTS); ref_ptr state = new osg::State(); glov.setState(state); infoCellText.get()->accept(glov); infoCellText->setCullingActive(false); infoCellText->addDrawable(txtSelectedCell.get()); ref_ptr mtSelectedCell->addChild(infoCellText); // Updated on mouse move Exploring this further, I created a new text object each time position on the grid was updated, that I added to the infoCellText geode. This would work only if I did not remove the original txtSelectedCell child. However, it would not work if txtSelectedCell->SetText was initialized to "" instead of "(X,Y)". If the txtSelectedCell text was changed with setText at the same time as a new osgText was added to the infoCellText geode, the text would not show. I suspect this has something to do with the bounding box of the text, however, I am not entirely sure if it is related to the osgText::Text object or the Geode with the text as a child. I tried to call computeBound() on txtSelectedCell as well as infoCellText after updating the text with setText(), but without any luck. In many cases when the text is not displayed I get weird artifacts with planes cutting through the view. Any suggestions would be extremely appreciated. Thank you! Cheers, Ronny -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66845#66845 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Disappearing Text
Hi, with Code: osg::ref_ptrosgText::Text label = new osgText::Text(); osg::ref_ptrosg::Geode labelGeode = new osg::Geode(); labelGeode-setName(TEXT_TOP); labelGeode-addDrawable(label.get()); label-setCharacterSize(1.3); label-setFont(arial.ttf); label-setText(fileName); label-setAxisAlignment(osgText::Text::XY_PLANE); label-setDrawMode(osgText::Text::TEXT); label-setAlignment(osgText::Text::CENTER_TOP); label-setPosition( osg::Vec3(0.0f, 0.5f,6.05f) ); label-setColor(_textColorTop); shapeGroup-addChild(labelGeode.get()); i write text on a geode. But when the geode is ovelayed with a transparent geode the text disappears. Code: osg::ref_ptrosg::Material shapeMaterial = new osg::Material; //rote Einfärbung shapeMaterial-setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); shapeMaterial-setTransparency(osg::Material::FRONT_AND_BACK, 0.8f); osg::ref_ptrosg::StateSet stateSet = new osg::StateSet(); stateSet-setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON ); stateSet-setAttribute(shapeMaterial.get(), osg::StateAttribute::OVERRIDE); stateSet-setRenderingHint(osg::StateSet::TRANSPARENT_BIN); shapeGeodeRZ-setStateSet(stateSet.get()); How can i stop the text from disappearing? Thank you! Cheers, Andrew -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35545#35545 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org