Recent

Author Topic: RayLib 5.0  (Read 12178 times)

Guva

  • Full Member
  • ***
  • Posts: 179
  • 🌈 ZX-Spectrum !!!
Re: RayLib 5.0
« Reply #15 on: December 26, 2024, 02:54:26 pm »
DrawText('FONT SIZE字体: 30.0', GetScreenWidth() - 240, 20, 20, DARKGRAY);   
How can this engine support displaying Chinese and unicode when drawing text?
https://github.com/raysan5/raylib/blob/master/examples/text/text_unicode.c

fireboxsoft

  • New Member
  • *
  • Posts: 11
Re: RayLib 5.0
« Reply #16 on: December 27, 2024, 01:17:31 am »
Thank you for your reply and guidance. I don't know C language, only pascal, but I would like to try using lazarus+Raylib to develop games. I will try to see if I can successfully support unicode. But we still hope that the author of the engine will officially release a demo and example, so that we will avoid detours. Looking forward to it, thank you!
« Last Edit: December 27, 2024, 01:23:34 am by fireboxsoft »

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: RayLib 5.0
« Reply #17 on: December 27, 2024, 07:55:16 am »
fireboxsoft,
{$codepage utf-8}
???
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Guva

  • Full Member
  • ***
  • Posts: 179
  • 🌈 ZX-Spectrum !!!
Re: RayLib 5.0
« Reply #18 on: December 27, 2024, 03:38:36 pm »
fireboxsoft,
{$codepage utf-8}
???

ru: Серж к сожалению в raylib так не работает для отображения юникода есть свои функции и процедуры.

en: Serge unfortunately raylib does not work like that for displaying Unicode has its own functions and procedures.


Code: Pascal  [Select][+][-]
  1. {Draw one character (codepoint)}
  2. procedure DrawTextCodepoint(font: TFont; codepoint: Integer; position: TVector2; fontSize: Single; tint: TColorB);
  3. {Draw multiple character (codepoint)}
  4. procedure DrawTextCodepoints(font: TFont; const codepoints: PInteger; codepointCount: Integer; position: TVector2; fontSize, spacing: Single; tint: TColorB);
  5.  
  6. {Load UTF-8 text encoded from codepoints array}
  7. function LoadUTF8(const codepoints: PInteger; length: Integer): PChar;
  8. {Unload UTF-8 text encoded from codepoints array}
  9. procedure UnloadUTF8(text: PChar);
  10. {Load all codepoints from a UTF-8 text string, codepoints count returned by parameter}
  11. function LoadCodepoints(const text: PChar; count: PInteger): PInteger;
  12. {Unload codepoints data from memory}
  13. procedure UnloadCodepoints(codepoints: PInteger);
  14. {Get total number of codepoints in a UTF-8 encoded string}
  15. function GetCodepointCount(const text: PChar): Integer;
  16. {Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure}
  17. function GetCodepoint(const text: PChar; codepointSize: PInteger): Integer;
  18. {Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure}
  19. function GetCodepointNext(const text: PChar; codepointSize: PInteger): Integer;
  20. {Get previous codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure}
  21. function GetCodepointPrevious(const text: PChar; codepointSize: PInteger): Integer;
  22. {Encode one codepoint into UTF-8 byte array (array length returned as parameter)}
  23. function CodepointToUTF8(codepoint: Integer; utf8Size: PInteger): PChar;
  24.  
     

fireboxsoft

  • New Member
  • *
  • Posts: 11
Re: RayLib 5.0
« Reply #19 on: December 28, 2024, 02:24:13 am »
thank you very much! :)

Guva

  • Full Member
  • ***
  • Posts: 179
  • 🌈 ZX-Spectrum !!!
Re: RayLib 5.0
« Reply #20 on: April 10, 2025, 04:27:53 am »
DrawText('FONT SIZE字体: 30.0', GetScreenWidth() - 240, 20, 20, DARKGRAY);   
How can this engine support displaying Chinese and unicode when drawing text?

I needed to display other languages.
Note: Your font must support the language you want.

To use in raygi, you need to download the font
Code: Pascal  [Select][+][-]
  1. MyFont := LoadUnicodeFont(16,'Cornerita_Regular.ttf');
  2. GuiSetFont(MyFont);  
  3.  

To use in your code, use the DrawTextEx or Draw Text Pro procedures .

