use bitmap width for texturing
authorDerek Foreman <manmower@gmail.com>
Thu, 29 May 2003 23:08:26 +0000 (23:08 +0000)
committerDerek Foreman <manmower@gmail.com>
Thu, 29 May 2003 23:08:26 +0000 (23:08 +0000)
glft/font.h
glft/render.c

index 2494358e7caf8f8c703376fdb0046487ce3eee97..12fa6d0f26917cad0671274b459c4b680d5928e9 100644 (file)
@@ -58,6 +58,7 @@ struct GlftGlyph {
     int height;
 
     int padx, pady;
+    int texw, texh;
 };
 
 /*! Takes a character in UTF-8 encoding and returns an OpenGL display list
index 3180d5f226d46f0e2532c10e8f93ddc85bfce4eb..fa7c33ecd3c2d40a960e2281025adcca8ab11a6c 100644 (file)
@@ -17,6 +17,9 @@ void GlftRenderGlyph(FT_Face face, struct GlftGlyph *g)
     err = FT_Render_Glyph(slot, ft_render_mode_normal);
         g_assert(!err);
 
+    g->texw = slot->bitmap.width;
+    g->texh = slot->bitmap.rows;
+
     g->padx = 1;
     while (g->padx < slot->bitmap.width)
        g->padx <<= 1;
@@ -26,6 +29,7 @@ void GlftRenderGlyph(FT_Face face, struct GlftGlyph *g)
        g->pady <<= 1;
 
     padbuf = g_new0(unsigned char, g->padx * g->pady);
+printf("glyph rendered to %d wide\n", slot->bitmap.width);
     for (i = 0; i < slot->bitmap.rows; i++)
         memcpy(padbuf + i*g->padx,
                slot->bitmap.buffer + i*slot->bitmap.width,
@@ -60,22 +64,23 @@ void GlftRenderString(struct GlftFont *font, const char *str, int bytes,
     while (c - str < bytes) {
         g = GlftFontGlyph(font, c);
         if (g) {
+printf("glyph width %d(%d)\n", g->width, g->x);
             glTranslatef(GlftFontAdvance(font, p, g), 0.0, 0.0);
             glBindTexture(GL_TEXTURE_2D, g->tnum);
             glBegin(GL_QUADS);
             glColor3f(0.0, 0.0, 0.0);
 
-            glTexCoord2f(0, g->height/(float)g->pady);
+            glTexCoord2f(0, g->texh/(float)g->pady);
             glVertex2i(0, 0);
 
-            glTexCoord2f(g->width/(float)g->padx, g->height/(float)g->pady);
-            glVertex2i(0 + g->width, 0);
+            glTexCoord2f(g->texw/(float)g->padx, g->texh/(float)g->pady);
+            glVertex2i(0 + g->texw, 0);
 
-            glTexCoord2f(g->width/(float)g->padx, 0);
-            glVertex2i(0 + g->width, 0 + g->height);
+            glTexCoord2f(g->texw/(float)g->padx, 0);
+            glVertex2i(0 + g->texw, 0 + g->texh);
 
             glTexCoord2f(0, 0);
-            glVertex2i(0, 0 + g->height);
+            glVertex2i(0, 0 + g->texh);
             glEnd();
         } else
             glTranslatef(font->max_advance_width, 0.0, 0.0);