double load_texture_special(void *data_, int width, int height)
{
char *data = (char*)data_;
/* convert the texture to have a width that is a power of 2 */
int new_width=1;
while (new_width < width)
{
new_width <<= 1;
};
printf("from %d to %d\n", width, new_width);
int pad = new_width-width;
printf("pad=%d\n", pad);
char *buffer = (char*) malloc(new_width*height);
if (buffer == NULL) return;
int count = height;
while (count--)
{
int cnt = width;
while (cnt--)
{
*buffer++ = *data++;
};
cnt = pad;
while (cnt--)
{
*buffer++ = 255;
};
};
glTexImage2D(GL_TEXTURE_2D,
0,
GL_ALPHA,
new_width,
height,
0,
GL_ALPHA,
GL_UNSIGNED_BYTE,
buffer);
/* return the old-to-new width ratio */
double ret = (double)width/(double)new_width;
return ret;
};
Then the function that actually displays the text is:
void text_overlay(MEOBJECT *object)
{
METEXT *text = (METEXT*)object;
char *string = text->str;
int penx, peny;
penx = text->x;
peny = text->y;
glColor4f(text->color.x, text->color.y, text->color.z, 1.0);
while (*string != 0)
{
MEGLYPH *glyph = get_character_glyph(text->font, *string++);
if (glyph == NULL) continue; /* skip all characters not included in the font */
glBindTexture(GL_TEXTURE_2D, glyph->name);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBegin(GL_TRIANGLES);
glTexCoord2f(0.0, 1.0);
glVertex2i(penx, peny+text->font->height);
glTexCoord2f(glyph->wc, 1.0);
glVertex2i(penx+glyph->width, peny+text->font->height);
glTexCoord2f(glyph->wc, 0.0);
glVertex2i(penx+glyph->width, peny);
glTexCoord2f(glyph->wc, 0.0);
glVertex2i(penx+glyph->width, peny);
glTexCoord2f(0.0, 0.0);
glVertex2i(penx, peny);
glTexCoord2f(0.0, 1.0);
glVertex2i(penx, peny+text->font->height);
glEnd();
penx += glyph->width;
};
};
Where glyph->wc is the width-to-new-width ratio (the rightmost X texture coordinate). But the function just renders a set of vertical bars! If I don't resize to a power-of-2 width, then you can see some of the letters, but they are either half-cut, curved, distorted, or otherwise unreadable. Does anyone have any idea of what could be going on here?