Code: Pascal  [Select][+][-]
  1. program TestFont;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6. cmem, {$IFDEF LINUX} cthreads,{$ENDIF}
  7. raylib, fontUtil;
  8.  
  9. const
  10.   screenWidth = 800;
  11.   screenHeight = 450;
  12.  
  13. var
  14.   MyFont: TFont;
  15.  
  16. begin
  17.   // Initialization
  18.   InitWindow(screenWidth, screenHeight, 'raylib - simple project');
  19.   SetTargetFPS(60);// Set our game to run at 60 frames-per-second
  20.  
  21.   MyFont := LoadUnicodeFont('NotoSansTC-Regular.ttf', 48);
  22.  
  23.   // Main game loop
  24.   while not WindowShouldClose() do
  25.     begin
  26.       // Update
  27.       // TODO: Update your variables here
  28.  
  29.       // Draw
  30.       BeginDrawing();
  31.         ClearBackground(RAYWHITE);
  32.         DrawTextEx(MyFont, '恭喜! 你创建了你的第一个窗口!', Vector2Create(140,200), 48, 1, LIGHTGRAY);
  33.       EndDrawing();
  34.     end;
  35.  
  36.   // De-Initialization
  37.   UnloadFont(MyFont);
  38.   CloseWindow();        // Close window and OpenGL context
  39. end.
  40.  

