Skip to content

Instantly share code, notes, and snippets.

int main()
{
/* INITIALIZE OPENGL */
font_ptr pFont = load_font("arial.ttf", 18);
text_buffer_ptr tbuff = text_buffer_ptr(new text_buffer());
std::wstring str = L"Hello World";
tbuff->set(str, pFont);
/* HERE YOU DRAW YOUR VERTEX ARRAY */
return 0;
}
class text_buffer
{
public:
void set(std::wstring& str, font_ptr& font)
{
int size = str.size();
va = vertex_ptr(new vertex());
va->allocate(size*4);
uv = vertex_ptr(new uv());
uv->allocate(size*4);
void fill_texture_data(uint32_t ch, font::font_info_t* font, uint32_t texture_width, uint8_t* texture_data)
{
font::char_info_t* char_info = &font->ch[ch];
uint8_t* char_bmp = char_info->bitmap;
int bmp_pos = 0;
int tex_pos = 0;
int char_x = char_info->x;
int char_y = char_info->y;
int char_width = char_info->width;
int char_height = char_info->height;
font_ptr load_font(const std::string& font_file_path, uint32_t font_size)
{
/* HERE YOU MUST LOAD YOUR TTF FILE INTO THE BUFFER */
uint32_t file_size =
uint8_t* file_buffer =
/* HERE YOU MUST LOAD YOUR TTF FILE INTO THE BUFFER */
font_ptr pFont = font_ptr(new font());
// Initialize Freetype
FT_Library ft_library;
FT_Face ft_face;
class font
{
public:
struct char_info_t
{
int x;
int y;
int width;
int height;
int left;
class texture
{
public:
uint32_t m_id;
bool create_two_channel (uint32_t width, uint32_t height, uint8_t* data)
{
glGenTextures(1, &m_id);
glBindTexture( GL_TEXTURE_2D, m_id);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
struct vertex_node
{
vertex_node():x(0.0f),y(0.0f),z(0.0f){}
float x,y,z;
};
struct uv_node
{
uv_node():u(0.0f),v(0.0f){}
float u,v;
inline int next_p2 ( int a )
{
int rval=1;
while(rval<a) rval<<=1;
return rval;
}
const uint32_t m_number_of_chars = 512;
const uint32_t m_texture_max_width = 2048;
#include <vector>
#include <string>
#include <gl/gl.h>
#include <gl/glu.h>
#include <ft2build.h>
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <boost/shared_ptr.hpp>