OCC22354 Bug in Overlay Text rendering
authorAPL <>
Thu, 28 Apr 2011 15:56:08 +0000 (15:56 +0000)
committerbugmaster <bugmaster@opencascade.com>
Mon, 5 Mar 2012 15:28:19 +0000 (19:28 +0400)
src/OpenGl/OpenGl_FontMgr.cxx
src/OpenGl/OpenGl_FontMgr.hxx
src/OpenGl/OpenGl_TextRender.cxx
src/OpenGl/OpenGl_togl_begin_layer_mode.cxx

index a422e90..641f435 100755 (executable)
@@ -310,7 +310,8 @@ int OpenGl_FontMgr::request_font( const Handle(TCollection_HAsciiString)& fontNa
   return -1;
 }
 
   return -1;
 }
 
-void OpenGl_FontMgr::render_text( const Standard_Integer id, const char* text)
+void OpenGl_FontMgr::render_text( const Standard_Integer id, const char* text,
+                                 const Standard_Boolean is2d )
 {
 #ifdef TRACE
   cout << "TKOpenGl::render_text\n"
 {
 #ifdef TRACE
   cout << "TKOpenGl::render_text\n"
@@ -329,8 +330,13 @@ void OpenGl_FontMgr::render_text( const Standard_Integer id, const char* text)
 
     if( !enableTexture )
       glEnable(GL_TEXTURE_2D);
 
     if( !enableTexture )
       glEnable(GL_TEXTURE_2D);
-    if( !enableDepthTest )
-      glEnable(GL_DEPTH_TEST);
+    if ( !is2d ) {
+      if ( !enableDepthTest )
+        glEnable(GL_DEPTH_TEST);
+    } 
+    else if ( enableDepthTest ) {
+        glDisable(GL_DEPTH_TEST);
+    }
 
     GLint* param = new GLint;    
     glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
 
     GLint* param = new GLint;    
     glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
@@ -357,8 +363,8 @@ void OpenGl_FontMgr::render_text( const Standard_Integer id, const char* text)
 
 }
 
 
 }
 
-void OpenGl_FontMgr::render_text( const char* text){
-  render_text( _CurrentFontId, text );
+void OpenGl_FontMgr::render_text( const char* text, const Standard_Boolean is2d ){
+  render_text( _CurrentFontId, text, is2d );
 }
 
 
 }
 
 
@@ -371,7 +377,6 @@ Standard_ShortReal OpenGl_FontMgr::computeWidth( const Standard_Integer id, cons
     return 0.f;
 
   OGLFont_Cache cache = _FontCache.Find( id );
     return 0.f;
 
   OGLFont_Cache cache = _FontCache.Find( id );
-  GLenum err = glGetError();
 
   Standard_ShortReal w = cache.Font->Advance( str );
 
 
   Standard_ShortReal w = cache.Font->Advance( str );
 
index d32b109..073a78b 100755 (executable)
@@ -28,10 +28,11 @@ public:
     const Standard_Integer                 fontHeight );
 
   void render_text( const Standard_Integer id,
     const Standard_Integer                 fontHeight );
 
   void render_text( const Standard_Integer id,
-    const char* text );
+    const char* text,
+    const Standard_Boolean is2d = 0 );
 
   //render text by last requested font
 
   //render text by last requested font
-  void render_text( const char* text );
+  void render_text( const char* text, const Standard_Boolean is2d = 0 );
 
   //returns direct access to FTGL font
   //Warning: don't change font pointer.
 
   //returns direct access to FTGL font
   //Warning: don't change font pointer.
