Fixed alignment issues for bitmap and texture glyphs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
diff --git a/include/FTBitmapGlyph.h b/include/FTBitmapGlyph.h
index dd1290b..ad88b00 100755
--- a/include/FTBitmapGlyph.h
+++ b/include/FTBitmapGlyph.h
@@ -53,7 +53,12 @@ class FTGL_EXPORT FTBitmapGlyph : public FTGlyph
* The height of the glyph 'image'
*/
unsigned int destHeight;
-
+
+ /**
+ * The pitch of the glyph 'image'
+ */
+ unsigned int destPitch;
+
/**
* Vector from the pen position to the topleft corner of the bitmap
*/
diff --git a/src/FTBitmapGlyph.cpp b/src/FTBitmapGlyph.cpp
index 8ff3dbf..9f48fb7 100755
--- a/src/FTBitmapGlyph.cpp
+++ b/src/FTBitmapGlyph.cpp
@@ -1,3 +1,5 @@
+#include <string>
+
#include "FTBitmapGlyph.h"
FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)
@@ -6,7 +8,6 @@ FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)
destHeight(0),
data(0)
{
- // This function will always fail if the glyph's format isn't scalable????
err = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_mono, 0, 1);
if( err || ft_glyph_format_bitmap != glyph->format)
{
@@ -16,40 +17,32 @@ FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;
FT_Bitmap* source = &bitmap->bitmap;
- //check the pixel mode
- //ft_pixel_mode_grays
-
unsigned int srcWidth = source->width;
unsigned int srcHeight = source->rows;
unsigned int srcPitch = source->pitch;
- // FIXME What about dest alignment?
destWidth = srcWidth;
destHeight = srcHeight;
-
+ destPitch = srcPitch;
+
if( destWidth && destHeight)
{
- data = new unsigned char[srcPitch * destHeight];
- unsigned char* dest = data + (( destHeight - 1) * srcPitch);
+ data = new unsigned char[destPitch * destHeight];
+ unsigned char* dest = data + (( destHeight - 1) * destPitch);
unsigned char* src = source->buffer;
- size_t destStep = srcPitch * 2;
-
+
for( unsigned int y = 0; y < srcHeight; ++y)
{
- for( unsigned int x = 0; x < srcPitch; ++x)
- {
- *dest++ = *src++;
- }
-
- dest -= destStep;
+ memcpy( dest, src, srcPitch);
+ dest -= destPitch;
+ src += srcPitch;
}
}
pos.x = bitmap->left;
pos.y = static_cast<int>(srcHeight) - bitmap->top;
-
- // Is this the right place to do this?
+
FT_Done_Glyph( glyph );
}
@@ -64,12 +57,11 @@ float FTBitmapGlyph::Render( const FTPoint& pen)
{
if( data)
{
- // Move the glyph origin
glBitmap( 0, 0, 0.0, 0.0, pen.x + pos.x, pen.y - pos.y, (const GLubyte*)0 );
+ glPixelStorei( GL_UNPACK_ROW_LENGTH, destPitch * 8);
glBitmap( destWidth, destHeight, 0.0f, 0.0, 0.0, 0.0, (const GLubyte*)data);
- // Restore the glyph origin
glBitmap( 0, 0, 0.0, 0.0, -pen.x - pos.x, -pen.y + pos.y, (const GLubyte*)0 );
}
diff --git a/src/FTGLBitmapFont.cpp b/src/FTGLBitmapFont.cpp
index 3f8627a..ddca168 100755
--- a/src/FTGLBitmapFont.cpp
+++ b/src/FTGLBitmapFont.cpp
@@ -37,7 +37,6 @@ void FTGLBitmapFont::Render( const char* string)
glPushAttrib( GL_ENABLE_BIT);
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
- glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
glDisable( GL_BLEND);
@@ -55,7 +54,6 @@ void FTGLBitmapFont::Render( const wchar_t* string)
glPushAttrib( GL_ENABLE_BIT);
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
- glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
glDisable( GL_BLEND);
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index 73d4b0c..902e2e2 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -132,7 +132,6 @@ GLuint FTGLTextureFont::CreateTexture()
GLuint textID;
glGenTextures( 1, (GLuint*)&textID);
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
glBindTexture( GL_TEXTURE_2D, textID);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
diff --git a/src/FTTextureGlyph.cpp b/src/FTTextureGlyph.cpp
index f6a13c7..250249c 100755
--- a/src/FTTextureGlyph.cpp
+++ b/src/FTTextureGlyph.cpp
@@ -22,9 +22,15 @@ FTTextureGlyph::FTTextureGlyph( FT_Glyph glyph, int id, int xOffset, int yOffset
if( destWidth && destHeight)
{
- glBindTexture( GL_TEXTURE_2D, glTextureID);
+ glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
+ glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
+
+ glBindTexture( GL_TEXTURE_2D, glTextureID);
glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, source->buffer);
+
+ glPopClientAttrib();
}
@@ -75,6 +81,5 @@ float FTTextureGlyph::Render( const FTPoint& pen)
glEnd();
return advance;
-
}