• Advertisement
Sign in to follow this  

Instanced font rendering lib

This topic is 1497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I made a font rendering library originally based on Shikoba.

 

It uses one texture, one vao, 5 vbos, and one draw call to draw text.
A screen full of text performs around 1ms on my PC (A8-4500m apu, 64 bit Xubuntu 12.04, composition disabled). Same performance on Win7 64 bit.

 

get it here (MIT licence):

https://github.com/Yours3lf/instanced_font_rendering

 

easy usage:
 

//load in the shaders with your method, get_shader() gives you a ref to the shader program
load_shader( font::get().get_shader(), GL_VERTEX_SHADER, "../shaders/font/font.vs" );
load_shader( font::get().get_shader(), GL_FRAGMENT_SHADER, "../shaders/font/font.ps" );

uvec2 screen = uvec2( 1280, 720 );

font_inst instance; //this holds your font type and the corresponding sizes
font::get().resize( screen ); //set screen size
font::get().load_font( "../resources/font.ttf", //where your font is
                       instance, //font will load your font into this instance
                       22 ); //the font size

vec3 color = vec3( 0.5, 0.8, 0.5 ); //rgb [0...1]
uvec2 pos = uvec2( 10, 20 ); //in pixels

std::wstring text = L"hello world\n"; //what to display

rendering:
while(true) //your ordinary rendering loop
{
clear_screen();
...
//optionally bind fbo here to render to texture
...
font::get().add_to_text( instance, text + L"_" ); //feed the font
font::get().render( instance, color, pos );
...
swap_buffers();
}

zsO7sST.png

Edited by Yours3!f

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement