diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index 5bc4d485c..03105f60e 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -235,12 +235,14 @@ void setScene(osg::Group* rootNode) geode->setName("BitmapFont"); geode->addDrawable( text ); -// textMaterial = new osg::Material(); -// textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); -// textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK,TEXT_COL_3D); -// textState = new osg::StateSet(); -// textState->setAttribute(textMaterial ); -// geode->setStateSet( textState ); +/* + osg::Material* textMaterial = new osg::Material(); + textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); + textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK,TEXT_COL_3D); + textState = new osg::StateSet(); + textState->setAttribute(textMaterial ); + geode->setStateSet( textState ); +*/ rootNode->addChild(geode); @@ -309,7 +311,8 @@ void setScene(osg::Group* rootNode) // textState->setAttribute(textMaterial ); textState->setAttribute(transp); - // textState->setMode(GL_BLEND,osg::StateAttribute::ON); + textState->setMode(GL_BLEND,osg::StateAttribute::ON); + textState->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::ON); textState->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); geode->setStateSet( textState ); @@ -463,57 +466,61 @@ protected: } - virtual void keyboard(int key, int x, int y) + virtual void keyboard(int key, int x, int y, bool keydown) { - switch(key) + if (keydown) { - case '1': - { // change DrawMode - std::vector >::iterator itr=gTextList.begin(); - for(;itr!=gTextList.end();itr++) - (*itr)->setDrawMode(osgText::Text::TEXT ^ (*itr)->getDrawMode()); - } - return; - case '2': - { // change DrawMode - std::vector >::iterator itr=gTextList.begin(); - for(;itr!=gTextList.end();itr++) - (*itr)->setDrawMode(osgText::Text::BOUNDINGBOX ^ (*itr)->getDrawMode()); - } - return; - case '3': - { // change DrawMode - std::vector >::iterator itr=gTextList.begin(); - for(;itr!=gTextList.end();itr++) - (*itr)->setDrawMode(osgText::Text::ALIGNMENT ^ (*itr)->getDrawMode()); - } - return; - /////////////////////////////////////////////////////////////////// - case '4': - { // change BoundingBoxType to GEOMETRY - std::vector >::iterator itr=gTextList.begin(); - osgText::Text::BoundingBoxType type=(*itr)->getBoundingBox()==osgText::Text::GLYPH ? - osgText::Text::GEOMETRY : - osgText::Text::GLYPH; - for(;itr!=gTextList.end();itr++) - (*itr)->setBoundingBox(type); - } - return; - /////////////////////////////////////////////////////////////////// - case '5': - { // change the textAlignment - gAlignment=(osgText::Text::AlignmentType)((int)gAlignment+1); - if(gAlignment>osgText::Text::RIGHT_BOTTOM) - gAlignment=osgText::Text::LEFT_TOP; + switch(key) + { + case '1': + { // change DrawMode + std::vector >::iterator itr=gTextList.begin(); + for(;itr!=gTextList.end();itr++) + (*itr)->setDrawMode(osgText::Text::TEXT ^ (*itr)->getDrawMode()); + } + return; + case '2': + { // change DrawMode + std::vector >::iterator itr=gTextList.begin(); + for(;itr!=gTextList.end();itr++) + (*itr)->setDrawMode(osgText::Text::BOUNDINGBOX ^ (*itr)->getDrawMode()); + } + return; + case '3': + { // change DrawMode + std::vector >::iterator itr=gTextList.begin(); + for(;itr!=gTextList.end();itr++) + (*itr)->setDrawMode(osgText::Text::ALIGNMENT ^ (*itr)->getDrawMode()); + } + return; + /////////////////////////////////////////////////////////////////// + case '4': + { // change BoundingBoxType to GEOMETRY + std::vector >::iterator itr=gTextList.begin(); + osgText::Text::BoundingBoxType type=(*itr)->getBoundingBox()==osgText::Text::GLYPH ? + osgText::Text::GEOMETRY : + osgText::Text::GLYPH; + for(;itr!=gTextList.end();itr++) + (*itr)->setBoundingBox(type); + } + return; + /////////////////////////////////////////////////////////////////// + case '5': + { // change the textAlignment + gAlignment=(osgText::Text::AlignmentType)((int)gAlignment+1); + if(gAlignment>osgText::Text::RIGHT_BOTTOM) + gAlignment=osgText::Text::LEFT_TOP; - std::vector >::iterator itr=gTextList.begin(); - for(;itr!=gTextList.end();itr++) - (*itr)->setAlignment(gAlignment); - } - return; - default: - Viewer::keyboard(key,x,y); - }; + std::vector >::iterator itr=gTextList.begin(); + for(;itr!=gTextList.end();itr++) + (*itr)->setAlignment(gAlignment); + } + return; + default: + break; + } + } + Viewer::keyboard(key,x,y,keydown); } }; diff --git a/src/osgText/FTGLBitmapFont.cpp b/src/osgText/FTGLBitmapFont.cpp index 886ccf9c0..c808a09f3 100644 --- a/src/osgText/FTGLBitmapFont.cpp +++ b/src/osgText/FTGLBitmapFont.cpp @@ -65,10 +65,33 @@ void FTGLBitmapFont::render( const wchar_t* string,unsigned int renderContext) glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei( GL_UNPACK_ROW_LENGTH, 0); +#if (FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR>=1) + glPixelStorei( GL_UNPACK_ALIGNMENT, 2); +#else glPixelStorei( GL_UNPACK_ALIGNMENT, 1); +#endif FTFont::render( string,renderContext); glPopClientAttrib(); - +} + +// mrn@changes +void FTGLBitmapFont::render( std::vector::const_iterator first, + std::vector::const_iterator last, + unsigned int renderContext) +{ + glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT); + + glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE); + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0); +#if (FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR>=1) + glPixelStorei( GL_UNPACK_ALIGNMENT, 2); +#else + glPixelStorei( GL_UNPACK_ALIGNMENT, 1); +#endif + + FTFont::render( first,last,renderContext); + + glPopClientAttrib(); } diff --git a/src/osgText/FTGLBitmapFont.h b/src/osgText/FTGLBitmapFont.h index b7f6c6790..d12f76286 100644 --- a/src/osgText/FTGLBitmapFont.h +++ b/src/osgText/FTGLBitmapFont.h @@ -43,6 +43,15 @@ class FTGL_EXPORT FTGLBitmapFont : public FTFont // mrn@changes void render( const wchar_t* string, unsigned int renderContext=0); + /** + * Renders a string of characters + * + * @param string unicode string to be output. + */ + // mrn@changes + void render( std::vector::const_iterator first, + std::vector::const_iterator last, + unsigned int renderContext=0); // attributes private: