Plaster

clike
int fond_load_internal(struct fond_font *font, unsigned char *fontdata, stbtt_pack_range *range){ stbtt_pack_context context = {0}; unsigned char atlasdata[font->width*font->height] = {0}; if(!atlasdata){ errcode = OUT_OF_MEMORY; goto fond_load_internal_cleanup; } if(!stbtt_PackBegin(&context, atlasdata, font->width, font->height, 0, 1, 0)){ errcode = FONT_PACK_FAILED; goto fond_load_internal_cleanup; } stbtt_PackSetOversampling(&context, font->oversample_h, font->oversample_v); if(!stbtt_PackFontRanges(&context, fontdata, font->index, &range, 1)){ errcode = FONT_PACK_FAILED; goto fond_load_internal_cleanup; } stbtt_PackEnd(&context); free(fontdata); glGenTextures(1, &font->texture); glBindTexture(GL_TEXTURE_2D, font->texture); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, font->width, font->height, 0, GL_RED, GL_UNSIGNED_BYTE, atlasdata); glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); if(glGetError() != GL_NO_ERROR){ errcode = OPENGL_ERROR; goto fond_load_internal_cleanup; } return 1; fond_load_internal_cleanup: if(atlasdata) free(atlasdata); if(font->texture) glDeleteTextures(1, &font->texture); font->texture = 0; return 0; }