summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-07-18 17:57:10 +0200
committerRay <[email protected]>2023-07-18 17:57:10 +0200
commit52541b4a1fb04d66de30c2a1e5f44358b2c1aee7 (patch)
tree2865c21e8f38e4d9671bb6283ef4e6b919f8e42c /src
parente0c80f5ddd9543a6f086f3871f886e275c331a53 (diff)
downloadraylib-52541b4a1fb04d66de30c2a1e5f44358b2c1aee7.tar.gz
raylib-52541b4a1fb04d66de30c2a1e5f44358b2c1aee7.zip
ADDED: `SUPPORT_FONT_ATLAS_WHITE_REC`
Support creating a 3x3 pixels white rectangle at the bottom-right corner of the generated font atlas image, useful for shapes+text drawing in a single draw call!
Diffstat (limited to 'src')
-rw-r--r--src/config.h5
-rw-r--r--src/rtext.c27
2 files changed, 27 insertions, 5 deletions
diff --git a/src/config.h b/src/config.h
index fbc7a5b4..67c6060b 100644
--- a/src/config.h
+++ b/src/config.h
@@ -181,6 +181,11 @@
// If not defined, still some functions are supported: TextLength(), TextFormat()
#define SUPPORT_TEXT_MANIPULATION 1
+// On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle
+// at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow
+// drawing text and shapes with a single draw call [SetShapesTexture()].
+#define SUPPORT_FONT_ATLAS_WHITE_REC 1
+
// rtext: Configuration values
//------------------------------------------------------------------------------------
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions:
diff --git a/src/rtext.c b/src/rtext.c
index 3b21a93c..a7d9903a 100644
--- a/src/rtext.c
+++ b/src/rtext.c
@@ -6,14 +6,19 @@
* #define SUPPORT_MODULE_RTEXT
* rtext module is included in the build
*
+* #define SUPPORT_DEFAULT_FONT
+* Load default raylib font on initialization to be used by DrawText() and MeasureText().
+* If no default font loaded, DrawTextEx() and MeasureTextEx() are required.
+*
* #define SUPPORT_FILEFORMAT_FNT
* #define SUPPORT_FILEFORMAT_TTF
* Selected desired fileformats to be supported for loading. Some of those formats are
* supported by default, to remove support, just comment unrequired #define in this module
*
-* #define SUPPORT_DEFAULT_FONT
-* Load default raylib font on initialization to be used by DrawText() and MeasureText().
-* If no default font loaded, DrawTextEx() and MeasureTextEx() are required.
+* #define SUPPORT_FONT_ATLAS_WHITE_REC
+* On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle
+* at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow
+* drawing text and shapes with a single draw call [SetShapesTexture()].
*
* #define TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH
* TextSplit() function static buffer max size
@@ -734,7 +739,6 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC
}
#endif
-
atlas.data = (unsigned char *)RL_CALLOC(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp)
atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
atlas.mipmaps = 1;
@@ -839,7 +843,20 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC
RL_FREE(nodes);
RL_FREE(context);
}
-
+
+#if defined(SUPPORT_FONT_ATLAS_WHITE_REC)
+ // Add a 3x3 white rectangle at the bottom-right corner of the generated atlas,
+ // useful to use as the white texture to draw shapes with raylib, using this rectangle
+ // shapes and text can be backed into a single draw call: SetShapesTexture()
+ for (int i = 0, k = atlas.width*atlas.height - 1; i < 3; i++)
+ {
+ ((unsigned char *)atlas.data)[k - 0] = 255;
+ ((unsigned char *)atlas.data)[k - 1] = 255;
+ ((unsigned char *)atlas.data)[k - 2] = 255;
+ k -= atlas.width;
+ }
+#endif
+
// Convert image data from GRAYSCALE to GRAY_ALPHA
unsigned char *dataGrayAlpha = (unsigned char *)RL_MALLOC(atlas.width*atlas.height*sizeof(unsigned char)*2); // Two channels