Nou Venit
Nou Venit
Mesaje: 1
Membru din: 09 Aug 2026, 02:20
  • Reacții: 7
  • Mesaje utile: 0
  • Status: Pierd vremea ^.^
  • [ID Discord]
  • Contact:
    I recently ran into a strange font rendering issue in the Metin2 client and wanted to share the solution in case somebody else encounters the same problem.

    The problem

    The ] character was rendered incorrectly in the client. A small extra pixel/artifact appeared near the bottom-right corner of the character, making it look like there was a comma or dot after it.

    [C++/Py] [FIX] Metin2 Client Extra Pixel After ] - Mesaj 1 - Imagine 1


    For example:
    [CH1]ˏ
    [15]ˏ

    At first, this looked like a chat formatting problem, especially because I was working on a custom shout chat system containing an empire flag, channel and level information.


    The important observation was this:
    ]
    could initially look correct, but after another character or even a space was rendered after it:
    ],
    ],A
    ],1
    the unwanted pixel/artifact appeared.

    The problem was especially visible with strings such as:
    [CH1]
    [15]
    [66]


    Things that did NOT fix it


    Several possible causes were tested first.

    1. Disabling text outline

    For example:
    Code:
    pChatLine->Instance.SetOutline(FALSE);
    pChatLine->InstanceChannel.SetOutline(FALSE);
    pChatLine->InstanceLevel.SetOutline(FALSE);
    This was useful for removing unwanted outlines from the custom chat elements, but it did not fix the extra pixel after ].

    So the outline renderer was not the cause.

    2. Changing the font

    The default font configuration was also tested.

    For example:
    Code:
    UI_DEF_FONT        Tahoma:12
    UI_DEF_FONT_LARGE  Tahoma:14
    UI_DEF_FONT_SMALL  Tahoma:9
    Tahoma was replaced with Arial for testing, but the artifact was still present.

    Therefore, the problem was not simply a broken ] glyph in Tahoma.

    3. Changing glyph UV coordinates

    The normal glyph rendering code in GrpTextInstance.cpp uses:
    Code:
    akVertex[0].u = pCurCharInfo->left;
    akVertex[0].v = pCurCharInfo->top;
    
    akVertex[1].u = pCurCharInfo->left;
    akVertex[1].v = pCurCharInfo->bottom;
    
    akVertex[2].u = pCurCharInfo->right;
    akVertex[2].v = pCurCharInfo->top;
    
    akVertex[3].u = pCurCharInfo->right;
    akVertex[3].v = pCurCharInfo->bottom;
    I tested shrinking the UV coordinates by half a texel:
    Code:
    const float uInset = 0.5f / textureWidth;
    const float vInset = 0.5f / textureHeight;
    This did not solve the issue and actually made the glyph rendering look worse, so the modification was reverted.

    The actual source of the problem

    The problem was eventually traced to:

    EterLib/GrpFontTexture.cpp

    inside:
    Code:
    CGraphicFontTexture::UpdateCharacterInfomation(...)
    Metin2 dynamically renders glyphs onto a DIB/GDI surface and then uses that data for its font texture atlas.

    The relevant call is:
    Code:
    TextOutW(hDC, m_x, m_y, &keyValue, 1);
    The important discovery was that the area used for the next glyph was not being explicitly cleared immediately before TextOutW() rendered the new character.

    This could leave unwanted pixel data in the glyph area. With certain characters, particularly the narrow ] glyph, the leftover data became very noticeable and looked like a comma/dot attached to the bottom-right of the character.

    The fix

    In EterLib/GrpFontTexture.cpp search:
    Code:
    CGraphicFontTexture::UpdateCharacterInfomation(...)
    TextOutW(hDC, m_x, m_y, &keyValue, 1);
    Before TextOutW(), explicitly clear the rectangle that will contain the new glyph.

    Replace:
    Code:
    TextOutW(hDC, m_x, m_y, &keyValue, 1);
    with:

    Conținut: Ascuns
    Reacționează ❤️ la acest mesaj și conținutul se va afișa automat.


    So the important fix is:

    Conținut: Ascuns
    Reacționează ❤️ la acest mesaj și conținutul se va afișa automat.


    After recompiling the client, the unwanted dot/comma-like artifact after ] disappeared.

    Custom shout chat notes

    While debugging this, I was also implementing a custom shout layout:
    [Empire Flag] [CH1] [LEVEL] PlayerName: Message
    Instead of trying to align everything using spaces in the server-generated string, the channel and level were separated into their own CGraphicTextInstance objects:
    Code:
    InstanceChannel
    InstanceLevel
    Instance
    This allows the empire flag, channel, level and normal chat text to be positioned independently.

    One important detail when extracting [LEVEL] is preserving the brackets for rendering.

    To display:
    Code:
    [15]
    use:

    Conținut: Ascuns
    Reacționează ❤️ la acest mesaj și conținutul se va afișa automat.


    But to obtain only the numeric value for level-based coloring:

    Conținut: Ascuns
    Reacționează ❤️ la acest mesaj și conținutul se va afișa automat.


    So:
    Code:
    levelText  = [15]
    numberText = 15
    These should not be confused.

    The same principle applies to [CH1] if the brackets need to remain visible.

    Final result

    The final shout layout works correctly:
    [Empire Flag] [CH1] [66] PlayerName: Message
    The channel and level can have independent colors and positions, and the strange artifact after ] is gone.

    TL;DR

    If your Metin2 client renders something that looks like an extra . or , after ], especially after another character is added, check:

    EterLib/GrpFontTexture.cpp
    Code:
    CGraphicFontTexture::UpdateCharacterInfomation()
    Clear the glyph's DIB area before calling TextOutW():

    Conținut: Ascuns
    Reacționează ❤️ la acest mesaj și conținutul se va afișa automat.


    That was the actual fix in my case.

    Hope this saves somebody else a few hours of debugging.

    Nou Cum descarc de pe TeraBox?

    Afișează detalii Ascunde detalii
    • Este asemănător cu Mega.nz
    • Instalați-vă clientul lor de Download de aici
    • Faceți-vă un cont (vă puteți loga cu Facebook / Google / etc)
    • Nou Dacă nu vreți să descărcați clientul de Download, folosiți acest site
    • Gata! Acum puteți descărca resursele rapid & simplu.

    De ce folosim TeraBox?

    • Este gratuit
    • Primești 1TB de spațiu gratuit la orice cont creat!
    • Este ușor de folosit și varianta premium este foarte ieftină
    • Fișierele nu sunt șterse niciodată
    TeraBox logo
    Administrator
    Administrator
  • Mesaje: 4711
    Membru din: 07 Aug 2024, 21:53
  • Reacții: 107918
  • Mesaje utile: 45
  • Status: Pe aici.. 🤠
    Server: Saga2 - Soon
  • Regat: Jinno
  • [ID Discord]
  • Contact:
    Avatar utilizator
    Administrator
    Administrator

    Mesaj de SCOOB »

    Topic aranjat - Multumim de FIX! :)
    Comunitatea Metin2 Romania este si pe Discord! :ymcowboy:

    2500+ membri • Chat activ zilnic • Support • Cereri & Resurse

    ► discord.gg/jWxeDSf7HP ◄





    See full signature
    Scrie răspuns

    Creează-ți un cont sau autentifică-te pentru a participa la discuție

    Trebuie să fii membru pentru a răspunde

    Creează-ți un cont

    Membrii pot crea subiecte noi și pot descărca resurse Metin2 Gratuit!


    Te poți înregistra sau conecta rapid utilizând contul tău de Discord, Github sau Google.

    Înregistrare

    Autentifică-te

    Înapoi la “Îmbunătățiri”

    Informații

    Utilizatori ce navighează pe acest forum: Google [Bot], mihaiolt112, one Key, The God și 1 vizitator

    Discord ID copiat: