#include #include FT_FREETYPE_H #include FT_STROKER_H #include #include #include #include // Render the specified character in texture atlas void AddGlyph( FT_Library &library, wchar_t ch, FT_Face &face, int size, sf::Image &image, int line, int col ) { col *= size; line *= size; // Load the glyph corresponding to the code point FT_Load_Char(face, ch, FT_LOAD_RENDER ); // Retrieve the glyph FT_Glyph glyphDesc; FT_Get_Glyph(face->glyph, &glyphDesc); // Convert the glyph to a bitmap (i.e. rasterize it) FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_NORMAL,0, 1); FT_BitmapGlyph bitmapGlyph = (FT_BitmapGlyph)glyphDesc; FT_Bitmap& bitmap = bitmapGlyph->bitmap; int width = bitmap.width; int pitch = bitmap.pitch; int height = bitmap.rows; int top = bitmapGlyph->top; int left = bitmapGlyph->left; unsigned char* pixels = bitmap.buffer; if ((width > 0) && (height > 0)) { int descent = face->size->metrics.descender >>6; int linegap = ((face->glyph->metrics.horiBearingY-face->glyph->metrics.height)>>6);//ascent - descent; int startY = (line);//+size-top)+descent; for (int y = 0; y \n"; return 1; } // Iniialize FreeType. FT_Library library; FT_Init_FreeType(&library); // Open up a font file. std::ifstream fontFile(argv[1], std::ios::binary); if (fontFile) { // Read the entire file to a memory buffer. fontFile.seekg(0, std::ios::end); std::fstream::pos_type fontFileSize = fontFile.tellg(); fontFile.seekg(0); unsigned char *fontBuffer = new unsigned char[fontFileSize]; fontFile.read((char *)fontBuffer, fontFileSize); // Create a face from a memory buffer. Be sure not to delete the memory // buffer until you are done using that font as FreeType will reference // it directly. FT_Face face; FT_New_Memory_Face(library, fontBuffer, fontFileSize, 0, &face); int Quality = 32; int TexSize = Quality * 16; //texture bitmap font sf::Image bitMapTexture; bitMapTexture.create(TexSize,TexSize); //Scale des caracteres FT_Set_Pixel_Sizes(face,Quality, Quality ); FT_Select_Charmap(face, FT_ENCODING_UNICODE); int charindex = 0; for(int ligne = 0 ; ligne < 16 ; ligne++) for(int colonne = 0 ; colonne < 16 ; colonne++ , charindex++) { AddGlyph(library,charindex,face, Quality,bitMapTexture,ligne,colonne); } // Now that we are done it is safe to delete the memory. delete [] fontBuffer; sf::Image charA; for(int x = 0 ; x < bitMapTexture.getSize().x ; x++) for(int y = 0 ; y < bitMapTexture.getSize().y ; y++ ) { if( x % Quality == 0 || y % Quality == 0) bitMapTexture.setPixel(x,y,sf::Color(255,0,0,255)); } bitMapTexture.saveToFile("Hello.png"); } // Clean up the library FT_Done_FreeType(library); return 1; } /* EOF */