(zr_common.c) Cleanups

This commit is contained in:
twinaphex 2016-03-22 01:20:41 +01:00
parent ddb912b373
commit b00878a595

View File

@ -131,24 +131,25 @@ struct zr_user_font zr_common_font(
{
int glyph_count;
int img_width, img_height;
void *img, *tmp;
size_t ttf_size;
size_t tmp_size, img_size;
struct texture_image ti;
struct zr_recti custom;
struct zr_font_config config;
struct zr_font_glyph *glyphes;
struct zr_baked_font baked_font;
struct zr_user_font user_font;
struct zr_recti custom;
void *img_rgba = NULL;
char *ttf_blob = NULL;
const char *custom_data = "....";
memset(&baked_font, 0, sizeof(baked_font));
memset(&user_font, 0, sizeof(user_font));
memset(&custom, 0, sizeof(custom));
{
struct texture_image ti;
/* bake and upload font texture */
struct zr_font_config config;
void *img, *tmp;
size_t ttf_size;
size_t tmp_size, img_size;
const char *custom_data = "....";
char *ttf_blob = zr_common_file_load(path, &ttf_size);
ttf_blob = zr_common_file_load(path, &ttf_size);
/* setup font configuration */
memset(&config, 0, sizeof(config));
@ -165,12 +166,14 @@ struct zr_user_font zr_common_font(
/* query needed amount of memory for the font baking process */
zr_font_bake_memory(&tmp_size, &glyph_count, &config, 1);
glyphes = (struct zr_font_glyph*)
calloc(sizeof(struct zr_font_glyph), (size_t)glyph_count);
tmp = calloc(1, tmp_size);
/* pack all glyphes and return needed image width, height and memory size*/
custom.w = 2; custom.h = 2;
custom.w = 2;
custom.h = 2;
zr_font_bake_pack(&img_size,
&img_width,&img_height,&custom,tmp,tmp_size,&config, 1);
@ -181,13 +184,12 @@ struct zr_user_font zr_common_font(
zr_font_bake_custom_data(img,
img_width, img_height, custom, custom_data, 2, 2, '.', 'X');
{
/* convert alpha8 image into rgba8 image */
void *img_rgba = calloc(4, (size_t)(img_height * img_width));
img_rgba = calloc(4, (size_t)(img_height * img_width));
zr_font_bake_convert(img_rgba, img_width, img_height, img);
free(img);
img = img_rgba;
}
/* upload baked font image */
ti.pixels = (uint32_t*)img;
@ -200,7 +202,6 @@ struct zr_user_font zr_common_font(
free(ttf_blob);
free(tmp);
free(img);
}
/* default white pixel in a texture which is needed to draw primitives */
dev->null.texture.id = (int)dev->font_tex;