| 134 | } |
| 135 | |
| 136 | void Font::buildAtlas(ResourceData data) |
| 137 | { |
| 138 | if(FT_New_Memory_Face(sLibrary, data.ptr.get(), data.length, 0, &face)) |
| 139 | { |
| 140 | LOG(LogError) << "Error creating font face!"; |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | //FT_Set_Char_Size(face, 0, size * 64, getDpiX(), getDpiY()); |
| 145 | FT_Set_Pixel_Sizes(face, 0, mSize); |
| 146 | |
| 147 | //find the size we should use |
| 148 | FT_GlyphSlot g = face->glyph; |
| 149 | int w = 0; |
| 150 | int h = 0; |
| 151 | |
| 152 | /*for(int i = 32; i < 128; i++) |
| 153 | { |
| 154 | if(FT_Load_Char(face, i, FT_LOAD_RENDER)) |
| 155 | { |
| 156 | fprintf(stderr, "Loading character %c failed!\n", i); |
| 157 | continue; |
| 158 | } |
| 159 | |
| 160 | w += g->bitmap.width; |
| 161 | h = std::max(h, g->bitmap.rows); |
| 162 | }*/ |
| 163 | |
| 164 | //the max size (GL_MAX_TEXTURE_SIZE) is like 3300 |
| 165 | w = 2048; |
| 166 | h = 512; |
| 167 | |
| 168 | textureWidth = w; |
| 169 | textureHeight = h; |
| 170 | |
| 171 | //create the texture |
| 172 | glGenTextures(1, &textureID); |
| 173 | glBindTexture(GL_TEXTURE_2D, textureID); |
| 174 | |
| 175 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 176 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 177 | |
| 178 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 179 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 180 | |
| 181 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 182 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 183 | |
| 184 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL); |
| 185 | |
| 186 | //copy the glyphs into the texture |
| 187 | int x = 0; |
| 188 | int y = 0; |
| 189 | int maxHeight = 0; |
| 190 | for(int i = 32; i < 128; i++) |
| 191 | { |
| 192 | if(FT_Load_Char(face, i, FT_LOAD_RENDER)) |
| 193 | continue; |