opengl text along a path

hi,

i’ve done a project a while back in processing that draws text along a path.

just wondering if anyone has some links to examples of this in openframeworks.

thanks.

Hi Julapy

Do you have any success on the text on cure?
May be ofxPango is the way to go?

Thanks

Hi,

I did it for this project - http://vimeo.com/31809603 Ill try and dig out the code when I get 5

This is the3 solution i used

  
  
// loop through the characters you want to display  
  
string currentChar  = msg.substr(i,1);  
  
                if(currentChar == " ") {  
                    charWidth           = font.stringWidth("p");// was "w"  
                    charHeight          = font.stringHeight("p");  
                } else {  
                    charWidth           = font.stringWidth(currentChar);  
                    charHeight          = font.stringHeight(currentChar);  
                }  
                if(currentChar == "w" || currentChar == "W" || currentChar == "m" || currentChar == "M"   ) {  
                    charWidth *=0.75;  
                }  
  
                charPctPosAlongPath = curTextLength/bezierLength;  
                curPos              = charPctPosAlongPath + pctPosStartOffset;  
  
                pt                  = getBezier4Pt(startPoint, cP1, cP2, endPoint, curPos);  
                tanPt               = tangentVector(curPos, startPoint, cP1, cP2, endPoint);  
  
                perPt.x             = tanPt.y;  
                perPt.y             = - tanPt.x;  
  
                float magnitude     = sqrt(pow(perPt.x,2) + pow(perPt.y,2)) / 4;  
  
                //---------------------------------  
  
                perPt.x = perPt.x/ magnitude;  
                perPt.y = perPt.y/ magnitude;  
  
                perPt.x *= charHeight;  
                perPt.y *= charHeight;  
  
                perPt.x += pt.x;  
                perPt.y += pt.y;  
  
                //---------------------------------  
  
                tanPt.x = tanPt.x/ magnitude;  
                tanPt.y = tanPt.y/ magnitude;  
  
                tanPt.x *= charHeight;  
                tanPt.y *= charHeight;  
  
                tanPt.x *= charHeight;  
                tanPt.y *= charHeight;  
  
                float angle = ofRadToDeg(atan2(pt.y - perPt.y, pt.x - perPt.x))-90;  
  
               ofTranslate(pt.x,pt.y,0);  
               ofRotateZ(angle);  
  
               // draw the characters here  
  

the two methods used above are

  
  
  
  
 //--------------------------------------------------------------  
  
  
ofPoint textAlongBezier::tangentVector(float t, ofPoint a, ofPoint b, ofPoint c, ofPoint d){  
  
    ofPoint v;  
  
    // note that abcd are aka x0 x1 x2 x3 -  the x positions of all four points and controls  
  
    float x1 = ( d.x - (3.0 * c.x) + (3.0 * b.x) - a.x );  
    float x2 = ( (3.0 * c.x) - (6.0 * b.x) + (3.0 * a.x) );  
    float x3 = ( (3.0 * b.x) - (3.0 * a.x) );  
    float x4 = ( a.x );  // (not needed for this calculation)  
  
    float y1 = ( d.y - (3.0 * c.y) + (3.0 * b.y) - a.y );  
    float y2 = ( (3.0 * c.y) - (6.0 * b.y) + (3.0 * a.y) );  
    float y3 = ( (3.0 * b.y) - (3.0 * a.y) );  
    float y4 = ( a.y );  // (not needed for this calculation)  
  
    // calculate the slope element, using those coefficients:  
  
    v.x =  ( ( 3.0 * x1 * t* t ) + ( 2.0 * x2 * t ) + x3 );  
    v.y = ( ( 3.0 * y1 * t* t ) + ( 2.0 * y2 * t ) + y3 );  
  
    return v;  
  
    // note that this routine works for both the x and y side;  
    // simply run this routine twice, once for x once for y  
    // note that there are sometimes said to be 8 (not 4) coefficients,  
    // these are simply the four for x and four for y, calculated as above in each case.  
 }  
  
  
  

bezierCurve.h

  
  
#ifndef 	BEZIER_H  
#define 	BEZIER_H  
  
#include "ofMain.h"  
  
  
/*  
  
[http://local.wasp.uwa.edu.au/~pbourke/surfaces-curves/bezier/index2.html](http://local.wasp.uwa.edu.au/~pbourke/surfaces-curves/bezier/index2.html)  
*/  
  
//-----------------------------------------  
inline ofPoint getBezier3Pt( ofPoint p1, ofPoint p2, ofPoint p3, float mu );  
inline ofPoint getBezier3Pt( ofPoint p1, ofPoint p2, ofPoint p3, float mu )  
{  
    double mum1,mum12,mu2;  
    ofPoint p;  
  
    mu2 = mu * mu;  
    mum1 = 1 - mu;  
    mum12 = mum1 * mum1;  
    p.x = p1.x * mum12 + 2 * p2.x * mum1 * mu + p3.x * mu2;  
    p.y = p1.y * mum12 + 2 * p2.y * mum1 * mu + p3.y * mu2;  
    p.z = p1.z * mum12 + 2 * p2.z * mum1 * mu + p3.z * mu2;  
  
    return(p);  
}  
  
//-----------------------------------------  
inline ofPoint getBezier4Pt( ofPoint p1, ofPoint p2, ofPoint p3, ofPoint p4, float mu );  
inline ofPoint getBezier4Pt( ofPoint p1, ofPoint p2, ofPoint p3, ofPoint p4, float mu )  
{  
   double mum1,mum13,mu3;  
   ofPoint p;  
  
   mum1 = 1 - mu;  
   mum13 = mum1 * mum1 * mum1;  
   mu3 = mu * mu * mu;  
  
   p.x = mum13*p1.x + 3*mu*mum1*mum1*p2.x + 3*mu*mu*mum1*p3.x + mu3*p4.x;  
   p.y = mum13*p1.y + 3*mu*mum1*mum1*p2.y + 3*mu*mu*mum1*p3.y + mu3*p4.y;  
   p.z = mum13*p1.z + 3*mu*mum1*mum1*p2.z + 3*mu*mu*mum1*p3.z + mu3*p4.z;  
  
   return(p);  
}  
  
//-----------------------------------------  
inline ofPoint getBezier( vector<ofPoint> & cpts, float mu );  
inline ofPoint getBezier( vector<ofPoint> & cpts, float mu )  
{  
  
   int k,kn,nn,nkn;  
   double blend,muk,munk;  
   ofPoint b = ofPoint(0.0,0.0);  
  
   int n = cpts.size()-1;  
  
   muk = 1;  
   munk = pow(1-mu,(double)n);  
  
  
  
   for (k=0;k<=n;k++) {  
      nn = n;  
      kn = k;  
      nkn = n - k;  
      blend = muk * munk;  
      muk *= mu;  
      munk /= (1-mu);  
      while (nn >= 1) {  
         blend *= nn;  
         nn--;  
         if (kn > 1) {  
            blend /= (double)kn;  
            kn--;  
         }  
         if (nkn > 1) {  
            blend /= (double)nkn;  
            nkn--;  
         }  
      }  
      b.x += cpts[k].x * blend;  
      b.y += cpts[k].y * blend;  
      b.z += cpts[k].z * blend;  
   }  
  
   return(b);  
}  
#endif  
  
  

10x ! I’ll try it right after the Resonate :slight_smile: