================================================================================
*/
-cvar_t r_font_disable_freetype = {CVAR_SAVE, "r_font_disable_freetype", "1", "disable freetype support for fonts entirely"};
-cvar_t r_font_use_alpha_textures = {CVAR_SAVE, "r_font_use_alpha_textures", "0", "use alpha-textures for font rendering, this should safe memory"};
-cvar_t r_font_size_snapping = {CVAR_SAVE, "r_font_size_snapping", "1", "stick to good looking font sizes whenever possible - bad when the mod doesn't support it!"};
-cvar_t r_font_kerning = {CVAR_SAVE, "r_font_kerning", "1", "Use kerning if available"};
-cvar_t r_font_diskcache = {CVAR_SAVE, "r_font_diskcache", "0", "save font textures to disk for future loading rather than generating them every time"};
-cvar_t r_font_compress = {CVAR_SAVE, "r_font_compress", "0", "use texture compression on font textures to save video memory"};
-cvar_t r_font_nonpoweroftwo = {CVAR_SAVE, "r_font_nonpoweroftwo", "1", "use nonpoweroftwo textures for font (saves memory, potentially slower)"};
-cvar_t developer_font = {CVAR_SAVE, "developer_font", "0", "prints debug messages about fonts"};
+cvar_t r_font_disable_freetype = {CVAR_CLIENT | CVAR_SAVE, "r_font_disable_freetype", "1", "disable freetype support for fonts entirely"};
+cvar_t r_font_use_alpha_textures = {CVAR_CLIENT | CVAR_SAVE, "r_font_use_alpha_textures", "0", "use alpha-textures for font rendering, this should safe memory"};
+cvar_t r_font_size_snapping = {CVAR_CLIENT | CVAR_SAVE, "r_font_size_snapping", "1", "stick to good looking font sizes whenever possible - bad when the mod doesn't support it!"};
+cvar_t r_font_kerning = {CVAR_CLIENT | CVAR_SAVE, "r_font_kerning", "1", "Use kerning if available"};
+cvar_t r_font_diskcache = {CVAR_CLIENT | CVAR_SAVE, "r_font_diskcache", "0", "save font textures to disk for future loading rather than generating them every time"};
+cvar_t r_font_compress = {CVAR_CLIENT | CVAR_SAVE, "r_font_compress", "0", "use texture compression on font textures to save video memory"};
+cvar_t r_font_nonpoweroftwo = {CVAR_CLIENT | CVAR_SAVE, "r_font_nonpoweroftwo", "1", "use nonpoweroftwo textures for font (saves memory, potentially slower)"};
+cvar_t developer_font = {CVAR_CLIENT | CVAR_SAVE, "developer_font", "0", "prints debug messages about fonts"};
#ifndef DP_FREETYPE_STATIC
if (qFT_Init_FreeType(&font_ft2lib))
{
- Con_Print("ERROR: Failed to initialize the FreeType2 library!\n");
+ Con_Error("ERROR: Failed to initialize the FreeType2 library!\n");
Font_CloseLibrary();
return;
}
font_mempool = Mem_AllocPool("FONT", 0, NULL);
if (!font_mempool)
{
- Con_Print("ERROR: Failed to allocate FONT memory pool!\n");
+ Con_Error("ERROR: Failed to allocate FONT memory pool!\n");
Font_CloseLibrary();
return;
}
break;
if (! (fb = Font_Alloc()) )
{
- Con_Printf("Failed to allocate font for fallback %i of font %s\n", i, name);
+ Con_Errorf("Failed to allocate font for fallback %i of font %s\n", i, name);
break;
}
if(!FS_FileExists(va(vabuf, sizeof(vabuf), "%s.png", dpfnt->fallbacks[i])))
if(!FS_FileExists(va(vabuf, sizeof(vabuf), "%s.jpg", dpfnt->fallbacks[i])))
if(!FS_FileExists(va(vabuf, sizeof(vabuf), "%s.pcx", dpfnt->fallbacks[i])))
- Con_Printf("Failed to load font %s for fallback %i of font %s\n", dpfnt->fallbacks[i], i, name);
+ Con_Errorf("Failed to load font %s for fallback %i of font %s\n", dpfnt->fallbacks[i], i, name);
Mem_Free(fb);
continue;
}
}
if (!count)
{
- Con_Printf("Failed to allocate font for fallback %i of font %s\n", i, name);
+ Con_Errorf("Failed to allocate font for fallback %i of font %s\n", i, name);
Font_UnloadFont(fb);
Mem_Free(fb);
break;
{
if (!r_font_disable_freetype.integer)
{
- Con_Printf("WARNING: can't open load font %s\n"
+ Con_Warnf("WARNING: can't open load font %s\n"
"You need the FreeType2 DLL to load font files\n",
name);
}
namelen = strlen(name);
if (namelen + 5 > sizeof(filename))
{
- Con_Printf("WARNING: too long font name. Cannot load this.\n");
+ Con_Warnf("WARNING: too long font name. Cannot load this.\n");
return false;
}
status = qFT_New_Memory_Face(font_ft2lib, (FT_Bytes)data, datasize, _face, (FT_Face*)&font->face);
if (status && _face != 0)
{
- Con_Printf("Failed to load face %i of %s. Falling back to face 0\n", _face, name);
+ Con_Errorf("Failed to load face %i of %s. Falling back to face 0\n", _face, name);
_face = 0;
status = qFT_New_Memory_Face(font_ft2lib, (FT_Bytes)data, datasize, _face, (FT_Face*)&font->face);
}
font->data = data;
if (status)
{
- Con_Printf("ERROR: can't create face for %s\n"
+ Con_Errorf("ERROR: can't create face for %s\n"
"Error %i\n", // TODO: error strings
name, status);
Font_UnloadFont(font);
args.memory_base = (const FT_Byte*)font->attachments[i].data;
args.memory_size = font->attachments[i].size;
if (qFT_Attach_Stream((FT_Face)font->face, &args))
- Con_Printf("Failed to add attachment %u to %s\n", (unsigned)i, font->name);
+ Con_Errorf("Failed to add attachment %u to %s\n", (unsigned)i, font->name);
}
strlcpy(font->name, name, sizeof(font->name));
memset(&temp, 0, sizeof(temp));
temp.size = size;
temp.glyphSize = size*2 + max(gpad_l + gpad_r, gpad_t + gpad_b);
- if (!(r_font_nonpoweroftwo.integer && vid.support.arb_texture_non_power_of_two))
+ if (!r_font_nonpoweroftwo.integer)
temp.glyphSize = CeilPowerOf2(temp.glyphSize);
temp.sfx = (1.0/64.0)/(double)size;
temp.sfy = (1.0/64.0)/(double)size;
temp.intSize = -1; // negative value: LoadMap must search now :)
if (!Font_LoadMap(font, &temp, 0, &fmap))
{
- Con_Printf("ERROR: can't load the first character map for %s\n"
+ Con_Errorf("ERROR: can't load the first character map for %s\n"
"This is fatal\n",
font->name);
Font_UnloadFont(font);
if (!Font_SetSize(font, fmap->intSize, fmap->intSize))
{
// this deserves an error message
- Con_Printf("Failed to get kerning for %s\n", font->name);
+ Con_Errorf("Failed to get kerning for %s\n", font->name);
return false;
}
ul = qFT_Get_Char_Index((FT_Face)font->face, left);
{
if (!Font_SetSize(font, intSize, intSize))
{
- Con_Printf("ERROR: can't set size for font %s: %f ((%f))\n", font->name, size, intSize);
+ Con_Errorf("ERROR: can't set size for font %s: %f ((%f))\n", font->name, size, intSize);
return -1;
}
if ((fontface->size->metrics.height>>6) <= size)
return intSize;
if (intSize < 2)
{
- Con_Printf("ERROR: no appropriate size found for font %s: %f\n", font->name, size);
+ Con_Errorf("ERROR: no appropriate size found for font %s: %f\n", font->name, size);
return -1;
}
--intSize;
if (!font->image_font && !Font_SetSize(font, mapstart->intSize, mapstart->intSize))
{
- Con_Printf("ERROR: can't set sizes for font %s: %f\n", font->name, mapstart->size);
+ Con_Errorf("ERROR: can't set sizes for font %s: %f\n", font->name, mapstart->size);
return false;
}
map = (ft2_font_map_t *)Mem_Alloc(font_mempool, sizeof(ft2_font_map_t));
if (!map)
{
- Con_Printf("ERROR: Out of memory when loading fontmap for %s\n", font->name);
+ Con_Errorf("ERROR: Out of memory when loading fontmap for %s\n", font->name);
return false;
}
(unsigned) mapidx);
// create a cachepic_t from the data now, or reuse an existing one
- map->pic = Draw_CachePic_Flags(map_identifier, CACHEPICFLAG_QUIET);
if (developer_font.integer)
- {
- if (map->pic->tex == r_texture_notexture)
- Con_Printf("Generating font map %s (size: %.1f MB)\n", map_identifier, mapstart->glyphSize * (256 * 4 / 1048576.0) * mapstart->glyphSize);
- else
- Con_Printf("Using cached font map %s (size: %.1f MB)\n", map_identifier, mapstart->glyphSize * (256 * 4 / 1048576.0) * mapstart->glyphSize);
- }
+ Con_Printf("Generating font map %s (size: %.1f MB)\n", map_identifier, mapstart->glyphSize * (256 * 4 / 1048576.0) * mapstart->glyphSize);
Font_Postprocess(font, NULL, 0, bytesPerPixel, mapstart->size*2, mapstart->size*2, &gpad_l, &gpad_r, &gpad_t, &gpad_b);
map->sfy = mapstart->sfy;
pitch = map->glyphSize * FONT_CHARS_PER_LINE * bytesPerPixel;
- if (map->pic->tex == r_texture_notexture)
+ data = (unsigned char *)Mem_Alloc(font_mempool, (FONT_CHAR_LINES * map->glyphSize) * pitch);
+ if (!data)
{
- data = (unsigned char *)Mem_Alloc(font_mempool, (FONT_CHAR_LINES * map->glyphSize) * pitch);
- if (!data)
- {
- Con_Printf("ERROR: Failed to allocate memory for font %s size %g\n", font->name, map->size);
- Mem_Free(map);
- return false;
- }
- // initialize as white texture with zero alpha
- tp = 0;
- while (tp < (FONT_CHAR_LINES * map->glyphSize) * pitch)
+ Con_Errorf("ERROR: Failed to allocate memory for font %s size %g\n", font->name, map->size);
+ Mem_Free(map);
+ return false;
+ }
+ // initialize as white texture with zero alpha
+ tp = 0;
+ while (tp < (FONT_CHAR_LINES * map->glyphSize) * pitch)
+ {
+ if (bytesPerPixel == 4)
{
- if (bytesPerPixel == 4)
- {
- data[tp++] = 0xFF;
- data[tp++] = 0xFF;
- data[tp++] = 0xFF;
- }
- data[tp++] = 0x00;
+ data[tp++] = 0xFF;
+ data[tp++] = 0xFF;
+ data[tp++] = 0xFF;
}
+ data[tp++] = 0x00;
}
memset(map->width_of, 0, sizeof(map->width_of));
h = bmp->rows;
if (w > (map->glyphSize - gpad_l - gpad_r) || h > (map->glyphSize - gpad_t - gpad_b)) {
- Con_Printf("WARNING: Glyph %lu is too big in font %s, size %g: %i x %i\n", ch, font->name, map->size, w, h);
+ Con_Warnf("WARNING: Glyph %lu is too big in font %s, size %g: %i x %i\n", ch, font->name, map->size, w, h);
if (w > map->glyphSize)
w = map->glyphSize - gpad_l - gpad_r;
if (h > map->glyphSize)
if (developer_font.integer)
Con_DPrintf("glyphinfo: Pixel Mode: Unknown: %i\n", bmp->pixel_mode);
Mem_Free(data);
- Con_Printf("ERROR: Unrecognized pixel mode for font %s size %f: %i\n", font->name, mapstart->size, bmp->pixel_mode);
+ Con_Errorf("ERROR: Unrecognized pixel mode for font %s size %f: %i\n", font->name, mapstart->size, bmp->pixel_mode);
return false;
}
for (y = 0; y < h; ++y)
map->glyphs[mapch].image = false;
}
- if (map->pic->tex == r_texture_notexture)
{
int w = map->glyphSize * FONT_CHARS_PER_LINE;
int h = map->glyphSize * FONT_CHAR_LINES;
- rtexture_t *tex;
- // abuse the Draw_CachePic system to keep track of this texture
- tex = R_LoadTexture2D(drawtexturepool, map_identifier, w, h, data, r_font_use_alpha_textures.integer ? TEXTYPE_ALPHA : TEXTYPE_RGBA, TEXF_ALPHA | (r_font_compress.integer > 0 ? TEXF_COMPRESS : 0), -1, NULL);
- // if tex is NULL for any reason, the pic->tex will remain set to r_texture_notexture
- if (tex)
- map->pic->tex = tex;
+ // update the pic returned by Draw_CachePic_Flags earlier to contain our texture
+ map->pic = Draw_NewPic(map_identifier, w, h, data, r_font_use_alpha_textures.integer ? TEXTYPE_ALPHA : TEXTYPE_RGBA, TEXF_ALPHA | TEXF_CLAMP | (r_font_compress.integer > 0 ? TEXF_COMPRESS : 0));
if (r_font_diskcache.integer >= 1)
{
}
Image_WriteTGABGRA(va(vabuf, sizeof(vabuf), "%s.tga", map_identifier), w, h, data);
#ifndef USE_GLES2
- if (r_font_compress.integer && qglGetCompressedTexImageARB && tex)
- R_SaveTextureDDSFile(tex, va(vabuf, sizeof(vabuf), "dds/%s.dds", map_identifier), r_texture_dds_save.integer < 2, true);
+ if (r_font_compress.integer && Draw_IsPicLoaded(map->pic))
+ R_SaveTextureDDSFile(Draw_GetPicTexture(map->pic), va(vabuf, sizeof(vabuf), "dds/%s.dds", map_identifier), r_texture_dds_save.integer < 2, true);
#endif
}
}
if(data)
Mem_Free(data);
- if (map->pic->tex == r_texture_notexture)
+ if (!Draw_IsPicLoaded(map->pic))
{
// if the first try isn't successful, keep it with a broken texture
// otherwise we retry to load it every single frame where ft2 rendering is used
// this would be bad...
// only `data' must be freed
- Con_Printf("ERROR: Failed to generate texture for font %s size %f map %lu\n",
+ Con_Errorf("ERROR: Failed to generate texture for font %s size %f map %lu\n",
font->name, mapstart->size, mapidx);
return false;
}