ofSetLineWidth maximum value

#1

Hi

There seems to be a max value possible for line width. I’m not sure exactly what it is, but I noticed that using say, ofSetLineWidth(50) and ofSetLineWidth(100) gives exactly the same result.

Is there some way I can change the max value? I looked for the function definition but couldn’t see anything relevant.

Thanks.

1 Like
#2

no, unfortunately this maximum is graphics card dependent (ie each implementation is slightly different) as we are calling internally opengl’s glLineWidth:

http://www.khronos.org/opengles/documen-…-Width.html

if you need thicker lines, you may need to draw them yourself with polygons, rectangles or an opengl type (like triangle strip, etc).

hope that helps -
zach

#3

I know this topic is way out of date, but this might just save people some time.

  
enum alignArc{  
        ALIGN_LEFT 	    = 0,  
        ALIGN_MIDDLE    = 1,  
        ALIGN_RIGHT     = 2  
    };  
      
    vector<ofPoint> customArcShape(int x, int y, int degrees, int precision, int inner, int outer, alignArc mode) {  
          
        // calculate start and end degrees based on alignment  
        int startDeg = 0;  
        int endDeg = degrees;  
        int offSet = -90; // ususally 0 is the most outer point on the right of a circle, I'd like to have it on top like a clock  
          
        switch (mode) {  
            case ALIGN_LEFT:  
                startDeg = (degrees*-1)+offSet;  
                endDeg = 0+offSet;  
                break;  
            case ALIGN_MIDDLE:  
                startDeg = ((degrees/2)*-1)+offSet;  
                endDeg = (degrees/2)+offSet;  
                break;  
            case ALIGN_RIGHT:  
                startDeg = 0+offSet;  
                endDeg = degrees+offSet;  
                break;  
            default:  
                break;  
        }  
          
        ofPolyline outerLine;  
        outerLine.arc(x, y, outer, outer, startDeg, endDeg, precision);  
        vector<ofPoint> outerPoints = outerLine.getVertices();  
          
        ofPolyline innerLine;  
        innerLine.arc(x, y, inner, inner, startDeg, endDeg, precision);  
        vector<ofPoint> innerPoints = innerLine.getVertices();  
          
        vector<ofPoint> combinedPoints;  
        for (int i = 0; i < outerPoints.size(); i++) {  
            combinedPoints.push_back(outerPoints.at(i));  
        }  
        for (int i = innerPoints.size()-1; i >= 0; i--) {  
            combinedPoints.push_back(innerPoints.at(i));  
        }  
          
        return combinedPoints;  
    }  
  

Just add this to an ofPolyline object or anything like that and you should be fine.

update: this only works on arcs of course, might have been a bit too focussed on my own issue in order to see if this is a useful addition.

#4

I discovered that limitation of max line width too, there is a simple solution - to translate
I got tripplesuperline with translations of the same line next to itself (4, 4) & (-4, -4) (since for me width limit is 9)

myTooThinLine.draw();
ofTranslate(4, 4);
myTooThinLine.draw();
ofTranslate(-4, -4);
myTooThinLine.draw();

#5

Just came across this issue so wrote a little function to draw a rectangle representation of a line. I know this topic is 5 years old but was one of the first search results I found, so might be of use to someone.

Possibly it would be more correct to use ofPoint instead of ofVect2f here as the vector parameters do refer to points on the screen.

  drawLineAsRect(ofVec2f startVec, ofVec2f endVec,float thickness) {
    float angle = atan((endVec.y-startVec.y)/(endVec.x-startVec.x));
    ofPushMatrix();
    ofTranslate(startVec.x,startVec.y);
    ofRotate(ofRadToDeg(angle));
    float lineLength = (endVec.x - startVec.x)/cos(angle);
    ofRect(0,-thickness/2,lineLength,thickness);
    ofPopMatrix();
}