Browse Source

Added RGB and RGBA image support to BMFont loader

pull/4730/head
Uneven Prankster 3 months ago
parent
commit
b4583ce18c
1 changed files with 28 additions and 20 deletions
  1. +28
    -20
      src/rtext.c

+ 28
- 20
src/rtext.c View File

@ -2227,26 +2227,34 @@ static Font LoadBMFont(const char *fileName)
{ {
imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i])); imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i]));
if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) PixelFormat format = imFonts[i].format;
{ if (format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8)
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel continue;
Image imFontAlpha = { // Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2), Image imFontAlpha = {
.width = imFonts[i].width, .data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),
.height = imFonts[i].height, .width = imFonts[i].width,
.mipmaps = 1, .height = imFonts[i].height,
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA .mipmaps = 1,
}; .format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
};
for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++) int stride = 1;
{ if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8){
((unsigned char *)(imFontAlpha.data))[p] = 0xff; stride = 3;
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi]; }else if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8){
} stride = 4;
}
UnloadImage(imFonts[i]); for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++)
imFonts[i] = imFontAlpha; {
} ((unsigned char *)(imFontAlpha.data))[p] = 0xff;
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi * stride];
}
UnloadImage(imFonts[i]);
imFonts[i] = imFontAlpha;
} }
Image fullFont = imFonts[0]; Image fullFont = imFonts[0];

||||||
x
 
000:0
Loading…
Cancel
Save