std::vector<FONSquad>& FontContext::rasterize(const std::string& _text, FontID _fontID, float _fontSize, float _sdf) { m_quadBuffer.clear(); fonsSetSize(m_fsContext, _fontSize); fonsSetFont(m_fsContext, _fontID); if (_sdf > 0){ fonsSetBlur(m_fsContext, _sdf); fonsSetBlurType(m_fsContext, FONS_EFFECT_DISTANCE_FIELD); } else { fonsSetBlurType(m_fsContext, FONS_EFFECT_NONE); } float advance = fonsDrawText(m_fsContext, 0, 0, _text.c_str(), _text.c_str() + _text.length(), 0); if (advance < 0) { m_quadBuffer.clear(); return m_quadBuffer; } return m_quadBuffer; }
/** * Render the font, called by Renderer.cpp */ void FontStashAdapter::render() { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glFrontFace( GL_CCW ); shaderLib->bind(); shaderLib->getShader()->setUniform("ortho", orthogonalProjection ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D , textureID ); shaderLib->getShader()->setUniform("font", 0 ); fonsClearState(context); for( auto text_info: texts ){ fonsSetFont ( context, text_info.fontID ); fonsSetSize ( context, text_info.fontSize ); fonsSetColor ( context, text_info.color ); fonsSetSpacing( context, text_info.spacing ); fonsSetBlur ( context, text_info.blur ); fonsDrawText ( context, text_info.x, text_info.y, text_info.text.c_str(), NULL ); } shaderLib->unbind(); }
bool ofxFontStash2::applyStyle(const ofxFontStashStyle & style){ //if(style.fontID.size()){ fonsClearState(fs); int id = getFsID(style.fontID); fonsSetFont(fs, id); fonsSetSize(fs, style.fontSize * pixelDensity * fontScale); fonsSetColor(fs, toFScolor(style.color)); fonsSetAlign(fs, style.alignment); fonsSetBlur(fs, style.blur); return id != FONS_INVALID; //} }
void FontContext::setSignedDistanceField(float _blurSpread) { fonsSetBlur(m_fsContext, _blurSpread); fonsSetBlurType(m_fsContext, FONS_EFFECT_DISTANCE_FIELD); }