From 869ae8bbd25a160bb01a52c93d6047119b65e12f Mon Sep 17 00:00:00 2001 From: Zean Key Date: Thu, 17 Apr 2025 14:40:36 -0400 Subject: [PATCH 1/9] [example] fix text size in text_draw_3d --- examples/text/text_draw_3d.c | 92 ++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/examples/text/text_draw_3d.c b/examples/text/text_draw_3d.c index 21be7dc62..7e32d93b9 100644 --- a/examples/text/text_draw_3d.c +++ b/examples/text/text_draw_3d.c @@ -107,7 +107,7 @@ int main(void) // Use the default font Font font = GetFontDefault(); - float fontSize = 8.0f; + float fontSize = 0.8f; float fontSpacing = 0.5f; float lineSpacing = -1.0f; @@ -317,44 +317,44 @@ int main(void) rlRotatef(180.0f, 0.0f, 1.0f, 0.0f); char *opt = (char *)TextFormat("< SIZE: %2.1f >", fontSize); quads += TextLength(opt); - Vector3 m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f); + Vector3 m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); Vector3 pos = { -m.x/2.0f, 0.01f, 2.0f}; - DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, BLUE); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, BLUE); + pos.z += 0.5f + m.z * 10.0f; opt = (char *)TextFormat("< SPACING: %2.1f >", fontSpacing); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, BLUE); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, BLUE); + pos.z += 0.5f + m.z * 10.0f; opt = (char *)TextFormat("< LINE: %2.1f >", lineSpacing); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, BLUE); - pos.z += 1.0f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, BLUE); + pos.z += 1.0f + m.z * 10.0f; opt = (char *)TextFormat("< LBOX: %3s >", slb? "ON" : "OFF"); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, RED); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, RED); + pos.z += 0.5f + m.z * 10.0f; opt = (char *)TextFormat("< TBOX: %3s >", SHOW_TEXT_BOUNDRY? "ON" : "OFF"); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, RED); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, RED); + pos.z += 0.5f + m.z * 10.0f; opt = (char *)TextFormat("< LAYER DISTANCE: %.3f >", layerDistance); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 8.0f, 1.0f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 8.0f, 1.0f, 0.0f, false, DARKPURPLE); + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, DARKPURPLE); rlPopMatrix(); //------------------------------------------------------------------------- @@ -362,44 +362,44 @@ int main(void) //------------------------------------------------------------------------- opt = "All the text displayed here is in 3D"; quads += 36; - m = MeasureText3D(GetFontDefault(), opt, 10.0f, 0.5f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 1.0f, 0.5f, 0.0f); pos = (Vector3){-m.x/2.0f, 0.01f, 2.0f}; - DrawText3D(GetFontDefault(), opt, pos, 10.0f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 1.0f, 0.5f, 0.0f, false, DARKBLUE); pos.z += 1.5f + m.z; opt = "press [Left]/[Right] to change the font size"; quads += 44; - m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); pos.z += 0.5f + m.z; opt = "press [Up]/[Down] to change the font spacing"; quads += 44; - m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); pos.z += 0.5f + m.z; opt = "press [PgUp]/[PgDown] to change the line spacing"; quads += 48; - m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); pos.z += 0.5f + m.z; opt = "press [F1] to toggle the letter boundry"; quads += 39; - m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); pos.z += 0.5f + m.z; opt = "press [F2] to toggle the text boundry"; quads += 37; - m = MeasureText3D(GetFontDefault(), opt, 6.0f, 0.5f, 0.0f); + m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 6.0f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); //------------------------------------------------------------------------- SHOW_LETTER_BOUNDRY = slb; @@ -470,8 +470,8 @@ static void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, floa Rectangle srcRec = { font.recs[index].x - (float)font.glyphPadding, font.recs[index].y - (float)font.glyphPadding, font.recs[index].width + 2.0f*font.glyphPadding, font.recs[index].height + 2.0f*font.glyphPadding }; - float width = (float)(font.recs[index].width + 2.0f*font.glyphPadding)/(float)font.baseSize*scale; - float height = (float)(font.recs[index].height + 2.0f*font.glyphPadding)/(float)font.baseSize*scale; + float width = (float)(font.recs[index].width + 2.0f*font.glyphPadding)*scale; + float height = (float)(font.recs[index].height + 2.0f*font.glyphPadding)*scale; if (font.texture.id > 0) { @@ -544,7 +544,7 @@ static void DrawText3D(Font font, const char *text, Vector3 position, float font { // NOTE: Fixed line spacing of 1.5 line-height // TODO: Support custom line spacing defined by user - textOffsetY += scale + lineSpacing/(float)font.baseSize*scale; + textOffsetY += scale + lineSpacing*scale; textOffsetX = 0.0f; } else @@ -554,8 +554,8 @@ static void DrawText3D(Font font, const char *text, Vector3 position, float font DrawTextCodepoint3D(font, codepoint, (Vector3){ position.x + textOffsetX, position.y, position.z + textOffsetY }, fontSize, backface, tint); } - if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; - else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)*scale; + else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)*scale; } i += codepointByteCount; // Move text bytes counter to next codepoint @@ -593,15 +593,15 @@ static Vector3 MeasureText3D(Font font, const char* text, float fontSize, float if (letter != '\n') { - if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)/(float)font.baseSize*scale; - else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)*scale; + else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)*scale; } else { if (tempTextWidth < textWidth) tempTextWidth = textWidth; lenCounter = 0; textWidth = 0.0f; - textHeight += scale + lineSpacing/(float)font.baseSize*scale; + textHeight += scale + lineSpacing*scale; } if (tempLen < lenCounter) tempLen = lenCounter; @@ -610,7 +610,7 @@ static Vector3 MeasureText3D(Font font, const char* text, float fontSize, float if (tempTextWidth < textWidth) tempTextWidth = textWidth; Vector3 vec = { 0 }; - vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing/(float)font.baseSize*scale); // Adds chars spacing to measure + vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing*scale); // Adds chars spacing to measure vec.y = 0.25f; vec.z = textHeight; @@ -645,7 +645,7 @@ static void DrawTextWave3D(Font font, const char *text, Vector3 position, float { // NOTE: Fixed line spacing of 1.5 line-height // TODO: Support custom line spacing defined by user - textOffsetY += scale + lineSpacing/(float)font.baseSize*scale; + textOffsetY += scale + lineSpacing*scale; textOffsetX = 0.0f; k = 0; } @@ -672,8 +672,8 @@ static void DrawTextWave3D(Font font, const char *text, Vector3 position, float DrawTextCodepoint3D(font, codepoint, (Vector3){ pos.x + textOffsetX, pos.y, pos.z + textOffsetY }, fontSize, backface, tint); } - if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; - else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)*scale; + else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)*scale; } i += codepointByteCount; // Move text bytes counter to next codepoint @@ -717,8 +717,8 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl } else { - if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)/(float)font.baseSize*scale; - else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)*scale; + else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)*scale; } } else @@ -726,7 +726,7 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl if (tempTextWidth < textWidth) tempTextWidth = textWidth; lenCounter = 0; textWidth = 0.0f; - textHeight += scale + lineSpacing/(float)font.baseSize*scale; + textHeight += scale + lineSpacing*scale; } if (tempLen < lenCounter) tempLen = lenCounter; @@ -735,7 +735,7 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl if (tempTextWidth < textWidth) tempTextWidth = textWidth; Vector3 vec = { 0 }; - vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing/(float)font.baseSize*scale); // Adds chars spacing to measure + vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing*scale); // Adds chars spacing to measure vec.y = 0.25f; vec.z = textHeight; From 77f31178ed26833bf7a3cd29bd9e23f0facb2573 Mon Sep 17 00:00:00 2001 From: Zean Key Date: Tue, 22 Apr 2025 16:48:50 -0400 Subject: [PATCH 2/9] fixed text_draw_3d --- examples/text/text_draw_3d.c | 156 +++++++++++------------------------ 1 file changed, 49 insertions(+), 107 deletions(-) diff --git a/examples/text/text_draw_3d.c b/examples/text/text_draw_3d.c index 7e32d93b9..6fc0e6c5c 100644 --- a/examples/text/text_draw_3d.c +++ b/examples/text/text_draw_3d.c @@ -65,8 +65,6 @@ typedef struct WaveTextConfig { static void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontSize, bool backface, Color tint); // Draw a 2D text in 3D space static void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, Color tint); -// Measure a text in 3D. For some reason `MeasureTextEx()` just doesn't seem to work so i had to use this instead. -static Vector3 MeasureText3D(Font font, const char *text, float fontSize, float fontSpacing, float lineSpacing); // Draw a 2D text in 3D space and wave the parts that start with `~~` and end with `~~`. // This is a modified version of the original code by @Nighten found here https://github.com/NightenDushi/Raylib_DrawTextStyle @@ -108,8 +106,8 @@ int main(void) // Use the default font Font font = GetFontDefault(); float fontSize = 0.8f; - float fontSpacing = 0.5f; - float lineSpacing = -1.0f; + float fontSpacing = 0.05f; + float lineSpacing = -0.1f; // Set the text (using markdown!) char text[64] = "Hello ~~World~~ in 3D!"; @@ -317,44 +315,44 @@ int main(void) rlRotatef(180.0f, 0.0f, 1.0f, 0.0f); char *opt = (char *)TextFormat("< SIZE: %2.1f >", fontSize); quads += TextLength(opt); - Vector3 m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); + Vector2 m = MeasureTextEx(GetFontDefault(), opt, 0.8f, 0.1f); Vector3 pos = { -m.x/2.0f, 0.01f, 2.0f}; - DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, BLUE); - pos.z += 0.5f + m.z * 10.0f; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 0.1f, 0.0f, false, BLUE); + pos.z += 0.5f + m.y; opt = (char *)TextFormat("< SPACING: %2.1f >", fontSpacing); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.8f, 0.1f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, BLUE); - pos.z += 0.5f + m.z * 10.0f; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 0.1f, 0.0f, false, BLUE); + pos.z += 0.5f + m.y; opt = (char *)TextFormat("< LINE: %2.1f >", lineSpacing); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.8f, 0.1f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, BLUE); - pos.z += 1.0f + m.z * 10.0f; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 0.1f, 0.0f, false, BLUE); + pos.z += 0.5f + m.y; opt = (char *)TextFormat("< LBOX: %3s >", slb? "ON" : "OFF"); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.8f, 0.1f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, RED); - pos.z += 0.5f + m.z * 10.0f; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 0.1f, 0.0f, false, RED); + pos.z += 0.5f + m.y; opt = (char *)TextFormat("< TBOX: %3s >", SHOW_TEXT_BOUNDRY? "ON" : "OFF"); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.8f, 0.1f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, RED); - pos.z += 0.5f + m.z * 10.0f; + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 0.1f, 0.0f, false, RED); + pos.z += 0.5f + m.y; opt = (char *)TextFormat("< LAYER DISTANCE: %.3f >", layerDistance); quads += TextLength(opt); - m = MeasureText3D(GetFontDefault(), opt, 0.8f, 1.0f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.8f, 0.1f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.8f, 1.0f, 0.0f, false, DARKPURPLE); + DrawText3D(GetFontDefault(), opt, pos, 0.8f, 0.1f, 0.0f, false, DARKPURPLE); rlPopMatrix(); //------------------------------------------------------------------------- @@ -362,44 +360,44 @@ int main(void) //------------------------------------------------------------------------- opt = "All the text displayed here is in 3D"; quads += 36; - m = MeasureText3D(GetFontDefault(), opt, 1.0f, 0.5f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 1.0f, 0.05f); pos = (Vector3){-m.x/2.0f, 0.01f, 2.0f}; - DrawText3D(GetFontDefault(), opt, pos, 1.0f, 0.5f, 0.0f, false, DARKBLUE); - pos.z += 1.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 1.0f, 0.05f, 0.0f, false, DARKBLUE); + pos.z += 1.5f + m.y; opt = "press [Left]/[Right] to change the font size"; quads += 44; - m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.6f, 0.05f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.05f, 0.0f, false, DARKBLUE); + pos.z += 0.5f + m.y; opt = "press [Up]/[Down] to change the font spacing"; quads += 44; - m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.6f, 0.05f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.05f, 0.0f, false, DARKBLUE); + pos.z += 0.5f + m.y; opt = "press [PgUp]/[PgDown] to change the line spacing"; quads += 48; - m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.6f, 0.05f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.05f, 0.0f, false, DARKBLUE); + pos.z += 0.5f + m.y; opt = "press [F1] to toggle the letter boundry"; quads += 39; - m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.6f, 0.05f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); - pos.z += 0.5f + m.z; + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.05f, 0.0f, false, DARKBLUE); + pos.z += 0.5f + m.y; opt = "press [F2] to toggle the text boundry"; quads += 37; - m = MeasureText3D(GetFontDefault(), opt, 0.6f, 0.5f, 0.0f); + m = MeasureTextEx(GetFontDefault(), opt, 0.6f, 0.05f); pos.x = -m.x/2.0f; - DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.5f, 0.0f, false, DARKBLUE); + DrawText3D(GetFontDefault(), opt, pos, 0.6f, 0.05f, 0.0f, false, DARKBLUE); //------------------------------------------------------------------------- SHOW_LETTER_BOUNDRY = slb; @@ -462,8 +460,8 @@ static void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, floa // Character destination rectangle on screen // NOTE: We consider charsPadding on drawing - position.x += (float)(font.glyphs[index].offsetX - font.glyphPadding)/(float)font.baseSize*scale; - position.z += (float)(font.glyphs[index].offsetY - font.glyphPadding)/(float)font.baseSize*scale; + position.x += (float)(font.glyphs[index].offsetX - font.glyphPadding)*scale; + position.z += (float)(font.glyphs[index].offsetY - font.glyphPadding)*scale; // Character source rectangle from font texture atlas // NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects @@ -544,7 +542,7 @@ static void DrawText3D(Font font, const char *text, Vector3 position, float font { // NOTE: Fixed line spacing of 1.5 line-height // TODO: Support custom line spacing defined by user - textOffsetY += scale + lineSpacing*scale; + textOffsetY += fontSize + lineSpacing; textOffsetX = 0.0f; } else @@ -554,69 +552,14 @@ static void DrawText3D(Font font, const char *text, Vector3 position, float font DrawTextCodepoint3D(font, codepoint, (Vector3){ position.x + textOffsetX, position.y, position.z + textOffsetY }, fontSize, backface, tint); } - if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)*scale; - else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)*scale; + if (font.glyphs[index].advanceX == 0) textOffsetX += (float)font.recs[index].width*scale + fontSpacing; + else textOffsetX += (float)font.glyphs[index].advanceX*scale + fontSpacing; } i += codepointByteCount; // Move text bytes counter to next codepoint } } -// Measure a text in 3D. For some reason `MeasureTextEx()` just doesn't seem to work so i had to use this instead. -static Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing) -{ - int len = TextLength(text); - int tempLen = 0; // Used to count longer text line num chars - int lenCounter = 0; - - float tempTextWidth = 0.0f; // Used to count longer text line width - - float scale = fontSize/(float)font.baseSize; - float textHeight = scale; - float textWidth = 0.0f; - - int letter = 0; // Current character - int index = 0; // Index position in sprite font - - for (int i = 0; i < len; i++) - { - lenCounter++; - - int next = 0; - letter = GetCodepoint(&text[i], &next); - index = GetGlyphIndex(font, letter); - - // NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f) - // but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1 - if (letter == 0x3f) next = 1; - i += next - 1; - - if (letter != '\n') - { - if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)*scale; - else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)*scale; - } - else - { - if (tempTextWidth < textWidth) tempTextWidth = textWidth; - lenCounter = 0; - textWidth = 0.0f; - textHeight += scale + lineSpacing*scale; - } - - if (tempLen < lenCounter) tempLen = lenCounter; - } - - if (tempTextWidth < textWidth) tempTextWidth = textWidth; - - Vector3 vec = { 0 }; - vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing*scale); // Adds chars spacing to measure - vec.y = 0.25f; - vec.z = textHeight; - - return vec; -} - // Draw a 2D text in 3D space and wave the parts that start with `~~` and end with `~~`. // This is a modified version of the original code by @Nighten found here https://github.com/NightenDushi/Raylib_DrawTextStyle static void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, WaveTextConfig* config, float time, Color tint) @@ -645,7 +588,7 @@ static void DrawTextWave3D(Font font, const char *text, Vector3 position, float { // NOTE: Fixed line spacing of 1.5 line-height // TODO: Support custom line spacing defined by user - textOffsetY += scale + lineSpacing*scale; + textOffsetY += fontSize + lineSpacing; textOffsetX = 0.0f; k = 0; } @@ -672,8 +615,8 @@ static void DrawTextWave3D(Font font, const char *text, Vector3 position, float DrawTextCodepoint3D(font, codepoint, (Vector3){ pos.x + textOffsetX, pos.y, pos.z + textOffsetY }, fontSize, backface, tint); } - if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)*scale; - else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)*scale; + if (font.glyphs[index].advanceX == 0) textOffsetX += (float)font.recs[index].width*scale + fontSpacing; + else textOffsetX += (float)font.glyphs[index].advanceX*scale + fontSpacing; } i += codepointByteCount; // Move text bytes counter to next codepoint @@ -698,8 +641,6 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl for (int i = 0; i < len; i++) { - lenCounter++; - int next = 0; letter = GetCodepoint(&text[i], &next); index = GetGlyphIndex(font, letter); @@ -717,7 +658,8 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl } else { - if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)*scale; + lenCounter++; + if (font.glyphs[index].advanceX != 0) textWidth += font.glyphs[index].advanceX*scale; else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)*scale; } } @@ -726,7 +668,7 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl if (tempTextWidth < textWidth) tempTextWidth = textWidth; lenCounter = 0; textWidth = 0.0f; - textHeight += scale + lineSpacing*scale; + textHeight += fontSize + lineSpacing; } if (tempLen < lenCounter) tempLen = lenCounter; @@ -735,7 +677,7 @@ static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, fl if (tempTextWidth < textWidth) tempTextWidth = textWidth; Vector3 vec = { 0 }; - vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing*scale); // Adds chars spacing to measure + vec.x = tempTextWidth + (float)((tempLen - 1)*fontSpacing); // Adds chars spacing to measure vec.y = 0.25f; vec.z = textHeight; @@ -749,4 +691,4 @@ static Color GenerateRandomColor(float s, float v) float h = (float)GetRandomValue(0, 360); h = fmodf((h + h*Phi), 360.0f); return ColorFromHSV(h, s, v); -} +} \ No newline at end of file From 10478ff756958459d25d2ea86f6e8caca08bc35f Mon Sep 17 00:00:00 2001 From: Gavin Rohrer Date: Fri, 25 Apr 2025 14:32:02 -0400 Subject: [PATCH 3/9] Revert GLFW_SCALE_FRAMEBUFFER to pre GLFW 4.3 behavior --- src/platforms/rcore_desktop_glfw.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 239df0657..94c780ca3 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1381,6 +1381,12 @@ int InitPlatform(void) if ((CORE.Window.flags & FLAG_WINDOW_TRANSPARENT) > 0) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); // Transparent framebuffer else glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); // Opaque framebuffer + // HACK: Most of this was written before GLFW_SCALE_FRAMEBUFFER existed and + // was enabled by default. Disabling it gets back the old behavior. A + // complete fix will require removing a lot of CORE.Window.render + // manipulation code. + glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_FALSE); + if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) { // Resize window content area based on the monitor content scale. @@ -1388,7 +1394,7 @@ int InitPlatform(void) // On platforms like macOS the resolution of the framebuffer is changed independently of the window size. glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); // Scale content area based on the monitor content scale where window is placed on #if defined(__APPLE__) - glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE); + glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE); #endif } else glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE); @@ -1602,7 +1608,7 @@ int InitPlatform(void) if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0) { // NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling. - // Framebuffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE); + // Framebuffer scaling should be activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE); #if !defined(__APPLE__) glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight); From 8d0363613299b36e0a763a3adf3f1f174aa8fbfa Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Sat, 26 Apr 2025 10:33:23 -0600 Subject: [PATCH 4/9] build.zig: fix building raylib for emscripten build.zig doesn't support the examples for the emscripten OS but it does support the raylib library. However, the examples panic if emscripten is configured which prevents it from building the library. I've replaced this panic with a fail step to fix this. --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index b3da65984..60356a215 100644 --- a/build.zig +++ b/build.zig @@ -504,7 +504,7 @@ fn addExamples( raylib: *std.Build.Step.Compile, ) !*std.Build.Step { if (target.result.os.tag == .emscripten) { - @panic("Emscripten building via Zig unsupported"); + return &b.addFail("Emscripten building via Zig unsupported").step; } const all = b.step(module, "All " ++ module ++ " examples"); From 629d4c17211d05727628e220ba5f658dd720dfbc Mon Sep 17 00:00:00 2001 From: Duy Tran Date: Sun, 27 Apr 2025 14:35:30 -0400 Subject: [PATCH 5/9] only create uninstall target when raylib is top level --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f9ee3268..0c242e8e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,8 +46,9 @@ endif() # Main sources directory (the second parameter sets the output directory name to raylib) add_subdirectory(src raylib) -# Uninstall target -if(NOT TARGET uninstall) +# Uninstall target, only create when building raylib by itself +# Avoid conflicting target names when using raylib with other libraries +if(NOT TARGET uninstall AND PROJECT_IS_TOP_LEVEL) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Uninstall.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" From ec5ce8c7feed10f590612b2cfa2162a9ae6790f1 Mon Sep 17 00:00:00 2001 From: Ivan Ugryumov Date: Mon, 28 Apr 2025 13:45:19 +0300 Subject: [PATCH 6/9] Update raudio.c --- src/raudio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/raudio.c b/src/raudio.c index 66d337567..dd8f4a255 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -604,6 +604,7 @@ AudioBuffer *LoadAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sam audioBuffer->usage = usage; audioBuffer->frameCursorPos = 0; + audioBuffer->framesProcessed = 0; audioBuffer->sizeInFrames = sizeInFrames; // Buffers should be marked as processed by default so that a call to @@ -650,6 +651,9 @@ void PlayAudioBuffer(AudioBuffer *buffer) buffer->playing = true; buffer->paused = false; buffer->frameCursorPos = 0; + buffer->framesProcessed = 0; + buffer->isSubBufferProcessed[0] = true; + buffer->isSubBufferProcessed[1] = true; ma_mutex_unlock(&AUDIO.System.lock); } } From f0de896f3641ba7b02a237386f992e1db6414092 Mon Sep 17 00:00:00 2001 From: Duy Tran Date: Mon, 28 Apr 2025 11:57:53 -0400 Subject: [PATCH 7/9] cmake: replace custom variable with built-in one --- CMakeLists.txt | 8 -------- CMakeOptions.txt | 2 +- projects/CMake/CMakeLists.txt | 1 - src/CMakeLists.txt | 2 +- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c242e8e2..f7597694c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,14 +23,6 @@ cmake_policy(SET CMP0063 NEW) # Anywhere you see include(...) you can check /cmake for that file list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -# RAYLIB_IS_MAIN determines whether the project is being used from root -# or if it is added as a dependency (through add_subdirectory for example). -if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") - set(RAYLIB_IS_MAIN TRUE) -else() - set(RAYLIB_IS_MAIN FALSE) -endif() - # Sets compiler flags and language standard include(CompilerFlags) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 4e413fe61..3c1c12742 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -11,7 +11,7 @@ enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM;SDL" "Platform to bui enum_option(OPENGL_VERSION "OFF;4.3;3.3;2.1;1.1;ES 2.0;ES 3.0" "Force a specific OpenGL Version?") # Configuration options -option(BUILD_EXAMPLES "Build the examples." ${RAYLIB_IS_MAIN}) +option(BUILD_EXAMPLES "Build the examples." ${PROJECT_IS_TOP_LEVEL}) option(CUSTOMIZE_BUILD "Show options for customizing your Raylib library build." OFF) option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF) option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF) diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index 96e33f344..56a5a5f51 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -18,7 +18,6 @@ if (NOT raylib_FOUND) # If there's none, fetch and build raylib if (NOT raylib_POPULATED) # Have we downloaded raylib yet? set(FETCHCONTENT_QUIET NO) FetchContent_MakeAvailable(raylib) - set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a7313a0b4..4ce6cb81a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ include(JoinPaths) # Sets build type if not set by now if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - if(RAYLIB_IS_MAIN) + if(PROJECT_IS_TOP_LEVEL) set(default_build_type Debug) else() message(WARNING "Default build type is not set (CMAKE_BUILD_TYPE)") From 696f225f29890d7429a6bcb335a9069375f39b4b Mon Sep 17 00:00:00 2001 From: Daniel Abbott Date: Wed, 30 Apr 2025 10:12:35 -0600 Subject: [PATCH 8/9] Update audio_sound_positioning.c Calculate `right` Vector3 for correct audio stereo positioning. --- examples/audio/audio_sound_positioning.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/audio/audio_sound_positioning.c b/examples/audio/audio_sound_positioning.c index 45f211ec4..aad558672 100644 --- a/examples/audio/audio_sound_positioning.c +++ b/examples/audio/audio_sound_positioning.c @@ -108,7 +108,7 @@ static void SetSoundPosition(Camera listener, Sound sound, Vector3 position, flo // Calculate normalized vectors for spatial positioning Vector3 normalizedDirection = Vector3Normalize(direction); Vector3 forward = Vector3Normalize(Vector3Subtract(listener.target, listener.position)); - Vector3 right = Vector3Normalize(Vector3CrossProduct(forward, listener.up)); + Vector3 right = Vector3Normalize(Vector3CrossProduct(listener.up, forward)); // Reduce volume for sounds behind the listener float dotProduct = Vector3DotProduct(forward, normalizedDirection); @@ -120,4 +120,4 @@ static void SetSoundPosition(Camera listener, Sound sound, Vector3 position, flo // Apply final sound properties SetSoundVolume(sound, attenuation); SetSoundPan(sound, pan); -} \ No newline at end of file +} From 8533d284c11967c00311e5263c88f2f7e9d9259d Mon Sep 17 00:00:00 2001 From: MrScautHD <65916181+MrScautHD@users.noreply.github.com> Date: Sun, 4 May 2025 11:20:11 +0200 Subject: [PATCH 9/9] Update BINDINGS.md --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index df53bb0ed..3468b7e89 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -13,7 +13,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers | [raylib-cs](https://github.com/raylib-cs/raylib-cs) | **5.5** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | Zlib | | [Raylib-CsLo](https://github.com/NotNotTech/Raylib-CsLo) | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | | [Raylib-CSharp-Vinculum](https://github.com/ZeroElectric/Raylib-CSharp-Vinculum) | **5.0** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | -| [Raylib-CSharp](https://github.com/MrScautHD/Raylib-CSharp) | **5.1-dev** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MIT | +| [Raylib-CSharp](https://github.com/MrScautHD/Raylib-CSharp) | **5.5** | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MIT | | [cl-raylib](https://github.com/longlene/cl-raylib) | 4.0 | [Common Lisp](https://common-lisp.net) | MIT | | [claylib/wrap](https://github.com/defun-games/claylib) | 4.5 | [Common Lisp](https://common-lisp.net) | Zlib | | [claw-raylib](https://github.com/bohonghuang/claw-raylib) | **auto** | [Common Lisp](https://common-lisp.net) | Apache-2.0 |