← Back

ofxVase

github.com/ofxyz/ofxVase · @ofxyz
OF 0.12 2D Graphics

quality polyline rendering for openFrameworks

3 0 Last commit 7mo ago Created 8mo ago

README

ofxVase



High-quality polyline rendering for openFrameworks with variable width, color, and smooth joints. Based on the VASE renderer algorithm by TSANG, Hao Fung for high-quality polyline tessellation.

sample

Features



How It Works



ofxVase tessellates polylines into triangle meshes with proper geometry for: All rendering uses standard ofMesh, so it works everywhere openFrameworks does.

Usage



#include "ofxVase.h"

void ofApp::draw() {
    // Draw an ofPolyline with uniform width
    ofPolyline line;
    line.addVertex(100, 100);
    line.addVertex(200, 150);
    line.addVertex(300, 100);
    
    ofSetColor(255, 100, 100);
    ofxVase::draw(line, 10.0f);  // 10px width
}


Configure styles



void ofApp::setup() {
    ofxVase::setJointStyle(ofxVase::JointStyle::Round);
    ofxVase::setCapStyle(ofxVase::CapStyle::Round);
}


Variable width and color



void ofApp::draw() {
    std::vector<glm::vec2> points = {
        {100, 100}, {200, 200}, {300, 150}, {400, 200}
    };
    
    std::vector<ofFloatColor> colors = {
        ofFloatColor::red,
        ofFloatColor::yellow,
        ofFloatColor::green,
        ofFloatColor::blue
    };
    
    std::vector<float> widths = {5, 20, 10, 30};
    
    ofxVase::Options opts;
    opts.joint = ofxVase::JointStyle::Round;
    opts.cap = ofxVase::CapStyle::Round;
    
    ofxVase::Polyline poly(points, colors, widths, opts);
    
    ofEnableAlphaBlending();
    ofDisableDepthTest();  // Important for proper alpha blending
    poly.holder.toMesh().draw();
    ofEnableDepthTest();
}


Using the Renderer (recommended)



class ofApp : public ofBaseApp {
    ofxVase::Renderer renderer;
    
    void setup() {
        renderer.setup();
    }
    
    void draw() {
        ofxVase::Polyline poly(points, colors, widths, opts);
        
        renderer.begin();  // Enables alpha blending and depth test settings
        renderer.draw(poly);
        renderer.end();
    }
};


Smoothing (Catmull-Rom Splines)



Enable opts.smoothing = N to subdivide each segment N times using Catmull-Rom spline interpolation. This creates smooth curves from fewer control points:

opts.smoothing = 4;  // 4 subdivisions per segment = silky smooth curves


Joint & Cap Styles



Joint Styles ✓

All three joint styles are fully implemented:
opts.joint = ofxVase::JointStyle::Round;  // or Bevel, or Miter
opts.miterLimit = 4.0f;  // Only affects Miter joints


Cap Styles ✓

opts.cap = ofxVase::CapStyle::Round;  // or Square, or Butt


Wishlist / TODO



License



BSD 3-Clause License - See LICENSE.txt

Get this addon

HTTPS
SSH