mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Fix issue #406: Empty glyphs cause some ATI cards to crash in Font::addGlyph().
This commit is contained in:
@@ -95,17 +95,10 @@ namespace opengl
|
|||||||
|
|
||||||
Font::Glyph * Font::addGlyph(int glyph)
|
Font::Glyph * Font::addGlyph(int glyph)
|
||||||
{
|
{
|
||||||
Glyph * g = new Glyph;
|
|
||||||
g->list = glGenLists(1);
|
|
||||||
if (g->list == 0)
|
|
||||||
{ // opengl failed to generate the list
|
|
||||||
delete g;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
|
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
|
||||||
g->spacing = gd->getAdvance();
|
|
||||||
int w = gd->getWidth();
|
int w = gd->getWidth();
|
||||||
int h = gd->getHeight();
|
int h = gd->getHeight();
|
||||||
|
|
||||||
if (texture_x + w + TEXTURE_PADDING > TEXTURE_WIDTH)
|
if (texture_x + w + TEXTURE_PADDING > TEXTURE_WIDTH)
|
||||||
{ // out of space - new row!
|
{ // out of space - new row!
|
||||||
texture_x = TEXTURE_PADDING;
|
texture_x = TEXTURE_PADDING;
|
||||||
@@ -116,6 +109,21 @@ namespace opengl
|
|||||||
{ // totally out of space - new texture!
|
{ // totally out of space - new texture!
|
||||||
createTexture();
|
createTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Glyph * g = new Glyph;
|
||||||
|
g->list = g->texture = 0;
|
||||||
|
g->spacing = gd->getAdvance();
|
||||||
|
|
||||||
|
// don't waste space for empty glyphs. also fixes a division by zero bug with ati drivers
|
||||||
|
if (w > 0 && h > 0)
|
||||||
|
{
|
||||||
|
g->list = glGenLists(1);
|
||||||
|
if (0 == g->list)
|
||||||
|
{
|
||||||
|
delete g;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GLuint t = textures.back();
|
GLuint t = textures.back();
|
||||||
bindTexture(t);
|
bindTexture(t);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
|
glTexSubImage2D(GL_TEXTURE_2D, 0, texture_x, texture_y, w, h, (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA), GL_UNSIGNED_BYTE, gd->getData());
|
||||||
@@ -146,11 +154,14 @@ namespace opengl
|
|||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
delete q;
|
delete q;
|
||||||
delete gd;
|
}
|
||||||
|
|
||||||
|
if (w > 0)
|
||||||
texture_x += (w + TEXTURE_PADDING);
|
texture_x += (w + TEXTURE_PADDING);
|
||||||
|
if (h > 0)
|
||||||
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
|
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
|
||||||
|
|
||||||
|
delete gd;
|
||||||
glyphs[glyph] = g;
|
glyphs[glyph] = g;
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
@@ -205,12 +216,16 @@ namespace opengl
|
|||||||
{
|
{
|
||||||
Glyph * glyph = glyphs[character];
|
Glyph * glyph = glyphs[character];
|
||||||
if (!glyph) glyph = addGlyph(character);
|
if (!glyph) glyph = addGlyph(character);
|
||||||
|
|
||||||
|
if (0 != glyph->texture)
|
||||||
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
|
glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
|
||||||
bindTexture(glyph->texture);
|
bindTexture(glyph->texture);
|
||||||
glCallList(glyph->list);
|
glCallList(glyph->list);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Font::getWidth(const std::string & line)
|
int Font::getWidth(const std::string & line)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user