Update rtext.c
This commit is contained in:
parent
7f3fcc44d1
commit
0236236934
29
src/rtext.c
29
src/rtext.c
|
|
@ -2102,38 +2102,37 @@ static Font LoadBMFont(const char *fileName)
|
||||||
|
|
||||||
// Resize and ReDraw Font Image
|
// Resize and ReDraw Font Image
|
||||||
Image fullFont = LoadImage(imPath[0]);;
|
Image fullFont = LoadImage(imPath[0]);;
|
||||||
|
Image *imFonts = (Image *)RL_CALLOC(pageCount, sizeof(Image)); // Font atlases, multiple images
|
||||||
Image imFont[pageCount] = { 0 }; // Font atlases, multiple images
|
|
||||||
|
|
||||||
for (int i = 0; i < pageCount; i++)
|
for (int i = 0; i < pageCount; i++)
|
||||||
{
|
{
|
||||||
imFont[i] = LoadImage(imPath[i]);
|
imFonts[i] = LoadImage(imPath[i]);
|
||||||
|
|
||||||
if (imFont[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
|
if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
|
||||||
{
|
{
|
||||||
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
|
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
|
||||||
Image imFontAlpha = {
|
Image imFontAlpha = {
|
||||||
.data = RL_CALLOC(imFont[i].width*imFont[i].height, 2),
|
.data = RL_CALLOC(imFonts[i].width*imFonts[i].height, 2),
|
||||||
.width = imFont[i].width,
|
.width = imFonts[i].width,
|
||||||
.height = imFont[i].height,
|
.height = imFonts[i].height,
|
||||||
.mipmaps = 1,
|
.mipmaps = 1,
|
||||||
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
|
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int p = 0, pi = 0; p < (imFont[i].width*imFont[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] = 0xff;
|
||||||
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFont[i].data)[pi];
|
((unsigned char *)(imFontAlpha.data))[p + 1] = ((unsigned char *)imFonts[i].data)[pi];
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadImage(imFont[i]);
|
UnloadImage(imFonts[i]);
|
||||||
imFont[i] = imFontAlpha;
|
imFonts[i] = imFontAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastSlash != NULL) RL_FREE(imPath[i]);
|
if (lastSlash != NULL) RL_FREE(imPath[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullFont = imFont[0];
|
fullFont = imFonts[0];
|
||||||
|
|
||||||
// If multiple atlas, then merge atlas
|
// If multiple atlas, then merge atlas
|
||||||
// NOTE: WARNING: This process could be really slow!
|
// NOTE: WARNING: This process could be really slow!
|
||||||
|
|
@ -2146,9 +2145,11 @@ static Font LoadBMFont(const char *fileName)
|
||||||
{
|
{
|
||||||
Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight };
|
Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight };
|
||||||
Rectangle destRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight };
|
Rectangle destRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight };
|
||||||
ImageDraw(&fullFont, imFont[i], srcRec, destRec, WHITE);
|
ImageDraw(&fullFont, imFonts[i], srcRec, destRec, WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RL_FREE(imFonts);
|
||||||
|
|
||||||
font.texture = LoadTextureFromImage(fullFont);
|
font.texture = LoadTextureFromImage(fullFont);
|
||||||
|
|
||||||
|
|
@ -2179,7 +2180,7 @@ static Font LoadBMFont(const char *fileName)
|
||||||
font.glyphs[i].offsetY = charOffsetY;
|
font.glyphs[i].offsetY = charOffsetY;
|
||||||
font.glyphs[i].advanceX = charAdvanceX;
|
font.glyphs[i].advanceX = charAdvanceX;
|
||||||
|
|
||||||
// Fill character image data from imFont data
|
// Fill character image data from full font data
|
||||||
font.glyphs[i].image = ImageFromImage(fullFont, font.recs[i]);
|
font.glyphs[i].image = ImageFromImage(fullFont, font.recs[i]);
|
||||||
}
|
}
|
||||||
else TRACELOG(LOG_WARNING, "FONT: [%s] Some characters data not correctly provided", fileName);
|
else TRACELOG(LOG_WARNING, "FONT: [%s] Some characters data not correctly provided", fileName);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user