• Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    I know that you need FTGL, but freetype2 library is available on aminet:

    http://aminet.net/package/dev/gg/libfreetype2-morphos

    You can use this library and draw a font charset to a OpenGL texture, it's relatively easy. I made a small tool that export a tft font to a png texture and a xml file with all chars parameters, later this files was used on the game i was developing for iPhone and MorphOS (but it was delayed because i need to make other projects, i need to pay my bills), anyway this is a small section of code from my tool, maybe it helps you.

    Code:

    int error = FT_Init_FreeType(&library);

    if (error) {
    printf("Error: Can't initialize freetype library.n");
    return 0;
    }

    FT_Face face;

    error= FT_New_Face(library, font_name, 0, &face);

    if (error) {
    printf("Error: Can't create font face.n");
    return 0;
    }

    FT_Set_Pixel_Sizes(face, font_size, 0);

    int xf = 0, yf = font_size, max_size = 0;
    TiXmlDocument doc;


    TiXmlElement *font_element = new TiXmlElement("font");
    font_element->SetAttribute("name", font_name);
    font_element->SetAttribute("size", font_size);
    font_element->SetAttribute("texture", file_output);

    for (int c = 32; c < 256; c++)
    {

    size_t char_index = FT_Get_Char_Index(face,c);

    error = FT_Load_Glyph(face, char_index, FT_LOAD_DEFAULT);
    if (error)
    continue;

    error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
    if (error)
    continue;

    if (xf+face->glyph->bitmap.width > output_image->width)
    {
    xf = 0;
    yf += max_size;
    if (yf + max_size > output_image->height)
    {
    printf("Error: Output texture is very small to put all characters in one texture.n");
    return 0;
    }
    max_size = 0;
    }

    TiXmlElement *element = new TiXmlElement("character");

    element->SetAttribute("code", c);
    element->SetAttribute("offsetx", xf);
    element->SetAttribute("offsety", yf-font_size);
    element->SetAttribute("width", face->glyph->bitmap.width);
    element->SetAttribute("height", font_size-face->glyph->bitmap_top+face->glyph->bitmap.rows);
    element->SetAttribute("advance", face->glyph->linearHoriAdvance>>16);
    element->SetAttribute("top", face->glyph->bitmap_top);
    font_element->LinkEndChild(element);

    if (max_size < font_size-face->glyph->bitmap_top+face->glyph->bitmap.rows) {
    max_size = font_size-face->glyph->bitmap_top+face->glyph->bitmap.rows;
    }

    for (int y = 0; y < face->glyph->bitmap.rows; y++)
    {
    for (int x = 0; x < face->glyph->bitmap.width; x++)
    {
    int ptr = (xf+x+((output_image->height-yf-y+face->glyph->bitmap_top-1)*output_image->width))*4;
    output_image->data[ptr] = face->glyph->bitmap.buffer[(x + (y * face->glyph->bitmap.width))];
    output_image->data[ptr + 1] = face->glyph->bitmap.buffer[(x + (y * face->glyph->bitmap.width))];
    output_image->data[ptr + 2] = face->glyph->bitmap.buffer[(x + (y * face->glyph->bitmap.width))];
    output_image->data[ptr + 3] = face->glyph->bitmap.buffer[(x + (y * face->glyph->bitmap.width))];
    }
    }

    xf += face->glyph->bitmap.width+1;
    }
    doc.LinkEndChild(font_element);
    doc.SaveFile("font_def.xml");
    }

    save_png(file_output, output_image);
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »14.09.12 - 10:36
    Profile Visit Website