index d25d4de..af90722 100755 (executable)
@@ -269,6 +269,8 @@ void OpenGl_TextRender::RenderText ( char* str, GLuint base, int is2d, GLfloat x
   GLdouble xdis = 0., ydis = 0.;
   GLint renderMode;  
 
   GLdouble xdis = 0., ydis = 0.;
   GLint renderMode;  
 
+  // FTFont changes texture state when it renders and computes size for the text
+  glPushAttrib(GL_TEXTURE_BIT);
   StringSize(str, &widthFont, &ascentFont, &descentFont );
 
   GLdouble identityMatrix[4][4] = 
   StringSize(str, &widthFont, &ascentFont, &descentFont );
 
   GLdouble identityMatrix[4][4] = 
@@ -298,6 +300,12 @@ void OpenGl_TextRender::RenderText ( char* str, GLuint base, int is2d, GLfloat x
   TsmGetAttri( 1, &keyZoom );
   zoom = keyZoom.data.ldata;
 
   TsmGetAttri( 1, &keyZoom );
   zoom = keyZoom.data.ldata;
 
+  CMN_KEY keyfontName;
+  keyfontName.id = TelTextFont;//This flag responding about TextFontName
+  TsmGetAttri( 1, &keyfontName );
+  char *fontName = new char[strlen((char*)keyfontName.data.pdata) + 1];
+  strcpy(fontName,(char*)keyfontName.data.pdata);
+
   OpenGl_TextRender* textRender = OpenGl_TextRender::instance(); 
   int vh = 2 ;
   int vv = 2 ;
   OpenGl_TextRender* textRender = OpenGl_TextRender::instance(); 
   int vh = 2 ;
   int vv = 2 ;
@@ -335,8 +343,10 @@ void OpenGl_TextRender::RenderText ( char* str, GLuint base, int is2d, GLfloat x
   OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance();
 
   const FTFont* fnt = mgr->fontById( curFont );
   OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance();
 
   const FTFont* fnt = mgr->fontById( curFont );
-  if ( !fnt )
+  if ( !fnt ) {
+    glPopAttrib();
     return; 
     return; 
+  }
 
   float export_h = 1.;
 
 
   float export_h = 1.;
 
@@ -392,24 +402,19 @@ void OpenGl_TextRender::RenderText ( char* str, GLuint base, int is2d, GLfloat x
   if ( renderMode == GL_FEEDBACK ) 
   {
 #ifdef HAVE_GL2PS
   if ( renderMode == GL_FEEDBACK ) 
   {
 #ifdef HAVE_GL2PS
-    CMN_KEY keyfontName;
-    keyfontName.id = TelTextFont;//This flag responding about TextFontName
-    TsmGetAttri( 1, &keyfontName );
-    char *fontName = new char[strlen((char*)keyfontName.data.pdata) + 1];
-    strcpy(fontName,(char*)keyfontName.data.pdata);
-
     export_h = (GLdouble)fnt->FaceSize() / export_h;
     int aligment = alignmentforgl2ps( vh, vv );
     glPopMatrix();
     ExportText( str, fontName, export_h, angle, aligment, x, y, z, is2d!=0 );
     export_h = (GLdouble)fnt->FaceSize() / export_h;
     int aligment = alignmentforgl2ps( vh, vv );
     glPopMatrix();
     ExportText( str, fontName, export_h, angle, aligment, x, y, z, is2d!=0 );
-    delete [] fontName;
 #endif
   }
   else
   {
 #endif
   }
   else
   {
-    mgr->render_text( curFont, str );
+    mgr->render_text( curFont, str, is2d );
     glPopMatrix();
   }
     glPopMatrix();
   }
+  glPopAttrib();
+  delete [] fontName;
   return;
 
 }
   return;
 
 }
index ae5d082..438b2e9 100755 (executable)
@@ -336,7 +336,7 @@ call_togl_redraw_layer2d (
 #endif
   glPushAttrib (
     GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT |
 #endif
   glPushAttrib (
     GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT |
-    GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT);
+    GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT );
   glDisable (GL_DEPTH_TEST);
   glCallList (alayer->ptrLayer->listIndex);
 
   glDisable (GL_DEPTH_TEST);
   glCallList (alayer->ptrLayer->listIndex);