static void graphics_Font_newTexture(graphics_Font* font) { /* Upload the "bitmap", which contains an 8-bit grayscale image, as an alpha texture */ glActiveTexture(GL_TEXTURE0); glGenTextures(1, &font->tex); glBindTexture(GL_TEXTURE_2D, font->tex); FT_Bitmap b = font->face->glyph->bitmap; uint8_t *buf = malloc(2*b.rows*b.width); uint8_t *row = b.buffer; for(int i = 0; i < b.rows; ++i) { for(int c = 0; c < b.width; ++c) { buf[2*(i*b.width + c) ] = 255; buf[2*(i*b.width + c) + 1] = row[c]; } row += b.pitch; } graphics_Font_setWrap(font, &defaultWrap); graphics_Font_setFilter(font, &defaultFilter); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, b.width, b.rows, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buf); free(buf); }
static int l_graphics_Font_setFilter(lua_State* state) { l_assertType(state, 1, l_graphics_isFont); graphics_Font* font = l_graphics_toFont(state, 1); graphics_Filter newFilter; graphics_Font_getFilter(font, &newFilter); newFilter.minMode = l_tools_toEnumOrError(state, 2, l_graphics_FilterMode); newFilter.magMode = l_tools_toEnumOrError(state, 3, l_graphics_FilterMode); newFilter.maxAnisotropy = luaL_optnumber(state, 4, 1.0f); graphics_Font_setFilter(font, &newFilter); return 0; }