1
#include "FTTextureGlyph.h"
4
FTTextureGlyph::FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height)
11
err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
12
if( err || glyph->format != ft_glyph_format_bitmap)
17
FT_Bitmap bitmap = glyph->bitmap;
19
destWidth = bitmap.width;
20
destHeight = bitmap.rows;
22
if( destWidth && destHeight)
24
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
25
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
26
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
27
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
29
glBindTexture( GL_TEXTURE_2D, glTextureID);
30
glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
44
uv[0].x = static_cast<float>(xOffset) / static_cast<float>(width);
45
uv[0].y = static_cast<float>(yOffset) / static_cast<float>(height);
46
uv[1].x = static_cast<float>( xOffset + destWidth) / static_cast<float>(width);
47
uv[1].y = static_cast<float>( yOffset + destHeight) / static_cast<float>(height);
49
pos.x = glyph->bitmap_left;
50
pos.y = glyph->bitmap_top;
54
FTTextureGlyph::~FTTextureGlyph()
59
float FTTextureGlyph::Render( const FTPoint& pen)
63
glGetIntegerv( GL_TEXTURE_2D_BINDING_EXT, &activeTextureID);
64
if( activeTextureID != glTextureID)
66
glBindTexture( GL_TEXTURE_2D, (GLuint)glTextureID);
69
dx= floor( (pen.x + pos.x ) );
72
glTexCoord2f( uv[0].x, uv[0].y);
73
glVertex2f( dx, pen.y + pos.y);
75
glTexCoord2f( uv[0].x, uv[1].y);
76
glVertex2f( dx, pen.y + pos.y - destHeight);
78
glTexCoord2f( uv[1].x, uv[1].y);
79
glVertex2f( dx + destWidth, pen.y + pos.y - destHeight);
81
glTexCoord2f( uv[1].x, uv[0].y);
82
glVertex2f( dx + destWidth, pen.y + pos.y);