<div dir="ltr"><div class="gmail_extra">Dear All</div><div class="gmail_extra"><br></div><div class="gmail_extra">I am trying to display a simple text on Android device using osgText. No matter what I  do I can't get to display the text out on the screen.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I am using GLES2 build.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Attached is the code. I have debugged and verified that the font is loaded. The text would just not appear.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">In the following function i create some 2D text and add that to the scenegraph. text <- _overlayGeode <- _overlayCamera <- _rootNode.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">namespace</div><div class="gmail_extra">{</div><div class="gmail_extra"><br></div><div class="gmail_extra">static const char gTextVertexShader[] =</div><div class="gmail_extra"><span class="" style="white-space:pre">   </span>"varying vec4 VertexColor;<span class="" style="white-space:pre">                                                                                                           </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"varying mediump vec2 TexCoord0;<span class="" style="white-space:pre">                                                                                             </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"uniform vec4 MaterialColor;<span class="" style="white-space:pre">                                                                                                 </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"void main()<span class="" style="white-space:pre">                                                                                                                         </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"{<span class="" style="white-space:pre">                                                                                                                                           </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">             </span>"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;<span class="" style="white-space:pre">                                                     </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">             </span>"VertexColor = MaterialColor;<span class="" style="white-space:pre">                                                                                                </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">             </span>"TexCoord0 = gl_MultiTexCoord0.xy;<span class="" style="white-space:pre">                                                                                   </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"}<span class="" style="white-space:pre">                                                                                                                                           </span>\n";</div><div class="gmail_extra"><br></div><div class="gmail_extra">static const char gTextFragmentShader[] =</div><div class="gmail_extra"><span class="" style="white-space:pre">       </span>"varying vec4 VertexColor;<span class="" style="white-space:pre">                                                                                                           </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"varying mediump vec2 TexCoord0;<span class="" style="white-space:pre">                                                                                             </span>\n"</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>"uniform sampler2D GlyphTexture;<span class="" style="white-space:pre">                                                                                             </span>\n"</div><div class="gmail_extra">    "void main() {                             <span class="" style="white-space:pre">                                                                                                 </span>\n"</div><div class="gmail_extra">    "<span class="" style="white-space:pre"> </span>gl_FragColor = texture2D(GlyphTexture,TexCoord0);<span class="" style="white-space:pre">                                                                 </span>\n"</div><div class="gmail_extra">    "}                                         <span class="" style="white-space:pre">                                                                                                           </span>\n";</div><div class="gmail_extra">} // end of unnamed namespace</div><div class="gmail_extra"><br></div></div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">void TerrainApp::initTextOverlays()</div><div class="gmail_extra">{</div><div class="gmail_extra">    _overlayCamera = new osg::Camera;</div><div class="gmail_extra">    _rootNode->addChild(_overlayCamera.get());</div><div class="gmail_extra"><br></div><div class="gmail_extra">    _overlayCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);</div><div class="gmail_extra">    _overlayCamera->setProjectionMatrixAsOrtho2D(</div><div class="gmail_extra">    <span class="" style="white-space:pre">               </span>0, vfui::Global::instance()->getTrueWidth(),</div><div class="gmail_extra">    <span class="" style="white-space:pre">                </span>0, vfui::Global::instance()->getTrueHeight()</div><div class="gmail_extra"><span class="" style="white-space:pre">              </span>);</div><div class="gmail_extra"><br></div><div class="gmail_extra">    _overlayCamera->setViewMatrix(osg::Matrix::identity());</div><div class="gmail_extra">    _overlayCamera->setClearMask(GL_DEPTH_BUFFER_BIT);</div><div class="gmail_extra">    _overlayCamera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);</div><div class="gmail_extra">    _overlayCamera->setCullingActive(false);</div><div class="gmail_extra">    _overlayCamera->getOrCreateStateSet()->setAttribute(new osg::Depth(osg::Depth::LESS, 0.0f, .0001f));</div><div class="gmail_extra"><br></div><div class="gmail_extra">    _overlayGeode = new osg::Geode;</div><div class="gmail_extra">    _overlayCamera->addChild(_overlayGeode.get());</div><div class="gmail_extra"><br></div><div class="gmail_extra">    osg::Shader * vshader = new osg::Shader(osg::Shader::VERTEX, gTextVertexShader );</div><div class="gmail_extra">    osg::Shader * fshader = new osg::Shader(osg::Shader::FRAGMENT, gTextFragmentShader );</div><div class="gmail_extra"><br></div><div class="gmail_extra">    osg::Program * prog = new osg::Program;</div><div class="gmail_extra">    prog->addShader ( vshader );</div><div class="gmail_extra">    prog->addShader ( fshader );</div><div class="gmail_extra"><br></div><div class="gmail_extra">    osg::ref_ptr<osg::Uniform> textColor = new osg::Uniform("MaterialColor",osg::Vec4(0,1,1,1));</div><div class="gmail_extra">    osg::ref_ptr<osg::Uniform> textTexture = new osg::Uniform("GlyphTexture",0);</div><div class="gmail_extra"><br></div><div class="gmail_extra">    //set a sample text overlay.</div><div class="gmail_extra"><span class="" style="white-space:pre">      </span>osg::ref_ptr<osgText::Text> text = TerrainApp::s_createText(osgText::String("Testing"), _datapath);</div><div class="gmail_extra"><br></div><div class="gmail_extra">    osg::StateSet *ss = text->getOrCreateStateSet();</div><div class="gmail_extra">    ss->addUniform(textColor);</div><div class="gmail_extra">    ss->addUniform(textTexture);</div><div class="gmail_extra">    ss->setAttributeAndModes(prog, osg::StateAttribute::ON);</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">      </span>_overlayGeode->addDrawable(text.get());</div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">osgText::Text* TerrainApp::s_createText(const osgText::String& str, const std::string& datapath)</div><div class="gmail_extra">{</div><div class="gmail_extra"><span class="" style="white-space:pre">  </span>// text geometry</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>std::string textStr("Hello World"); // replace this with str.</div><div class="gmail_extra"><span class="" style="white-space:pre">      </span>osgText::Text* myText = new osgText::Text;</div><div class="gmail_extra"><br></div><div class="gmail_extra">        std::string font_filename = datapath + "/fonts/androidnation.ttf";</div><div class="gmail_extra">        osgText::Font* font = osgText::readFontFile(font_filename);</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">    </span>myText->setFont(font);</div><div class="gmail_extra"><span class="" style="white-space:pre">    </span>myText->setCharacterSize(100.0f);</div><div class="gmail_extra"><span class="" style="white-space:pre"> </span>myText->setText(textStr);</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class="" style="white-space:pre">  </span>myText->setPosition(osg::Vec3(500.0f, 500.0f, 0.0f));</div><div class="gmail_extra"><span class="" style="white-space:pre">     </span>return myText;</div><div class="gmail_extra"><br></div><div class="gmail_extra">}</div><div class="gmail_extra"><br></div><div class="gmail_extra">Any thing that I have done that is not correct? I am cracking my head. I  found a couple of  examples / tutorials of osgText on Android using GLES2. All of them dont seem to work. By right setting up text should be very simple. Any help or advice will be greatly appreciated.</div><div class="gmail_extra"><br></div><div class="gmail_extra">regards</div><div class="gmail_extra">Shamim</div></div></div></div></div>