简体   繁体   中英

FreeType2 my_draw_bitmap undefined

I am trying to run "7. Simple text rendering" the "a. Basic code" from here but the function "my_draw_bitmap" seems to be undefined. I tried to use GLEW, but the issue is the same. Then I saw "pngwriter" library here , but the compilation for Visual Studio 2013 with Cmake give error.

PNG_LIBRARY错误

Please someone help, where 'my_draw_bitmap' function is defined ?

The tutorial states

The function my_draw_bitmap is not part of FreeType but must be provided by the application to draw the bitmap to the target surface. In this example, it takes a pointer to a FT_Bitmap descriptor and the position of its top-left corner as arguments.

What this means is that you need to implement the function for copying the glyphs to the texture or bitmap to be rendered yourself (assuming there isn't a suitable function available in the libraries you're using).

The below code should be appropriate for copying the pixels of a single glyph to an array that could be copied to a texture.

unsigned char **tex;
void makeTex(const unsigned int width, const unsigned int height)
{
    tex = (unsigned char**)malloc(sizeof(char*)*height);
    tex[0] = (unsigned char*)malloc(sizeof(char)*width*height);
    memset(tex[0], 0, sizeof(char)*width*height);
    for (int i = 1; i < height;i++)
    {
        tex[i] = tex[i*width];
    }
}
void paintGlyph(FT_GlyphSlot glyph, unsigned int penX, unsigned int penY)
{

    for (int y = 0; y<glyph->bitmap.rows; y++)
    {
        //src ptr maps to the start of the current row in the glyph
        unsigned char *src_ptr = glyph->bitmap.buffer + y*glyph->bitmap.pitch;
        //dst ptr maps to the pens current Y pos, adjusted for the current char row
        unsigned char *dst_ptr = tex[penY + (glyph->bitmap.rows - y - 1)] + penX;
        //copy entire row
        for (int x = 0; x<glyph->bitmap.pitch; x++)
        {
            dst_ptr[x] = src_ptr[x];
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM