summaryrefslogtreecommitdiff
path: root/src/ftgl/FTGlyph
diff options
context:
space:
mode:
Diffstat (limited to 'src/ftgl/FTGlyph')
-rw-r--r--src/ftgl/FTGlyph/FTBitmapGlyph.cpp128
-rw-r--r--src/ftgl/FTGlyph/FTBitmapGlyphImpl.h71
-rw-r--r--src/ftgl/FTGlyph/FTBufferGlyph.cpp121
-rw-r--r--src/ftgl/FTGlyph/FTBufferGlyphImpl.h52
-rw-r--r--src/ftgl/FTGlyph/FTExtrudeGlyph.cpp265
-rw-r--r--src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h69
-rw-r--r--src/ftgl/FTGlyph/FTGlyph.cpp112
-rw-r--r--src/ftgl/FTGlyph/FTGlyphGlue.cpp198
-rw-r--r--src/ftgl/FTGlyph/FTGlyphImpl.h64
-rw-r--r--src/ftgl/FTGlyph/FTOutlineGlyph.cpp149
-rw-r--r--src/ftgl/FTGlyph/FTOutlineGlyphImpl.h69
-rw-r--r--src/ftgl/FTGlyph/FTPixmapGlyph.cpp139
-rw-r--r--src/ftgl/FTGlyph/FTPixmapGlyphImpl.h67
-rw-r--r--src/ftgl/FTGlyph/FTPolygonGlyph.cpp156
-rw-r--r--src/ftgl/FTGlyph/FTPolygonGlyphImpl.h66
-rw-r--r--src/ftgl/FTGlyph/FTTextureGlyph.cpp153
-rw-r--r--src/ftgl/FTGlyph/FTTextureGlyphImpl.h88
17 files changed, 1967 insertions, 0 deletions
diff --git a/src/ftgl/FTGlyph/FTBitmapGlyph.cpp b/src/ftgl/FTGlyph/FTBitmapGlyph.cpp
new file mode 100644
index 0000000..989c890
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBitmapGlyph.cpp
@@ -0,0 +1,128 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <string>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTBitmapGlyphImpl.h"
+
+
+//
+// FTGLBitmapGlyph
+//
+
+
+FTBitmapGlyph::FTBitmapGlyph(FT_GlyphSlot glyph) :
+ FTGlyph(new FTBitmapGlyphImpl(glyph))
+{}
+
+
+FTBitmapGlyph::~FTBitmapGlyph()
+{}
+
+
+const FTPoint& FTBitmapGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTBitmapGlyphImpl *myimpl = dynamic_cast<FTBitmapGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLBitmapGlyphImpl
+//
+
+
+FTBitmapGlyphImpl::FTBitmapGlyphImpl(FT_GlyphSlot glyph)
+: FTGlyphImpl(glyph),
+ destWidth(0),
+ destHeight(0),
+ data(0)
+{
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_MONO);
+ if(err || ft_glyph_format_bitmap != glyph->format)
+ {
+ return;
+ }
+
+ FT_Bitmap bitmap = glyph->bitmap;
+
+ unsigned int srcWidth = bitmap.width;
+ unsigned int srcHeight = bitmap.rows;
+ unsigned int srcPitch = bitmap.pitch;
+
+ destWidth = srcWidth;
+ destHeight = srcHeight;
+ destPitch = srcPitch;
+
+ if(destWidth && destHeight)
+ {
+ data = new unsigned char[destPitch * destHeight];
+ unsigned char* dest = data + ((destHeight - 1) * destPitch);
+
+ unsigned char* src = bitmap.buffer;
+
+ for(unsigned int y = 0; y < srcHeight; ++y)
+ {
+ memcpy(dest, src, srcPitch);
+ dest -= destPitch;
+ src += srcPitch;
+ }
+ }
+
+ pos = FTPoint(glyph->bitmap_left, static_cast<int>(srcHeight) - glyph->bitmap_top, 0.0);
+}
+
+
+FTBitmapGlyphImpl::~FTBitmapGlyphImpl()
+{
+ delete [] data;
+}
+
+
+const FTPoint& FTBitmapGlyphImpl::RenderImpl(const FTPoint& pen, int renderMode)
+{
+ if(data)
+ {
+ float dx, dy;
+
+ dx = pen.Xf() + pos.Xf();
+ dy = pen.Yf() - pos.Yf();
+
+ glBitmap(0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, destPitch * 8);
+ glBitmap(destWidth, destHeight, 0.0f, 0.0, 0.0, 0.0,
+ (const GLubyte*)data);
+ glBitmap(0, 0, 0.0f, 0.0f, -dx, -dy, (const GLubyte*)0);
+ }
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTBitmapGlyphImpl.h b/src/ftgl/FTGlyph/FTBitmapGlyphImpl.h
new file mode 100644
index 0000000..c61a679
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBitmapGlyphImpl.h
@@ -0,0 +1,71 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTBitmapGlyphImpl__
+#define __FTBitmapGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTBitmapGlyphImpl : public FTGlyphImpl
+{
+ friend class FTBitmapGlyph;
+
+ protected:
+ FTBitmapGlyphImpl(FT_GlyphSlot glyph);
+
+ virtual ~FTBitmapGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * The width of the glyph 'image'
+ */
+ unsigned int destWidth;
+
+ /**
+ * 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
+ */
+ FTPoint pos;
+
+ /**
+ * Pointer to the 'image' data
+ */
+ unsigned char* data;
+};
+
+#endif // __FTBitmapGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTBufferGlyph.cpp b/src/ftgl/FTGlyph/FTBufferGlyph.cpp
new file mode 100644
index 0000000..7a78b0e
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBufferGlyph.cpp
@@ -0,0 +1,121 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <string>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTBufferGlyphImpl.h"
+
+
+//
+// FTGLBufferGlyph
+//
+
+
+FTBufferGlyph::FTBufferGlyph(FT_GlyphSlot glyph, FTBuffer *buffer) :
+ FTGlyph(new FTBufferGlyphImpl(glyph, buffer))
+{}
+
+
+FTBufferGlyph::~FTBufferGlyph()
+{}
+
+
+const FTPoint& FTBufferGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTBufferGlyphImpl *myimpl = dynamic_cast<FTBufferGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLBufferGlyphImpl
+//
+
+
+FTBufferGlyphImpl::FTBufferGlyphImpl(FT_GlyphSlot glyph, FTBuffer *p)
+: FTGlyphImpl(glyph),
+ has_bitmap(false),
+ buffer(p)
+{
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
+ if(err || glyph->format != ft_glyph_format_bitmap)
+ {
+ return;
+ }
+
+ bitmap = glyph->bitmap;
+ pixels = new unsigned char[bitmap.pitch * bitmap.rows];
+ memcpy(pixels, bitmap.buffer, bitmap.pitch * bitmap.rows);
+
+ if(bitmap.width && bitmap.rows)
+ {
+ has_bitmap = true;
+ corner = FTPoint(glyph->bitmap_left, glyph->bitmap_top);
+ }
+}
+
+
+FTBufferGlyphImpl::~FTBufferGlyphImpl()
+{
+ delete[] pixels;
+}
+
+
+const FTPoint& FTBufferGlyphImpl::RenderImpl(const FTPoint& pen, int renderMode)
+{
+ if(has_bitmap)
+ {
+ FTPoint pos(buffer->Pos() + pen + corner);
+ int dx = (int)(pos.Xf() + 0.5f);
+ int dy = buffer->Height() - (int)(pos.Yf() + 0.5f);
+ unsigned char * dest = buffer->Pixels() + dx + dy * buffer->Width();
+
+ for(int y = 0; y < bitmap.rows; y++)
+ {
+ // FIXME: change the loop bounds instead of doing this test
+ if(y + dy < 0 || y + dy >= buffer->Height()) continue;
+
+ for(int x = 0; x < bitmap.width; x++)
+ {
+ if(x + dx < 0 || x + dx >= buffer->Width()) continue;
+
+ unsigned char p = pixels[y * bitmap.pitch + x];
+
+ if(p)
+ {
+ dest[y * buffer->Width() + x] = p;
+ }
+ }
+ }
+ }
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTBufferGlyphImpl.h b/src/ftgl/FTGlyph/FTBufferGlyphImpl.h
new file mode 100644
index 0000000..5a15049
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTBufferGlyphImpl.h
@@ -0,0 +1,52 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTBufferGlyphImpl__
+#define __FTBufferGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTBufferGlyphImpl : public FTGlyphImpl
+{
+ friend class FTBufferGlyph;
+
+ protected:
+ FTBufferGlyphImpl(FT_GlyphSlot glyph, FTBuffer *p);
+
+ virtual ~FTBufferGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ bool has_bitmap;
+ FT_Bitmap bitmap;
+ unsigned char *pixels;
+ FTPoint corner;
+
+ FTBuffer *buffer;
+};
+
+#endif // __FTBufferGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTExtrudeGlyph.cpp b/src/ftgl/FTGlyph/FTExtrudeGlyph.cpp
new file mode 100644
index 0000000..df0496e
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTExtrudeGlyph.cpp
@@ -0,0 +1,265 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <iostream>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTExtrudeGlyphImpl.h"
+#include "FTVectoriser.h"
+
+
+//
+// FTGLExtrudeGlyph
+//
+
+
+FTExtrudeGlyph::FTExtrudeGlyph(FT_GlyphSlot glyph, float depth,
+ float frontOutset, float backOutset,
+ bool useDisplayList) :
+ FTGlyph(new FTExtrudeGlyphImpl(glyph, depth, frontOutset, backOutset,
+ useDisplayList))
+{}
+
+
+FTExtrudeGlyph::~FTExtrudeGlyph()
+{}
+
+
+const FTPoint& FTExtrudeGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTExtrudeGlyphImpl *myimpl = dynamic_cast<FTExtrudeGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLExtrudeGlyphImpl
+//
+
+
+FTExtrudeGlyphImpl::FTExtrudeGlyphImpl(FT_GlyphSlot glyph, float _depth,
+ float _frontOutset, float _backOutset,
+ bool useDisplayList)
+: FTGlyphImpl(glyph),
+ vectoriser(0),
+ glList(0)
+{
+ bBox.SetDepth(-_depth);
+
+ if(ft_glyph_format_outline != glyph->format)
+ {
+ err = 0x14; // Invalid_Outline
+ return;
+ }
+
+ vectoriser = new FTVectoriser(glyph);
+
+ if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
+ {
+ delete vectoriser;
+ vectoriser = NULL;
+ return;
+ }
+
+ hscale = glyph->face->size->metrics.x_ppem * 64;
+ vscale = glyph->face->size->metrics.y_ppem * 64;
+ depth = _depth;
+ frontOutset = _frontOutset;
+ backOutset = _backOutset;
+
+ if(useDisplayList)
+ {
+ glList = glGenLists(3);
+
+ /* Front face */
+ glNewList(glList + 0, GL_COMPILE);
+ RenderFront();
+ glEndList();
+
+ /* Back face */
+ glNewList(glList + 1, GL_COMPILE);
+ RenderBack();
+ glEndList();
+
+ /* Side face */
+ glNewList(glList + 2, GL_COMPILE);
+ RenderSide();
+ glEndList();
+
+ delete vectoriser;
+ vectoriser = NULL;
+ }
+}
+
+
+FTExtrudeGlyphImpl::~FTExtrudeGlyphImpl()
+{
+ if(glList)
+ {
+ glDeleteLists(glList, 3);
+ }
+ else if(vectoriser)
+ {
+ delete vectoriser;
+ }
+}
+
+
+const FTPoint& FTExtrudeGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ glTranslatef(pen.Xf(), pen.Yf(), pen.Zf());
+ if(glList)
+ {
+ if(renderMode & FTGL::RENDER_FRONT)
+ glCallList(glList + 0);
+ if(renderMode & FTGL::RENDER_BACK)
+ glCallList(glList + 1);
+ if(renderMode & FTGL::RENDER_SIDE)
+ glCallList(glList + 2);
+ }
+ else if(vectoriser)
+ {
+ if(renderMode & FTGL::RENDER_FRONT)
+ RenderFront();
+ if(renderMode & FTGL::RENDER_BACK)
+ RenderBack();
+ if(renderMode & FTGL::RENDER_SIDE)
+ RenderSide();
+ }
+ glTranslatef(-pen.Xf(), -pen.Yf(), -pen.Zf());
+
+ return advance;
+}
+
+
+void FTExtrudeGlyphImpl::RenderFront()
+{
+ vectoriser->MakeMesh(1.0, 1, frontOutset);
+ glNormal3d(0.0, 0.0, 1.0);
+
+ const FTMesh *mesh = vectoriser->GetMesh();
+ for(unsigned int j = 0; j < mesh->TesselationCount(); ++j)
+ {
+ const FTTesselation* subMesh = mesh->Tesselation(j);
+ unsigned int polygonType = subMesh->PolygonType();
+
+ glBegin(polygonType);
+ for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+ {
+ FTPoint pt = subMesh->Point(i);
+
+ glTexCoord2f(pt.Xf() / hscale,
+ pt.Yf() / vscale);
+
+ glVertex3f(pt.Xf() / 64.0f,
+ pt.Yf() / 64.0f,
+ 0.0f);
+ }
+ glEnd();
+ }
+}
+
+
+void FTExtrudeGlyphImpl::RenderBack()
+{
+ vectoriser->MakeMesh(-1.0, 2, backOutset);
+ glNormal3d(0.0, 0.0, -1.0);
+
+ const FTMesh *mesh = vectoriser->GetMesh();
+ for(unsigned int j = 0; j < mesh->TesselationCount(); ++j)
+ {
+ const FTTesselation* subMesh = mesh->Tesselation(j);
+ unsigned int polygonType = subMesh->PolygonType();
+
+ glBegin(polygonType);
+ for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+ {
+ FTPoint pt = subMesh->Point(i);
+
+ glTexCoord2f(subMesh->Point(i).Xf() / hscale,
+ subMesh->Point(i).Yf() / vscale);
+
+ glVertex3f(subMesh->Point(i).Xf() / 64.0f,
+ subMesh->Point(i).Yf() / 64.0f,
+ -depth);
+ }
+ glEnd();
+ }
+}
+
+
+void FTExtrudeGlyphImpl::RenderSide()
+{
+ int contourFlag = vectoriser->ContourFlag();
+
+ for(size_t c = 0; c < vectoriser->ContourCount(); ++c)
+ {
+ const FTContour* contour = vectoriser->Contour(c);
+ size_t n = contour->PointCount();
+
+ if(n < 2)
+ {
+ continue;
+ }
+
+ glBegin(GL_QUAD_STRIP);
+ for(size_t j = 0; j <= n; ++j)
+ {
+ size_t cur = (j == n) ? 0 : j;
+ size_t next = (cur == n - 1) ? 0 : cur + 1;
+
+ FTPoint frontPt = contour->FrontPoint(cur);
+ FTPoint nextPt = contour->FrontPoint(next);
+ FTPoint backPt = contour->BackPoint(cur);
+
+ FTPoint normal = FTPoint(0.f, 0.f, 1.f) ^ (frontPt - nextPt);
+ if(normal != FTPoint(0.0f, 0.0f, 0.0f))
+ {
+ glNormal3dv(static_cast<const FTGL_DOUBLE*>(normal.Normalise()));
+ }
+
+ glTexCoord2f(frontPt.Xf() / hscale, frontPt.Yf() / vscale);
+
+ if(contourFlag & ft_outline_reverse_fill)
+ {
+ glVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, 0.0f);
+ glVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, -depth);
+ }
+ else
+ {
+ glVertex3f(backPt.Xf() / 64.0f, backPt.Yf() / 64.0f, -depth);
+ glVertex3f(frontPt.Xf() / 64.0f, frontPt.Yf() / 64.0f, 0.0f);
+ }
+ }
+ glEnd();
+ }
+}
+
diff --git a/src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h b/src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h
new file mode 100644
index 0000000..7c547c7
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTExtrudeGlyphImpl.h
@@ -0,0 +1,69 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTExtrudeGlyphImpl__
+#define __FTExtrudeGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTVectoriser;
+
+class FTExtrudeGlyphImpl : public FTGlyphImpl
+{
+ friend class FTExtrudeGlyph;
+
+ protected:
+ FTExtrudeGlyphImpl(FT_GlyphSlot glyph, float depth, float frontOutset,
+ float backOutset, bool useDisplayList);
+
+ virtual ~FTExtrudeGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Private rendering methods.
+ */
+ void RenderFront();
+ void RenderBack();
+ void RenderSide();
+
+ /**
+ * Private rendering variables.
+ */
+ unsigned int hscale, vscale;
+ float depth;
+ float frontOutset, backOutset;
+ FTVectoriser *vectoriser;
+
+ /**
+ * OpenGL display list
+ */
+ GLuint glList;
+};
+
+#endif // __FTExtrudeGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTGlyph.cpp b/src/ftgl/FTGlyph/FTGlyph.cpp
new file mode 100644
index 0000000..4d3dff6
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTGlyph.cpp
@@ -0,0 +1,112 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTGlyphImpl.h"
+
+
+//
+// FTGlyph
+//
+
+
+FTGlyph::FTGlyph(FT_GlyphSlot glyph)
+{
+ impl = new FTGlyphImpl(glyph);
+}
+
+
+FTGlyph::FTGlyph(FTGlyphImpl *pImpl)
+{
+ impl = pImpl;
+}
+
+
+FTGlyph::~FTGlyph()
+{
+ delete impl;
+}
+
+
+float FTGlyph::Advance() const
+{
+ return impl->Advance();
+}
+
+
+const FTBBox& FTGlyph::BBox() const
+{
+ return impl->BBox();
+}
+
+
+FT_Error FTGlyph::Error() const
+{
+ return impl->Error();
+}
+
+
+//
+// FTGlyphImpl
+//
+
+
+FTGlyphImpl::FTGlyphImpl(FT_GlyphSlot glyph, bool useList) : err(0)
+{
+ if(glyph)
+ {
+ bBox = FTBBox(glyph);
+ advance = FTPoint(glyph->advance.x / 64.0f,
+ glyph->advance.y / 64.0f);
+ }
+}
+
+
+FTGlyphImpl::~FTGlyphImpl()
+{}
+
+
+float FTGlyphImpl::Advance() const
+{
+ return advance.Xf();
+}
+
+
+const FTBBox& FTGlyphImpl::BBox() const
+{
+ return bBox;
+}
+
+
+FT_Error FTGlyphImpl::Error() const
+{
+ return err;
+}
+
diff --git a/src/ftgl/FTGlyph/FTGlyphGlue.cpp b/src/ftgl/FTGlyph/FTGlyphGlue.cpp
new file mode 100644
index 0000000..0fbbc01
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTGlyphGlue.cpp
@@ -0,0 +1,198 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+
+static const FTPoint static_ftpoint;
+static const FTBBox static_ftbbox;
+
+FTGL_BEGIN_C_DECLS
+
+#define C_TOR(cname, cargs, cxxname, cxxarg, cxxtype) \
+ FTGLglyph* cname cargs \
+ { \
+ cxxname *g = new cxxname cxxarg; \
+ if(g->Error()) \
+ { \
+ delete g; \
+ return NULL; \
+ } \
+ FTGLglyph *ftgl = (FTGLglyph *)malloc(sizeof(FTGLglyph)); \
+ ftgl->ptr = g; \
+ ftgl->type = cxxtype; \
+ return ftgl; \
+ }
+
+// FTBitmapGlyph::FTBitmapGlyph();
+C_TOR(ftglCreateBitmapGlyph, (FT_GlyphSlot glyph),
+ FTBitmapGlyph, (glyph), GLYPH_BITMAP);
+
+// FTBufferGlyph::FTBufferGlyph();
+// FIXME: not implemented
+
+// FTExtrudeGlyph::FTExtrudeGlyph();
+C_TOR(ftglCreateExtrudeGlyph, (FT_GlyphSlot glyph, float depth,
+ float frontOutset, float backOutset, int useDisplayList),
+ FTExtrudeGlyph, (glyph, depth, frontOutset, backOutset, (useDisplayList != 0)),
+ GLYPH_EXTRUDE);
+
+// FTOutlineGlyph::FTOutlineGlyph();
+C_TOR(ftglCreateOutlineGlyph, (FT_GlyphSlot glyph, float outset,
+ int useDisplayList),
+ FTOutlineGlyph, (glyph, outset, (useDisplayList != 0)), GLYPH_OUTLINE);
+
+// FTPixmapGlyph::FTPixmapGlyph();
+C_TOR(ftglCreatePixmapGlyph, (FT_GlyphSlot glyph),
+ FTPixmapGlyph, (glyph), GLYPH_PIXMAP);
+
+// FTPolygonGlyph::FTPolygonGlyph();
+C_TOR(ftglCreatePolygonGlyph, (FT_GlyphSlot glyph, float outset,
+ int useDisplayList),
+ FTPolygonGlyph, (glyph, outset, (useDisplayList != 0)), GLYPH_POLYGON);
+
+// FTTextureGlyph::FTTextureGlyph();
+C_TOR(ftglCreateTextureGlyph, (FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height),
+ FTTextureGlyph, (glyph, id, xOffset, yOffset, width, height),
+ GLYPH_TEXTURE);
+
+// FTCustomGlyph::FTCustomGlyph();
+class FTCustomGlyph : public FTGlyph
+{
+public:
+ FTCustomGlyph(FTGLglyph *base, void *p,
+ void (*render) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *),
+ void (*destroy) (FTGLglyph *, void *))
+ : FTGlyph((FT_GlyphSlot)0),
+ baseGlyph(base),
+ data(p),
+ renderCallback(render),
+ destroyCallback(destroy)
+ {}
+
+ ~FTCustomGlyph()
+ {
+ destroyCallback(baseGlyph, data);
+ }
+
+ float Advance() const { return baseGlyph->ptr->Advance(); }
+
+ const FTPoint& Render(const FTPoint& pen, int renderMode)
+ {
+ FTGL_DOUBLE advancex, advancey;
+ renderCallback(baseGlyph, data, pen.X(), pen.Y(), renderMode,
+ &advancex, &advancey);
+ advance = FTPoint(advancex, advancey);
+ return advance;
+ }
+
+ const FTBBox& BBox() const { return baseGlyph->ptr->BBox(); }
+
+ FT_Error Error() const { return baseGlyph->ptr->Error(); }
+
+private:
+ FTPoint advance;
+ FTGLglyph *baseGlyph;
+ void *data;
+ void (*renderCallback) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *);
+ void (*destroyCallback) (FTGLglyph *, void *);
+};
+
+C_TOR(ftglCreateCustomGlyph, (FTGLglyph *base, void *data,
+ void (*renderCallback) (FTGLglyph *, void *, FTGL_DOUBLE, FTGL_DOUBLE,
+ int, FTGL_DOUBLE *, FTGL_DOUBLE *),
+ void (*destroyCallback) (FTGLglyph *, void *)),
+ FTCustomGlyph, (base, data, renderCallback, destroyCallback),
+ GLYPH_CUSTOM);
+
+#define C_FUN(cret, cname, cargs, cxxerr, cxxname, cxxarg) \
+ cret cname cargs \
+ { \
+ if(!g || !g->ptr) \
+ { \
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", #cname); \
+ cxxerr; \
+ } \
+ return g->ptr->cxxname cxxarg; \
+ }
+
+// FTGlyph::~FTGlyph();
+void ftglDestroyGlyph(FTGLglyph *g)
+{
+ if(!g || !g->ptr)
+ {
+ fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+ return;
+ }
+ delete g->ptr;
+ free(g);
+}
+
+// const FTPoint& FTGlyph::Render(const FTPoint& pen, int renderMode);
+extern "C++" {
+C_FUN(static const FTPoint&, _ftglRenderGlyph, (FTGLglyph *g,
+ const FTPoint& pen, int renderMode),
+ return static_ftpoint, Render, (pen, renderMode));
+}
+
+void ftglRenderGlyph(FTGLglyph *g, FTGL_DOUBLE penx, FTGL_DOUBLE peny,
+ int renderMode, FTGL_DOUBLE *advancex,
+ FTGL_DOUBLE *advancey)
+{
+ FTPoint pen(penx, peny);
+ FTPoint ret = _ftglRenderGlyph(g, pen, renderMode);
+ *advancex = ret.X();
+ *advancey = ret.Y();
+}
+
+// float FTGlyph::Advance() const;
+C_FUN(float, ftglGetGlyphAdvance, (FTGLglyph *g), return 0.0, Advance, ());
+
+// const FTBBox& FTGlyph::BBox() const;
+extern "C++" {
+C_FUN(static const FTBBox&, _ftglGetGlyphBBox, (FTGLglyph *g),
+ return static_ftbbox, BBox, ());
+}
+
+void ftglGetGlyphBBox(FTGLglyph *g, float bounds[6])
+{
+ FTBBox ret = _ftglGetGlyphBBox(g);
+ FTPoint lower = ret.Lower(), upper = ret.Upper();
+ bounds[0] = lower.Xf(); bounds[1] = lower.Yf(); bounds[2] = lower.Zf();
+ bounds[3] = upper.Xf(); bounds[4] = upper.Yf(); bounds[5] = upper.Zf();
+}
+
+// FT_Error FTGlyph::Error() const;
+C_FUN(FT_Error, ftglGetGlyphError, (FTGLglyph *g), return -1, Error, ());
+
+FTGL_END_C_DECLS
+
diff --git a/src/ftgl/FTGlyph/FTGlyphImpl.h b/src/ftgl/FTGlyph/FTGlyphImpl.h
new file mode 100644
index 0000000..37ea96f
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTGlyphImpl.h
@@ -0,0 +1,64 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTGlyphImpl__
+#define __FTGlyphImpl__
+
+#include "FTGL/ftgl.h"
+
+class FTGlyphImpl
+{
+ friend class FTGlyph;
+
+ protected:
+ FTGlyphImpl(FT_GlyphSlot glyph, bool useDisplayList = true);
+
+ virtual ~FTGlyphImpl();
+
+ float Advance() const;
+
+ const FTBBox& BBox() const;
+
+ FT_Error Error() const;
+
+ /**
+ * The advance distance for this glyph
+ */
+ FTPoint advance;
+
+ /**
+ * The bounding box of this glyph.
+ */
+ FTBBox bBox;
+
+ /**
+ * Current error code. Zero means no error.
+ */
+ FT_Error err;
+};
+
+#endif // __FTGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTOutlineGlyph.cpp b/src/ftgl/FTGlyph/FTOutlineGlyph.cpp
new file mode 100644
index 0000000..48e11f7
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTOutlineGlyph.cpp
@@ -0,0 +1,149 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTOutlineGlyphImpl.h"
+#include "FTVectoriser.h"
+
+
+//
+// FTGLOutlineGlyph
+//
+
+
+FTOutlineGlyph::FTOutlineGlyph(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList) :
+ FTGlyph(new FTOutlineGlyphImpl(glyph, outset, useDisplayList))
+{}
+
+
+FTOutlineGlyph::~FTOutlineGlyph()
+{}
+
+
+const FTPoint& FTOutlineGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTOutlineGlyphImpl *myimpl = dynamic_cast<FTOutlineGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLOutlineGlyphImpl
+//
+
+
+FTOutlineGlyphImpl::FTOutlineGlyphImpl(FT_GlyphSlot glyph, float _outset,
+ bool useDisplayList)
+: FTGlyphImpl(glyph),
+ glList(0)
+{
+ if(ft_glyph_format_outline != glyph->format)
+ {
+ err = 0x14; // Invalid_Outline
+ return;
+ }
+
+ vectoriser = new FTVectoriser(glyph);
+
+ if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
+ {
+ delete vectoriser;
+ vectoriser = NULL;
+ return;
+ }
+
+ outset = _outset;
+
+ if(useDisplayList)
+ {
+ glList = glGenLists(1);
+ glNewList(glList, GL_COMPILE);
+
+ DoRender();
+
+ glEndList();
+
+ delete vectoriser;
+ vectoriser = NULL;
+ }
+}
+
+
+FTOutlineGlyphImpl::~FTOutlineGlyphImpl()
+{
+ if(glList)
+ {
+ glDeleteLists(glList, 1);
+ }
+ else if(vectoriser)
+ {
+ delete vectoriser;
+ }
+}
+
+
+const FTPoint& FTOutlineGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ glTranslatef(pen.Xf(), pen.Yf(), pen.Zf());
+ if(glList)
+ {
+ glCallList(glList);
+ }
+ else if(vectoriser)
+ {
+ DoRender();
+ }
+ glTranslatef(-pen.Xf(), -pen.Yf(), -pen.Zf());
+
+ return advance;
+}
+
+
+void FTOutlineGlyphImpl::DoRender()
+{
+ for(unsigned int c = 0; c < vectoriser->ContourCount(); ++c)
+ {
+ const FTContour* contour = vectoriser->Contour(c);
+
+ glBegin(GL_LINE_LOOP);
+ for(unsigned int i = 0; i < contour->PointCount(); ++i)
+ {
+ FTPoint point = FTPoint(contour->Point(i).X() + contour->Outset(i).X() * outset,
+ contour->Point(i).Y() + contour->Outset(i).Y() * outset,
+ 0);
+ glVertex2f(point.Xf() / 64.0f, point.Yf() / 64.0f);
+ }
+ glEnd();
+ }
+}
+
diff --git a/src/ftgl/FTGlyph/FTOutlineGlyphImpl.h b/src/ftgl/FTGlyph/FTOutlineGlyphImpl.h
new file mode 100644
index 0000000..ead4b12
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTOutlineGlyphImpl.h
@@ -0,0 +1,69 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTOutlineGlyphImpl__
+#define __FTOutlineGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTVectoriser;
+
+class FTOutlineGlyphImpl : public FTGlyphImpl
+{
+ friend class FTOutlineGlyph;
+
+ protected:
+ FTOutlineGlyphImpl(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList);
+
+ virtual ~FTOutlineGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Private rendering method.
+ */
+ void DoRender();
+
+ /**
+ * Private rendering variables.
+ */
+ FTVectoriser *vectoriser;
+
+ /**
+ * Private rendering variables.
+ */
+ float outset;
+
+ /**
+ * OpenGL display list
+ */
+ GLuint glList;
+};
+
+#endif // __FTOutlineGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTPixmapGlyph.cpp b/src/ftgl/FTGlyph/FTPixmapGlyph.cpp
new file mode 100644
index 0000000..5301e43
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPixmapGlyph.cpp
@@ -0,0 +1,139 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTPixmapGlyphImpl.h"
+
+
+//
+// FTGLPixmapGlyph
+//
+
+
+FTPixmapGlyph::FTPixmapGlyph(FT_GlyphSlot glyph) :
+ FTGlyph(new FTPixmapGlyphImpl(glyph))
+{}
+
+
+FTPixmapGlyph::~FTPixmapGlyph()
+{}
+
+
+const FTPoint& FTPixmapGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTPixmapGlyphImpl *myimpl = dynamic_cast<FTPixmapGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLPixmapGlyphImpl
+//
+
+
+FTPixmapGlyphImpl::FTPixmapGlyphImpl(FT_GlyphSlot glyph)
+: FTGlyphImpl(glyph),
+ destWidth(0),
+ destHeight(0),
+ data(0)
+{
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
+ if(err || ft_glyph_format_bitmap != glyph->format)
+ {
+ return;
+ }
+
+ FT_Bitmap bitmap = glyph->bitmap;
+
+ //check the pixel mode
+ //ft_pixel_mode_grays
+
+ int srcWidth = bitmap.width;
+ int srcHeight = bitmap.rows;
+
+ destWidth = srcWidth;
+ destHeight = srcHeight;
+
+ if(destWidth && destHeight)
+ {
+ data = new unsigned char[destWidth * destHeight * 2];
+ unsigned char* src = bitmap.buffer;
+
+ unsigned char* dest = data + ((destHeight - 1) * destWidth * 2);
+ size_t destStep = destWidth * 2 * 2;
+
+ for(int y = 0; y < srcHeight; ++y)
+ {
+ for(int x = 0; x < srcWidth; ++x)
+ {
+ *dest++ = static_cast<unsigned char>(255);
+ *dest++ = *src++;
+ }
+ dest -= destStep;
+ }
+
+ destHeight = srcHeight;
+ }
+
+ pos.X(glyph->bitmap_left);
+ pos.Y(srcHeight - glyph->bitmap_top);
+}
+
+
+FTPixmapGlyphImpl::~FTPixmapGlyphImpl()
+{
+ delete [] data;
+}
+
+
+const FTPoint& FTPixmapGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ if(data)
+ {
+ float dx, dy;
+
+ dx = floor(pen.Xf() + pos.Xf());
+ dy = floor(pen.Yf() - pos.Yf());
+
+ glBitmap(0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+
+ glDrawPixels(destWidth, destHeight, GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_BYTE, (const GLvoid*)data);
+ glBitmap(0, 0, 0.0f, 0.0f, -dx, -dy, (const GLubyte*)0);
+ }
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTPixmapGlyphImpl.h b/src/ftgl/FTGlyph/FTPixmapGlyphImpl.h
new file mode 100644
index 0000000..8331469
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPixmapGlyphImpl.h
@@ -0,0 +1,67 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTPixmapGlyphImpl__
+#define __FTPixmapGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTPixmapGlyphImpl : public FTGlyphImpl
+{
+ friend class FTPixmapGlyph;
+
+ protected:
+ FTPixmapGlyphImpl(FT_GlyphSlot glyph);
+
+ virtual ~FTPixmapGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * The width of the glyph 'image'
+ */
+ int destWidth;
+
+ /**
+ * The height of the glyph 'image'
+ */
+ int destHeight;
+
+ /**
+ * Vector from the pen position to the topleft corner of the pixmap
+ */
+ FTPoint pos;
+
+ /**
+ * Pointer to the 'image' data
+ */
+ unsigned char* data;
+
+};
+
+#endif // __FTPixmapGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTPolygonGlyph.cpp b/src/ftgl/FTGlyph/FTPolygonGlyph.cpp
new file mode 100644
index 0000000..6db3581
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPolygonGlyph.cpp
@@ -0,0 +1,156 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Éric Beets <ericbeets@free.fr>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTPolygonGlyphImpl.h"
+#include "FTVectoriser.h"
+
+
+//
+// FTGLPolyGlyph
+//
+
+
+FTPolygonGlyph::FTPolygonGlyph(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList) :
+ FTGlyph(new FTPolygonGlyphImpl(glyph, outset, useDisplayList))
+{}
+
+
+FTPolygonGlyph::~FTPolygonGlyph()
+{}
+
+
+const FTPoint& FTPolygonGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTPolygonGlyphImpl *myimpl = dynamic_cast<FTPolygonGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLPolyGlyphImpl
+//
+
+
+FTPolygonGlyphImpl::FTPolygonGlyphImpl(FT_GlyphSlot glyph, float _outset,
+ bool useDisplayList)
+: FTGlyphImpl(glyph),
+ glList(0)
+{
+ if(ft_glyph_format_outline != glyph->format)
+ {
+ err = 0x14; // Invalid_Outline
+ return;
+ }
+
+ vectoriser = new FTVectoriser(glyph);
+
+ if((vectoriser->ContourCount() < 1) || (vectoriser->PointCount() < 3))
+ {
+ delete vectoriser;
+ vectoriser = NULL;
+ return;
+ }
+
+
+ hscale = glyph->face->size->metrics.x_ppem * 64;
+ vscale = glyph->face->size->metrics.y_ppem * 64;
+ outset = _outset;
+
+ if(useDisplayList)
+ {
+ glList = glGenLists(1);
+ glNewList(glList, GL_COMPILE);
+
+ DoRender();
+
+ glEndList();
+
+ delete vectoriser;
+ vectoriser = NULL;
+ }
+}
+
+
+FTPolygonGlyphImpl::~FTPolygonGlyphImpl()
+{
+ if(glList)
+ {
+ glDeleteLists(glList, 1);
+ }
+ else if(vectoriser)
+ {
+ delete vectoriser;
+ }
+}
+
+
+const FTPoint& FTPolygonGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ glTranslatef(pen.Xf(), pen.Yf(), pen.Zf());
+ if(glList)
+ {
+ glCallList(glList);
+ }
+ else if(vectoriser)
+ {
+ DoRender();
+ }
+ glTranslatef(-pen.Xf(), -pen.Yf(), -pen.Zf());
+
+ return advance;
+}
+
+
+void FTPolygonGlyphImpl::DoRender()
+{
+ vectoriser->MakeMesh(1.0, 1, outset);
+
+ const FTMesh *mesh = vectoriser->GetMesh();
+
+ for(unsigned int t = 0; t < mesh->TesselationCount(); ++t)
+ {
+ const FTTesselation* subMesh = mesh->Tesselation(t);
+ unsigned int polygonType = subMesh->PolygonType();
+
+ glBegin(polygonType);
+ for(unsigned int i = 0; i < subMesh->PointCount(); ++i)
+ {
+ FTPoint point = subMesh->Point(i);
+ glTexCoord2f(point.Xf() / hscale, point.Yf() / vscale);
+ glVertex3f(point.Xf() / 64.0f, point.Yf() / 64.0f, 0.0f);
+ }
+ glEnd();
+ }
+}
+
diff --git a/src/ftgl/FTGlyph/FTPolygonGlyphImpl.h b/src/ftgl/FTGlyph/FTPolygonGlyphImpl.h
new file mode 100644
index 0000000..e353391
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTPolygonGlyphImpl.h
@@ -0,0 +1,66 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTPolygonGlyphImpl__
+#define __FTPolygonGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTVectoriser;
+
+class FTPolygonGlyphImpl : public FTGlyphImpl
+{
+ friend class FTPolygonGlyph;
+
+ public:
+ FTPolygonGlyphImpl(FT_GlyphSlot glyph, float outset,
+ bool useDisplayList);
+
+ virtual ~FTPolygonGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * Private rendering method.
+ */
+ void DoRender();
+
+ /**
+ * Private rendering variables.
+ */
+ unsigned int hscale, vscale;
+ FTVectoriser *vectoriser;
+ float outset;
+
+ /**
+ * OpenGL display list
+ */
+ GLuint glList;
+};
+
+#endif // __FTPolygonGlyphImpl__
+
diff --git a/src/ftgl/FTGlyph/FTTextureGlyph.cpp b/src/ftgl/FTGlyph/FTTextureGlyph.cpp
new file mode 100644
index 0000000..a9cf2e8
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTTextureGlyph.cpp
@@ -0,0 +1,153 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#include "FTGL/ftgl.h"
+
+#include "FTInternals.h"
+#include "FTTextureGlyphImpl.h"
+
+
+//
+// FTGLTextureGlyph
+//
+
+
+FTTextureGlyph::FTTextureGlyph(FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height) :
+ FTGlyph(new FTTextureGlyphImpl(glyph, id, xOffset, yOffset, width, height))
+{}
+
+
+FTTextureGlyph::~FTTextureGlyph()
+{}
+
+
+const FTPoint& FTTextureGlyph::Render(const FTPoint& pen, int renderMode)
+{
+ FTTextureGlyphImpl *myimpl = dynamic_cast<FTTextureGlyphImpl *>(impl);
+ return myimpl->RenderImpl(pen, renderMode);
+}
+
+
+//
+// FTGLTextureGlyphImpl
+//
+
+
+GLint FTTextureGlyphImpl::activeTextureID = 0;
+
+FTTextureGlyphImpl::FTTextureGlyphImpl(FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height)
+: FTGlyphImpl(glyph),
+ destWidth(0),
+ destHeight(0),
+ glTextureID(id)
+{
+ /* FIXME: need to propagate the render mode all the way down to
+ * here in order to get FT_RENDER_MODE_MONO aliased fonts.
+ */
+
+ err = FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL);
+ if(err || glyph->format != ft_glyph_format_bitmap)
+ {
+ return;
+ }
+
+ FT_Bitmap bitmap = glyph->bitmap;
+
+ destWidth = bitmap.width;
+ destHeight = bitmap.rows;
+
+ 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);
+
+ glBindTexture(GL_TEXTURE_2D, glTextureID);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
+
+ glPopClientAttrib();
+ }
+
+
+// 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));
+
+ corner = FTPoint(glyph->bitmap_left, glyph->bitmap_top);
+}
+
+
+FTTextureGlyphImpl::~FTTextureGlyphImpl()
+{}
+
+
+const FTPoint& FTTextureGlyphImpl::RenderImpl(const FTPoint& pen,
+ int renderMode)
+{
+ float dx, dy;
+
+ if(activeTextureID != glTextureID)
+ {
+ glBindTexture(GL_TEXTURE_2D, (GLuint)glTextureID);
+ activeTextureID = glTextureID;
+ }
+
+ dx = floor(pen.Xf() + corner.Xf());
+ dy = floor(pen.Yf() + corner.Yf());
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(uv[0].Xf(), uv[0].Yf());
+ glVertex2f(dx, dy);
+
+ glTexCoord2f(uv[0].Xf(), uv[1].Yf());
+ glVertex2f(dx, dy - destHeight);
+
+ glTexCoord2f(uv[1].Xf(), uv[1].Yf());
+ glVertex2f(dx + destWidth, dy - destHeight);
+
+ glTexCoord2f(uv[1].Xf(), uv[0].Yf());
+ glVertex2f(dx + destWidth, dy);
+ glEnd();
+
+ return advance;
+}
+
diff --git a/src/ftgl/FTGlyph/FTTextureGlyphImpl.h b/src/ftgl/FTGlyph/FTTextureGlyphImpl.h
new file mode 100644
index 0000000..793af04
--- /dev/null
+++ b/src/ftgl/FTGlyph/FTTextureGlyphImpl.h
@@ -0,0 +1,88 @@
+/*
+ * FTGL - OpenGL font library
+ *
+ * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
+ * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * 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.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __FTTextureGlyphImpl__
+#define __FTTextureGlyphImpl__
+
+#include "FTGlyphImpl.h"
+
+class FTTextureGlyphImpl : public FTGlyphImpl
+{
+ friend class FTTextureGlyph;
+ friend class FTTextureFontImpl;
+
+ protected:
+ FTTextureGlyphImpl(FT_GlyphSlot glyph, int id, int xOffset,
+ int yOffset, int width, int height);
+
+ virtual ~FTTextureGlyphImpl();
+
+ virtual const FTPoint& RenderImpl(const FTPoint& pen, int renderMode);
+
+ private:
+ /**
+ * 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; }
+
+ /**
+ * The width of the glyph 'image'
+ */
+ int destWidth;
+
+ /**
+ * The height of the glyph 'image'
+ */
+ int destHeight;
+
+ /**
+ * Vector from the pen position to the topleft corner of the pixmap
+ */
+ FTPoint corner;
+
+ /**
+ * The texture co-ords of this glyph within the texture.
+ */
+ FTPoint uv[2];
+
+ /**
+ * The texture index that this glyph is contained in.
+ */
+ int glTextureID;
+
+ /**
+ * 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.
+ */
+ static GLint activeTextureID;
+};
+
+#endif // __FTTextureGlyphImpl__
+