Changeset 18550

Show
Ignore:
Timestamp:
04/12/06 09:01:57 (3 years ago)
Author:
patrick
Message:

MFT [rev 18368]:

  • Added method to Text for drawing full text block
  • Fixed bug where text only worked in first context (needed to use gl
    context data)
  • Updated perf class to use new interface and to work in multiple
    contexts.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.0/modules/vrjuggler/test/Draw/OGL/perfAddon/PerfProbe.cpp

    r17820 r18550  
    4646 
    4747#include <vrj/Kernel/Kernel.h> 
     48#include <vpr/Util/Debug.h> 
    4849 
    4950//#include <boost/format.hpp> 
    5051 
    51 namespace 
    52 { 
    53    template<class OutIt> 
    54    void splitStr( 
    55       const std::string& s, 
    56       const std::string& sep, 
    57       OutIt dest) 
    58    { 
    59       std::string::size_type left = s.find_first_not_of( sep ); 
    60       std::string::size_type right = s.find_first_of( sep, left ); 
    61       while( left < right ) 
    62       { 
    63          *dest = s.substr( left, right-left ); 
    64          ++dest; 
    65          left = s.find_first_not_of( sep, right ); 
    66          right = s.find_first_of( sep, left ); 
    67       } 
    68    } 
    69  
    70    //std::string s = "apple, orange, cherry, peach, grapefruit, cantalope,watermelon"; 
    71  
    72    //std::vector<std::string> v; 
    73    //split( s, " ,", std::back_inserter(v) ); 
    74  
    75 } 
    7652 
    7753 
     
    11793      { mOverlayTextStream << "   "; } 
    11894      mOverlayTextStream << (*prof_node).getName() << "  " << (*prof_node).getSTA().msecf() << std::endl; 
    119    } 
    120  
     95   }         
    12196} 
    12297 
     
    137112 
    138113void PerfProbe::drawOverlayText() 
    139 
    140    const float font_height(10.0f); 
    141    const float font_h_spacing(font_height*1.3f); 
    142    float win_height(1000); 
    143    float win_width(win_height * 1.4f); 
    144  
     114{    
    145115   std::string overlay_text = mOverlayTextStream.str(); 
    146    std::vector<std::string> overlay_lines; 
    147    splitStr(overlay_text,"\n",std::back_inserter(overlay_lines)); 
    148  
    149    float needed_h = font_h_spacing*float(overlay_lines.size()); 
    150    if(needed_h > win_height) 
    151    { 
    152       win_height = needed_h * 1.1f; 
    153       win_width = win_height * 1.4f; 
    154    } 
    155  
    156    glMatrixMode( GL_PROJECTION ); 
    157    glPushMatrix(); 
    158    glLoadIdentity(); 
    159    glOrtho( 0.0, win_width, 0.0, win_height, -1.0, 1.0);     // Setup virtual space 1000, 1000 
    160  
    161    glMatrixMode( GL_MODELVIEW ); 
    162    glPushMatrix(); 
    163    glLoadIdentity(); 
    164  
    165    glDisable(GL_DEPTH_TEST); 
    166  
    167    /* 
    168    glBegin(GL_TRIANGLES); 
    169       glColor3f(1.0, 0.0, 0); 
    170       glVertex3f(100,100,-0.5); 
    171       glColor3f(0,1,0); 
    172       glVertex3f(900,100,-0.5); 
    173       glColor3f(0,0,1); 
    174       glVertex3f(450,800,-0.5); 
    175    glEnd(); 
    176    */ 
    177    //Text::getSingleton()->drawString(Text::StrokeFont, std::string("No Translation")); 
    178  
     116    
    179117   glColor3f(1.0,1.0,0.0); 
    180    glTranslatef(10, win_height-30, 0); 
    181    //float num_lines(overlay_lines.size()); 
    182  
    183    for (unsigned l=0;l<overlay_lines.size();++l) 
    184    { 
    185       glPushMatrix(); 
    186       glTranslatef(0,-font_h_spacing*float(l), 0); 
    187       Text::getSingleton()->drawString(Text::StrokeFont, overlay_lines[l]); 
    188       glPopMatrix(); 
    189    } 
    190  
    191    glEnable(GL_DEPTH_TEST); 
    192  
    193    glMatrixMode(GL_PROJECTION); 
    194    glPopMatrix(); 
    195    glMatrixMode( GL_MODELVIEW); 
    196    glPopMatrix(); 
     118   mText->drawTextBlock(overlay_text);       
    197119} 
    198120 
  • juggler/branches/2.0/modules/vrjuggler/test/Draw/OGL/perfAddon/PerfProbe.h

    r16525 r18550  
    3838#include <vpr/Util/Interval.h> 
    3939#include <sstream> 
     40#include <vrj/Draw/OGL/GlContextData.h> 
     41#include <Text.h> 
    4042 
    4143 
     
    7274 
    7375   std::stringstream    mOverlayTextStream;  /**< Text to write out each frame. */ 
     76   std::string          mOverlayTextToDraw; 
     77   vrj::GlContextData<Text>   mText;         /**< Context specific copy of text. */ 
    7478 
    7579   std::deque<float>    mFrameRateHistory; 
  • juggler/branches/2.0/modules/vrjuggler/test/Draw/OGL/perfAddon/Text.cpp

    r16435 r18550  
    1212 ****************** <aqua heading END do not edit this line> ******************/ 
    1313#include "Text.h" 
     14#include <vector> 
     15#include <string> 
     16 
     17namespace 
     18{ 
     19   template<class OutIt> 
     20   void splitStr( 
     21      const std::string& s, 
     22      const std::string& sep, 
     23      OutIt dest) 
     24   { 
     25      std::string::size_type left = s.find_first_not_of( sep ); 
     26      std::string::size_type right = s.find_first_of( sep, left ); 
     27      while( left < right ) 
     28      { 
     29         *dest = s.substr( left, right-left ); 
     30         ++dest; 
     31         left = s.find_first_not_of( sep, right ); 
     32         right = s.find_first_of( sep, left ); 
     33      } 
     34   } 
     35 
     36   //std::string s = "apple, orange, cherry, peach, grapefruit, cantalope,watermelon"; 
     37 
     38   //std::vector<std::string> v; 
     39   //split( s, " ,", std::back_inserter(v) ); 
     40 
     41} 
    1442 
    1543Text *Text::theText = NULL; 
     
    5179} 
    5280 
    53 // Force singleton 
    54 void *Text::operator new( size_t size ) 
    55 { 
    56     if( theText == NULL ) 
    57       theText = (Text *)malloc( size ); 
    58     return (void *)theText; 
    59 } 
    6081 
    6182Text *Text::getSingleton() 
     
    1375713778    GLuint base = fontmap[font]; 
    1375813779    if( base == 0 ) 
    13759    base = loadFont(font); 
     13780    { base = loadFont(font); } 
    1376013781    glPushAttrib(GL_LIST_BIT); 
    1376113782    glListBase(base); 
     
    1376313784    glPopAttrib(); 
    1376413785} 
     13786 
     13787void Text::drawTextBlock(std::string text, const float xPosFactor, const float yPosFactor,  
     13788                           float fontHeight,  
     13789                           float winHeight, float winWidth) 
     13790{ 
     13791   const float font_h_spacing(fontHeight*1.3f); 
     13792    
     13793   std::vector<std::string> text_lines; 
     13794   splitStr(text,"\n",std::back_inserter(text_lines)); 
     13795 
     13796   float needed_h = font_h_spacing*float(text_lines.size()); 
     13797   if(needed_h > winHeight) 
     13798   { 
     13799      winHeight = needed_h * 1.1f; 
     13800      winWidth = winHeight * 1.4f; 
     13801   } 
     13802 
     13803   glMatrixMode( GL_PROJECTION ); 
     13804   glPushMatrix(); 
     13805   glLoadIdentity(); 
     13806   glOrtho( 0.0, winWidth, 0.0, winHeight, -1.0, 1.0);     // Setup virtual space 1000, 1000 
     13807 
     13808   glMatrixMode( GL_MODELVIEW ); 
     13809   glPushMatrix(); 
     13810   glLoadIdentity(); 
     13811 
     13812   glDisable(GL_DEPTH_TEST); 
     13813 
     13814   /* 
     13815   glBegin(GL_TRIANGLES); 
     13816      glColor3f(1.0, 0.0, 0); 
     13817      glVertex3f(100,100,-0.5); 
     13818      glColor3f(0,1,0); 
     13819      glVertex3f(900,100,-0.5); 
     13820      glColor3f(0,0,1); 
     13821      glVertex3f(450,800,-0.5); 
     13822   glEnd(); 
     13823   */ 
     13824   //Text::getSingleton()->drawString(Text::StrokeFont, std::string("No Translation")); 
     13825 
     13826   glTranslatef(xPosFactor*winWidth, winHeight-(yPosFactor*winHeight), 0); 
     13827   //float num_lines(overlay_lines.size()); 
     13828 
     13829   for (unsigned l=0; l<text_lines.size(); ++l) 
     13830   { 
     13831      glPushMatrix(); 
     13832      glTranslatef(0,-font_h_spacing*float(l), 0); 
     13833      drawString(Text::StrokeFont, text_lines[l]); 
     13834      glPopMatrix(); 
     13835   } 
     13836 
     13837   glEnable(GL_DEPTH_TEST); 
     13838 
     13839   glMatrixMode(GL_PROJECTION); 
     13840   glPopMatrix(); 
     13841   glMatrixMode( GL_MODELVIEW); 
     13842   glPopMatrix(); 
     13843} 
     13844 
  • juggler/branches/2.0/modules/vrjuggler/test/Draw/OGL/perfAddon/Text.h

    r17693 r18550  
    3636        Text(); 
    3737        void drawString( Font, std::string ); 
    38         static Text *getSingleton(); 
    39         void *operator new( size_t size ); 
     38        void drawTextBlock(std::string text, const float xPosFactor=0.05f, const float yPosFactor=0.05f,  
     39                           float fontHeight=10.0f,  
     40                           float winHeight = 1000.0f, float winWidth = 1.4f * 1000.0f); 
     41 
     42         
     43        static Text *getSingleton();     
    4044 
    4145    protected: