Browse Source

Fix ImageTextEx and ImageDrawTextEx scaling (#2756)

* Use RL_QUADS/RL_TRIANGLES for single-pixel drawing

Addresses problem mentioned in
https://github.com/raysan5/raylib/issues/2744#issuecomment-1273568263
(in short: when drawing pixels using DrawPixel{,V} in camera mode,
upscaled pixel becomes a line instead of bigger pixel)

* [rtextures] Fixed scaling down in ImageTextEx

Closes #2755
pull/2760/head
hkc 2 years ago
committed by GitHub
parent
commit
0b69bc28c6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      src/rtextures.c

+ 3
- 2
src/rtextures.c View File

@ -1248,6 +1248,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
// NOTE: Text image is generated at font base size, later scaled to desired font size // NOTE: Text image is generated at font base size, later scaled to desired font size
Vector2 imSize = MeasureTextEx(font, text, (float)font.baseSize, spacing); // WARNING: Module required: rtext Vector2 imSize = MeasureTextEx(font, text, (float)font.baseSize, spacing); // WARNING: Module required: rtext
Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing);
// Create image to store text // Create image to store text
imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK); imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK);
@ -1286,9 +1287,9 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
} }
// Scale image depending on text size // Scale image depending on text size
if (fontSize > imSize.y) if (textSize.y != imSize.y)
{ {
float scaleFactor = fontSize/imSize.y; float scaleFactor = textSize.y / imSize.y;
TRACELOG(LOG_INFO, "IMAGE: Text scaled by factor: %f", scaleFactor); TRACELOG(LOG_INFO, "IMAGE: Text scaled by factor: %f", scaleFactor);
// Using nearest-neighbor scaling algorithm for default font // Using nearest-neighbor scaling algorithm for default font

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