* Fix FTTextureGlyph rendering offset so that it works with layouts.
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
diff --git a/demo/FTGLDemo.cpp b/demo/FTGLDemo.cpp
index 4373ab0..9f0bce3 100644
--- a/demo/FTGLDemo.cpp
+++ b/demo/FTGLDemo.cpp
@@ -563,7 +563,7 @@ void parseSpecialKey(int key, int x, int y)
current_font = (current_font + 1) % 6;
break;
case GLUT_KEY_DOWN:
- current_font = (current_font + 4) % 6;
+ current_font = (current_font + 5) % 6;
break;
case GLUT_KEY_PAGE_UP:
currentLayout = (currentLayout + 1) % NumLayouts;
diff --git a/include/FTTextureGlyph.h b/include/FTTextureGlyph.h
index b6ee78e..a898756 100644
--- a/include/FTTextureGlyph.h
+++ b/include/FTTextureGlyph.h
@@ -10,10 +10,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -47,7 +47,7 @@
/**
* FTTextureGlyph is a specialisation of FTGlyph for creating texture
* glyphs.
- *
+ *
* @see FTGlyphContainer
*
*/
@@ -67,7 +67,7 @@ class FTGL_EXPORT FTTextureGlyph : public FTGlyph
* @param width The width of the parent texture
* @param height The height (number of rows) of the parent texture
*/
- FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height);
+ FTTextureGlyph(FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height);
/**
* Destructor
@@ -81,13 +81,14 @@ class FTGL_EXPORT FTTextureGlyph : public FTGlyph
* @param renderMode Render mode to display
* @return The advance distance for this glyph.
*/
- virtual const FTPoint& Render( const FTPoint& pen, int renderMode);
+ virtual const FTPoint& Render(const FTPoint& pen, int renderMode);
/**
- * Reset the currently active texture to zero to get into a known state before
- * drawing a string. This is to get round possible threading issues.
+ * Reset the currently active texture to zero to get into a known
+ * state before drawing a string. This is to get round possible
+ * threading issues.
*/
- static void ResetActiveTexture(){ activeTextureID = 0;}
+ static void ResetActiveTexture() { activeTextureID = 0; }
private:
/**
@@ -118,12 +119,11 @@ class FTGL_EXPORT FTTextureGlyph : public FTGlyph
/**
* The texture index of the currently active texture
*
- * We keep track of the currently active texture to try to reduce the number
- * of texture bind operations.
+ * We keep track of the currently active texture to try to reduce the
+ * number of texture bind operations.
*/
static GLint activeTextureID;
-
};
-
#endif // __FTTextureGlyph__
+
diff --git a/src/FTTextureGlyph.cpp b/src/FTTextureGlyph.cpp
index 504874b..b478f5b 100644
--- a/src/FTTextureGlyph.cpp
+++ b/src/FTTextureGlyph.cpp
@@ -10,10 +10,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -37,15 +37,15 @@
#include "FTTextureGlyph.h"
GLint FTTextureGlyph::activeTextureID = 0;
-
-FTTextureGlyph::FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height)
-: FTGlyph( glyph),
+
+FTTextureGlyph::FTTextureGlyph(FT_GlyphSlot glyph, int id, int xOffset, int yOffset, GLsizei width, GLsizei height)
+: FTGlyph(glyph),
destWidth(0),
destHeight(0),
glTextureID(id)
{
- err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
- if( err || glyph->format != ft_glyph_format_bitmap)
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
+ if(err || glyph->format != ft_glyph_format_bitmap)
{
return;
}
@@ -54,36 +54,36 @@ FTTextureGlyph::FTTextureGlyph( FT_GlyphSlot glyph, int id, int xOffset, int yOf
destWidth = bitmap.width;
destHeight = bitmap.rows;
-
- if( destWidth && destHeight)
+
+ if(destWidth && destHeight)
{
- glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
- glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE);
- glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
+ 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, bitmap.buffer);
+ glBindTexture(GL_TEXTURE_2D, glTextureID);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
glPopClientAttrib();
}
-// 0
+// 0
// +----+
// | |
// | |
// | |
// +----+
// 1
-
- uv[0].X( static_cast<float>(xOffset) / static_cast<float>(width));
- uv[0].Y( static_cast<float>(yOffset) / static_cast<float>(height));
- uv[1].X( static_cast<float>( xOffset + destWidth) / static_cast<float>(width));
- uv[1].Y( static_cast<float>( yOffset + destHeight) / static_cast<float>(height));
-
- pos.X( glyph->bitmap_left);
- pos.Y( glyph->bitmap_top);
+
+ uv[0].X(static_cast<float>(xOffset) / static_cast<float>(width));
+ uv[0].Y(static_cast<float>(yOffset) / static_cast<float>(height));
+ uv[1].X(static_cast<float>(xOffset + destWidth) / static_cast<float>(width));
+ uv[1].Y(static_cast<float>(yOffset + destHeight) / static_cast<float>(height));
+
+ pos.X(glyph->bitmap_left);
+ pos.Y(glyph->bitmap_top);
}
@@ -91,30 +91,32 @@ FTTextureGlyph::~FTTextureGlyph()
{}
-const FTPoint& FTTextureGlyph::Render( const FTPoint& pen, int renderMode)
+const FTPoint& FTTextureGlyph::Render(const FTPoint& pen, int renderMode)
{
- if( activeTextureID != glTextureID)
+ if(activeTextureID != glTextureID)
{
- glBindTexture( GL_TEXTURE_2D, (GLuint)glTextureID);
+ glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID);
activeTextureID = glTextureID;
}
-
- glTranslatef( pen.X(), pen.Y(), 0.0f);
- glBegin( GL_QUADS);
- glTexCoord2f( uv[0].X(), uv[0].Y());
- glVertex2f( pos.X(), pos.Y());
+ glTranslatef(pen.X(), pen.Y(), 0.0f);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(uv[0].X(), uv[0].Y());
+ glVertex2f(pos.X(), pos.Y());
- glTexCoord2f( uv[0].X(), uv[1].Y());
- glVertex2f( pos.X(), pos.Y() - destHeight);
+ glTexCoord2f(uv[0].X(), uv[1].Y());
+ glVertex2f(pos.X(), pos.Y() - destHeight);
- glTexCoord2f( uv[1].X(), uv[1].Y());
- glVertex2f( destWidth + pos.X(), pos.Y() - destHeight);
-
- glTexCoord2f( uv[1].X(), uv[0].Y());
- glVertex2f( destWidth + pos.X(), pos.Y());
+ glTexCoord2f(uv[1].X(), uv[1].Y());
+ glVertex2f(destWidth + pos.X(), pos.Y() - destHeight);
+
+ glTexCoord2f(uv[1].X(), uv[0].Y());
+ glVertex2f(destWidth + pos.X(), pos.Y());
glEnd();
+ glTranslatef(-pen.X(), -pen.Y(), 0.0f);
+
return advance;
}