Code: Pascal  [Select][+][-]
  1. unit fontUtil;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   raylib, SysUtils;
  9.  
  10. function LoadUnicodeFont(FileName: String; FontSize: Integer;
  11.   TextureFilter: TTextureFilter = TEXTURE_FILTER_POINT): TFont;
  12.  
  13. implementation
  14.  
  15. function LoadUnicodeFont(FileName: String; FontSize: Integer;
  16.   TextureFilter: TTextureFilter): TFont;
  17. var
  18.   cp: array of Integer;  // Array to store Unicode codepoints
  19.   count: Integer;        // Counter for codepoints
  20.  
  21.   // Helper procedure to add a range of Unicode codepoints
  22.   procedure AddRange(start, stop: Integer);
  23.   begin
  24.     while start <= stop do
  25.     begin
  26.       // Dynamically expand array if needed
  27.       if count >= Length(cp) then
  28.         SetLength(cp, Length(cp) + 1024);
  29.       // Add current codepoint and increment
  30.       cp[count] := start;
  31.       Inc(count);
  32.       Inc(start);
  33.     end;
  34.   end;
  35.  
  36. begin
  37.   // Initialize codepoint array with initial capacity
  38.   SetLength(cp, 65536);
  39.   count := 0;
  40.  
  41.   // --------------------------------------------------
  42.   // 1. BASIC ASCII CHARACTERS
  43.   // --------------------------------------------------
  44.   AddRange(32, 126);  // Basic Latin (letters, digits, punctuation)
  45.  
  46.   // --------------------------------------------------
  47.   // 2. EUROPEAN LANGUAGES (LATIN SCRIPT)
  48.   // --------------------------------------------------
  49.   AddRange($C0, $17F);  // Latin-1 Supplement + Latin Extended-A
  50.   AddRange($180, $24F); // Latin Extended-B
  51.   AddRange($1E00, $1EFF); // Latin Extended Additional
  52.   AddRange($2C60, $2C7F); // Latin Extended-C
  53.  
  54.   // --------------------------------------------------
  55.   // 3. GREEK AND COPTIC
  56.   // --------------------------------------------------
  57.   AddRange($370, $3FF); // Greek and Coptic
  58.   AddRange($1F00, $1FFF); // Greek Extended
  59.  
  60.   // --------------------------------------------------
  61.   // 4. CYRILLIC SCRIPTS
  62.   // --------------------------------------------------
  63.   AddRange($400, $4FF); // Basic Cyrillic
  64.   AddRange($500, $52F); // Cyrillic Supplement
  65.   AddRange($2DE0, $2DFF); // Cyrillic Extended-A
  66.   AddRange($A640, $A69F); // Cyrillic Extended-B
  67.  
  68.   // --------------------------------------------------
  69.   // 5. CJK LANGUAGES (CHINESE, JAPANESE, KOREAN)
  70.   // --------------------------------------------------
  71.   AddRange($4E00, $9FFF); // CJK Unified Ideographs
  72.   AddRange($3400, $4DBF); // CJK Extension A
  73.   AddRange($3000, $303F); // CJK Symbols and Punctuation
  74.   AddRange($3040, $309F); // Hiragana (Japanese)
  75.   AddRange($30A0, $30FF); // Katakana (Japanese)
  76.   AddRange($31F0, $31FF); // Katakana Phonetic Extensions
  77.   AddRange($FF00, $FFEF); // Halfwidth and Fullwidth Forms
  78.   AddRange($AC00, $D7AF); // Hangul Syllables (Korean)
  79.   AddRange($1100, $11FF); // Hangul Jamo
  80.  
  81.   // --------------------------------------------------
  82.   // 6. SOUTHEAST ASIAN LANGUAGES
  83.   // --------------------------------------------------
  84.   AddRange($0E00, $0E7F); // Thai
  85.   AddRange($0E80, $0EFF); // Lao
  86.   AddRange($1780, $17FF); // Khmer
  87.   AddRange($1000, $109F); // Myanmar
  88.   AddRange($1980, $19DF); // New Tai Lue
  89.  
  90.   // --------------------------------------------------
  91.   // 7. INDIAN SUBCONTINENT LANGUAGES
  92.   // --------------------------------------------------
  93.   AddRange($900, $97F);  // Devanagari (Hindi, Sanskrit)
  94.   AddRange($980, $9FF);  // Bengali
  95.   AddRange($A00, $A7F);  // Gurmukhi (Punjabi)
  96.   AddRange($A80, $AFF);  // Gujarati
  97.   AddRange($B00, $B7F);  // Oriya
  98.   AddRange($B80, $BFF);  // Tamil
  99.   AddRange($C00, $C7F);  // Telugu
  100.   AddRange($C80, $CFF);  // Kannada
  101.   AddRange($D00, $D7F);  // Malayalam
  102.   AddRange($D80, $DFF);  // Sinhala
  103.  
  104.   // --------------------------------------------------
  105.   // 8. MIDDLE EASTERN LANGUAGES
  106.   // --------------------------------------------------
  107.   AddRange($600, $6FF);  // Arabic
  108.   AddRange($750, $77F);  // Arabic Supplement
  109.   AddRange($8A0, $8FF);  // Arabic Extended-A
  110.   AddRange($FB50, $FDFF); // Arabic Presentation Forms-A
  111.   AddRange($5D0, $5EA);  // Hebrew
  112.   AddRange($591, $5C7);  // Hebrew Extended
  113.   AddRange($7C0, $7FF);  // N'Ko
  114.   AddRange($640, $6FF);  // Syriac
  115.  
  116.   // --------------------------------------------------
  117.   // 9. AFRICAN LANGUAGES
  118.   // --------------------------------------------------
  119.   AddRange($2C80, $2CFF); // Coptic
  120.   AddRange($2D30, $2D7F); // Tifinagh
  121.   AddRange($A6A0, $A6FF); // Bamum
  122.   AddRange($AB00, $AB2F); // Ethiopic Extended
  123.  
  124.   // --------------------------------------------------
  125.   // 10. SPECIAL CHARACTERS AND SYMBOLS
  126.   // --------------------------------------------------
  127.   AddRange($300, $36F);  // Combining Diacritical Marks
  128.   AddRange($1DC0, $1DFF); // Combining Diacritical Marks Supplement
  129.   AddRange($2000, $206F); // General Punctuation
  130.   AddRange($20A0, $20CF); // Currency Symbols
  131.   AddRange($2100, $214F); // Letterlike Symbols
  132.   AddRange($2190, $21FF); // Arrows
  133.   AddRange($2200, $22FF); // Mathematical Operators
  134.  
  135.   // Trim the array to actual used size
  136.   SetLength(cp, count);
  137.  
  138.   // Attempt to load the specified font file with all collected codepoints
  139.   if FileExists(FileName) then
  140.     Result := LoadFontEx(PChar(FileName), FontSize, @cp[0], Length(cp));
  141.  
  142.   // Fallback to default font if loading fails
  143.   if Result.texture.id = 0 then
  144.     Result := GetFontDefault();
  145.  
  146.   // Apply requested texture filter (defaults to point filtering)
  147.   SetTextureFilter(Result.texture, TextureFilter);
  148. end;
  149.  
  150. end.
  151.  
  152.  
« Last Edit: April 10, 2025, 04:56:19 am by Guva »

threedslider

  • Newbie
  • Posts: 2
Re: RayLib 5.0
« Reply #21 on: May 11, 2025, 08:19:39 pm »
Awesome ! God job !

Keep it up please the good work !  :)

I am new to Lazarus, I may ask you, this RayLib 5.0 supports to the latest with Lazarus 4.0, right ?

Thank you.

Guva

  • Full Member
  • ***
  • Posts: 179
  • 🌈 ZX-Spectrum !!!
Re: RayLib 5.0
« Reply #22 on: May 13, 2025, 05:12:07 am »
I am new to Lazarus, I may ask you, this RayLib 5.0 supports to the latest with Lazarus 4.0, right ?

Yes, it supports. Are you having any problems with the installation?

 

TinyPortal © 2005-2018