diff options
| author | raysan5 <[email protected]> | 2020-05-14 13:36:22 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2020-05-14 13:36:22 +0200 |
| commit | 65b7047111c27de11c87c90cb15ef376c902e2d7 (patch) | |
| tree | 8cd25ec6f7ac2599849298bc01e39d41651d9dfd /src/text.c | |
| parent | ca6016cc71a67ccc411e715f4b45afafa08fada6 (diff) | |
| download | raylib-65b7047111c27de11c87c90cb15ef376c902e2d7.tar.gz raylib-65b7047111c27de11c87c90cb15ef376c902e2d7.zip | |
Remove some [textures] function dependencies
- LoadFontDefault() -> Some code simplifications
- LoadFontFromImage() -> Avoid LoadImageEx()
- LoadFontData() -> Avoid GenImageColor(), ImageFormat()
- LoadBMFont() -> Avoid ImageCopy(), ImageFormat()
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 69 |
1 files changed, 41 insertions, 28 deletions
@@ -191,33 +191,31 @@ extern void LoadFontDefault(void) // Re-construct image from defaultFontData and generate OpenGL texture //---------------------------------------------------------------------- - int imWidth = 128; - int imHeight = 128; - - Color *imagePixels = (Color *)RL_MALLOC(imWidth*imHeight*sizeof(Color)); - - for (int i = 0; i < imWidth*imHeight; i++) imagePixels[i] = BLANK; // Initialize array - - int counter = 0; // Font data elements counter - - // Fill imgData with defaultFontData (convert from bit to pixel!) - for (int i = 0; i < imWidth*imHeight; i += 32) + Image imFont = { + .data = calloc(128*128, 2), // 2 bytes per pixel (gray + alpha) + .width = 128, + .height = 128, + .format = UNCOMPRESSED_GRAY_ALPHA, + .mipmaps = 1 + }; + + // Fill image.data with defaultFontData (convert from bit to pixel!) + for (int i = 0, counter = 0; i < imFont.width*imFont.height; i += 32) { for (int j = 31; j >= 0; j--) { - if (BIT_CHECK(defaultFontData[counter], j)) imagePixels[i+j] = WHITE; + if (BIT_CHECK(defaultFontData[counter], j)) + { + // NOTE: We are unreferencing data as short, so, + // we must consider data as little-endian order (alpha + gray) + ((unsigned short *)imFont.data)[i + j] = 0xffff; + } + else ((unsigned short *)imFont.data)[i + j] = 0x00ff; } counter++; - - if (counter > 512) counter = 0; // Security check... } - Image imFont = LoadImageEx(imagePixels, imWidth, imHeight); - ImageFormat(&imFont, UNCOMPRESSED_GRAY_ALPHA); - - RL_FREE(imagePixels); - defaultFont.texture = LoadTextureFromImage(imFont); // Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, charsCount @@ -445,9 +443,13 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK; // Create a new image with the processed color data (key color replaced by BLANK) - Image fontClear = LoadImageEx(pixels, image.width, image.height); - - RL_FREE(pixels); // Free pixels array memory + Image fontClear = { + .data = pixels, + .width = image.width, + .height = image.height, + .format = UNCOMPRESSED_R8G8B8A8, + .mipmaps = 1 + }; // Create spritefont with all data parsed from image Font font = { 0 }; @@ -571,8 +573,15 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c // NOTE: We create an empty image for space character, it could be further required for atlas packing if (ch == 32) { - chars[i].image = GenImageColor(chars[i].advanceX, fontSize, BLANK); - ImageFormat(&chars[i].image, UNCOMPRESSED_GRAYSCALE); + Image imSpace = { + .data = calloc(chars[i].advanceX*fontSize, 2), + .width = chars[i].advanceX, + .height = fontSize, + .format = UNCOMPRESSED_GRAYSCALE, + .mipmaps = 1 + }; + + chars[i].image = imSpace; } if (type == FONT_BITMAP) @@ -727,7 +736,6 @@ Image GenImageFontAtlas(const CharInfo *chars, Rectangle **charRecs, int charsCo // TODO: Crop image if required for smaller size // Convert image data from GRAYSCALE to GRAY_ALPHA - // WARNING: ImageAlphaMask(&atlas, atlas) does not work in this case, requires manual operation unsigned char *dataGrayAlpha = (unsigned char *)RL_MALLOC(atlas.width*atlas.height*sizeof(unsigned char)*2); // Two channels for (int i = 0, k = 0; i < atlas.width*atlas.height; i++, k += 2) @@ -1732,9 +1740,14 @@ static Font LoadBMFont(const char *fileName) if (imFont.format == UNCOMPRESSED_GRAYSCALE) { // Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel - Image imFontAlpha = ImageCopy(imFont); - ImageFormat(&imFontAlpha, UNCOMPRESSED_GRAY_ALPHA); - + Image imFontAlpha = { + .data = calloc(imFont.width*imFont.height, 2), + .width = imFont.width, + .height = imFont.height, + .format = UNCOMPRESSED_GRAY_ALPHA, + .mipmaps = 1 + }; + for (int p = 0, i = 0; p < (imFont.width*imFont.height*2); p += 2, i++) { ((unsigned char *)(imFontAlpha.data))[p] = 0xff; |
