Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Uneven Prankster committed Jan 27, 2025
1 parent 6e2c28c commit 5e8a67e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/rtext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2227,29 +2227,36 @@ static Font LoadBMFont(const char *fileName)
{
imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i]));

PixelFormat format = imFonts[i].format;
if (format != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 && format != PIXELFORMAT_UNCOMPRESSED_R8G8B8){
int pageFormat = imFonts[i].format;

if (pageFormat != PIXELFORMAT_UNCOMPRESSED_GRAYSCALE && pageFormat != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 && pageFormat != PIXELFORMAT_UNCOMPRESSED_R8G8B8)
{
TRACELOG(LOG_WARNING, "FONT: [%s] Page number %i used an unsupported pixel format", fileName, i);
continue;
}

// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
Image imFontAlpha = {
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),

Image imFont = {
.data = RL_CALLOC(imFonts[i].width * imFonts[i].height, 2),
.width = imFonts[i].width,
.height = imFonts[i].height,
.mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
};

int stride = 1;
if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8){

if (pageFormat == PIXELFORMAT_UNCOMPRESSED_R8G8B8)
{
stride = 3;
}else if (format == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8){
}
else if (pageFormat == PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
{
stride = 4;
}

for (int p = 0, pi = 0; p < (imFonts[i].width*imFonts[i].height*2); p += 2, pi++)
for (int p = 0, pi = 0; p < (imFonts[i].width * imFonts[i].height * 2); p += 2, pi++)
{
((unsigned char *)(imFontAlpha.data))[p] = 0xff;
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi * stride];
Expand Down

0 comments on commit 5e8a67e

Please sign in to comment.