Corrected ImageTextEx()
- Added new function: GenImageColor() ImageDraw() should be reviewed... specially alpha blending...
This commit is contained in:
parent
cbe0dcedfe
commit
539a9ca50e
2 changed files with 24 additions and 19 deletions
|
@ -940,6 +940,7 @@ RLAPI void ImageColorContrast(Image *image, float contrast);
|
||||||
RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255)
|
RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255)
|
||||||
|
|
||||||
// Image generation functions
|
// Image generation functions
|
||||||
|
RLAPI Image GenImageColor(int width, int height, Color color); // Generate image: plain color
|
||||||
RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
|
RLAPI Image GenImageGradientV(int width, int height, Color top, Color bottom); // Generate image: vertical gradient
|
||||||
RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
|
RLAPI Image GenImageGradientH(int width, int height, Color left, Color right); // Generate image: horizontal gradient
|
||||||
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
|
RLAPI Image GenImageGradientRadial(int width, int height, float density, Color inner, Color outer); // Generate image: radial gradient
|
||||||
|
|
|
@ -1032,6 +1032,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec)
|
||||||
dstCol.r = ((srcCol.a*(srcCol.r - dstCol.r)) >> 8) + dstCol.r;
|
dstCol.r = ((srcCol.a*(srcCol.r - dstCol.r)) >> 8) + dstCol.r;
|
||||||
dstCol.g = ((srcCol.a*(srcCol.g - dstCol.g)) >> 8) + dstCol.g;
|
dstCol.g = ((srcCol.a*(srcCol.g - dstCol.g)) >> 8) + dstCol.g;
|
||||||
dstCol.b = ((srcCol.a*(srcCol.b - dstCol.b)) >> 8) + dstCol.b;
|
dstCol.b = ((srcCol.a*(srcCol.b - dstCol.b)) >> 8) + dstCol.b;
|
||||||
|
dstCol.a = ((srcCol.a*(srcCol.a - dstCol.a)) >> 8) + dstCol.a;
|
||||||
|
|
||||||
dstPixels[j*dst->width + i] = dstCol;
|
dstPixels[j*dst->width + i] = dstCol;
|
||||||
|
|
||||||
|
@ -1067,6 +1068,8 @@ Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing
|
||||||
int posX = 0;
|
int posX = 0;
|
||||||
|
|
||||||
Vector2 imSize = MeasureTextEx(font, text, font.baseSize, spacing);
|
Vector2 imSize = MeasureTextEx(font, text, font.baseSize, spacing);
|
||||||
|
|
||||||
|
TraceLog(LOG_WARNING, "Text Image size: %f, %f", imSize.x, imSize.y);
|
||||||
|
|
||||||
// NOTE: glGetTexImage() not available in OpenGL ES
|
// NOTE: glGetTexImage() not available in OpenGL ES
|
||||||
Image imFont = GetTextureData(font.texture);
|
Image imFont = GetTextureData(font.texture);
|
||||||
|
@ -1074,31 +1077,21 @@ Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing
|
||||||
ImageFormat(&imFont, UNCOMPRESSED_R8G8B8A8); // Convert to 32 bit for color tint
|
ImageFormat(&imFont, UNCOMPRESSED_R8G8B8A8); // Convert to 32 bit for color tint
|
||||||
ImageColorTint(&imFont, tint); // Apply color tint to font
|
ImageColorTint(&imFont, tint); // Apply color tint to font
|
||||||
|
|
||||||
Color *fontPixels = GetImageData(imFont);
|
|
||||||
|
|
||||||
// Create image to store text
|
// Create image to store text
|
||||||
// NOTE: Pixels are initialized to BLANK color (0, 0, 0, 0)
|
Image imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK);
|
||||||
Color *pixels = (Color *)calloc((int)imSize.x*(int)imSize.y, sizeof(Color));
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
Rectangle letterRec = font.chars[(int)text[i] - 32].rec;
|
CharInfo letter = font.chars[(int)text[i] - 32];
|
||||||
|
|
||||||
|
ImageDraw(&imText, imFont, letter.rec, (Rectangle){ posX + letter.offsetX,
|
||||||
|
letter.offsetY, letter.rec.width, letter.rec.height });
|
||||||
|
|
||||||
for (int y = letterRec.y; y < (letterRec.y + letterRec.height); y++)
|
posX += letter.advanceX + spacing;
|
||||||
{
|
|
||||||
for (int x = posX; x < (posX + letterRec.width); x++)
|
|
||||||
{
|
|
||||||
pixels[(y - letterRec.y)*(int)imSize.x + x] = fontPixels[y*font.texture.width + (x - posX + letterRec.x)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
posX += letterRec.width + spacing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadImage(imFont);
|
UnloadImage(imFont);
|
||||||
|
|
||||||
Image imText = LoadImageEx(pixels, (int)imSize.x, (int)imSize.y);
|
|
||||||
|
|
||||||
// Scale image depending on text size
|
// Scale image depending on text size
|
||||||
if (fontSize > imSize.y)
|
if (fontSize > imSize.y)
|
||||||
{
|
{
|
||||||
|
@ -1110,9 +1103,6 @@ Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing
|
||||||
else ImageResize(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
else ImageResize(&imText, (int)(imSize.x*scaleFactor), (int)(imSize.y*scaleFactor));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pixels);
|
|
||||||
free(fontPixels);
|
|
||||||
|
|
||||||
return imText;
|
return imText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1452,6 +1442,20 @@ void ImageColorBrightness(Image *image, int brightness)
|
||||||
#endif // SUPPORT_IMAGE_MANIPULATION
|
#endif // SUPPORT_IMAGE_MANIPULATION
|
||||||
|
|
||||||
#if defined(SUPPORT_IMAGE_GENERATION)
|
#if defined(SUPPORT_IMAGE_GENERATION)
|
||||||
|
// Generate image: plain color
|
||||||
|
Image GenImageColor(int width, int height, Color color)
|
||||||
|
{
|
||||||
|
Color *pixels = (Color *)calloc(width*height, sizeof(Color));
|
||||||
|
|
||||||
|
for (int i = 0; i < width*height; i++) pixels[i] = color;
|
||||||
|
|
||||||
|
Image image = LoadImageEx(pixels, width, height);
|
||||||
|
|
||||||
|
free(pixels);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
// Generate image: vertical gradient
|
// Generate image: vertical gradient
|
||||||
Image GenImageGradientV(int width, int height, Color top, Color bottom)
|
Image GenImageGradientV(int width, int height, Color top, Color bottom)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue