extended ascii (, ,...)

Started by
45 comments, last by Evil Steve 13 years, 4 months ago
I'm trying to get the letter "é" to show in the application (Win32 c++ app, with some opengl, using Visual Studio 2008).

std::ostringstream output;
output.setf(std::ios::fixed, std::ios::floatfield);
output << std::setprecision(2);
output << "Sensibilité: " << mouse.weightModifier();
g_font.drawText(1, 1, output.str().c_str());

I tried :

output << "Sensibilit" << char(130): " << mouse.weightModifier();
output << "Sensibilit\x82: " << mouse.weightModifier();

No "é" showed, just "Sensibilit".

Anyone have a solution for this?
Advertisement
What is g_font, what encoding does its drawText method expect and in what encoding is the text that are you giving it?
Like the_edd says, it depends entirely on the font/font library you're using.

The first obvious thing to check is whether said font library and font claim to support extended ASCII, and if so if you've enabled it (have set the correspond character set or some such).

I can't help with Win32 API specifics I'm afraid
Quote:Original post by the_edd
What is g_font, what encoding does its drawText method expect and in what encoding is the text that are you giving it?


void GLFont::drawText(int x, int y, const char *pszText)
{

}


Quote:Original post by Beyond_Repair
Like the_edd says, it depends entirely on the font/font library you're using.

The first obvious thing to check is whether said font library and font claim to support extended ASCII, and if so if you've enabled it (have set the correspond character set or some such).

I can't help with Win32 API specifics I'm afraid


Where do i find the font library i'm using in the project?

I don't know if it matters, but in Configuration Properties, under general, Character Set is set to Use Multi-Byte Character Set.
Quote:Original post by m_power_hax
Where do i find the font library i'm using in the project?
How do you draw the text? What do you use? You must have some way to map characters to something visible on the screen. E.g. cout, using a bitmap font you created, using some library you downloaded, using the GDI DrawText() function, using SDL_ttf, etc.
Quote:Original post by Evil Steve
Quote:Original post by m_power_hax
Where do i find the font library i'm using in the project?
How do you draw the text? What do you use? You must have some way to map characters to something visible on the screen. E.g. cout, using a bitmap font you created, using some library you downloaded, using the GDI DrawText() function, using SDL_ttf, etc.


Ok well here some code :

From main.cpp
std::ostringstream output;output.setf(std::ios::fixed, std::ios::floatfield);output &lt;&lt; std::setprecision(2);output &lt;&lt; "  Sensibilit\x82: " &lt;&lt; mouse.weightModifier();g_font.begin();g_font.setColor(0.2f, 0.70f, 0.8f);g_font.drawText(1, 1, output.str().c_str());g_font.end();

From gl_font.cpp
void GLFont::begin(){    HWND hWnd = GetForegroundWindow();    RECT rcClient;    GetClientRect(hWnd, &rcClient);    int w = rcClient.right - rcClient.left;    int h = rcClient.bottom - rcClient.top;        glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT);    glDisable(GL_LIGHTING);    glEnable(GL_BLEND);    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);    glEnable(GL_TEXTURE_2D);    glBindTexture(GL_TEXTURE_2D, m_textureObject);    glMatrixMode(GL_PROJECTION);    glPushMatrix();    glLoadIdentity();    glOrtho(0.0f, w, h, 0.0f, -1.0f, 1.0f);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();       drawTextBegin();}void GLFont::drawTextBegin(){    m_numCharsToDraw = 0;    m_pVertex = m_vertices;}void GLFont::drawChar(char c, int x, int y){    //  1------4    //  |      |            1 = (x, y)    //  |      |            2 = (x, y + charHeight)    //  |      |            3 = (x + charWidth, y + charHeight)    //  |      |            4 = (x + charWidth, y)    //  |      |    //  |      |    //  2------3    //    const Glyph &glyph = getChar(c);    int charWidth = glyph.width;    int charHeight = m_charHeight;    if (m_drawDropShadows)    {	  //bunch of m_pVertex-&gt; calls	  //...        //...        if (++m_numCharsToDraw == MAX_CHARS_PER_BATCH)        {            drawTextEnd();            drawBatchOfChars();            drawTextBegin();        }    }    //bunch of m_pVertex-&gt; calls    //...    //...    if (++m_numCharsToDraw == MAX_CHARS_PER_BATCH)    {        drawTextEnd();        drawBatchOfChars();        drawTextBegin();    }}void GLFont::drawText(int x, int y, const char *pszText){    char prevCh = 0;    char ch = 0;    int dx = x;    int dy = y;    int charHeight = getCellHeight();    int whitespaceWidth = getChar(' ').width;    while (*pszText != '\0')    {        prevCh = ch;        ch = *pszText++;        if (ch == ' ')        {            if (prevCh != '\r')                dx += whitespaceWidth;        }        else if (ch == '\n' || ch == '\r')        {            dx = x;            dy += charHeight;        }        else if (ch == '\t')        {            dx += whitespaceWidth * TAB_SPACES;        }        else if (ch &gt;= CHAR_FIRST && ch &lt;= CHAR_LAST)        {            drawChar(ch, dx, dy);            dx += getChar(ch).width;        }    }}void GLFont::drawChar(char c, int x, int y){    //  1------4    //  |      |            1 = (x, y)    //  |      |            2 = (x, y + charHeight)    //  |      |            3 = (x + charWidth, y + charHeight)    //  |      |            4 = (x + charWidth, y)    //  |      |    //  |      |    //  2------3    //    const Glyph &glyph = getChar(c);    int charWidth = glyph.width;    int charHeight = m_charHeight;    if (m_drawDropShadows)    {	  //bunch of m_pVertex-&gt; calls	  //...        //...        if (++m_numCharsToDraw == MAX_CHARS_PER_BATCH)        {            drawTextEnd();            drawBatchOfChars();            drawTextBegin();        }    }    //bunch of m_pVertex-&gt; calls    //...    //...    if (++m_numCharsToDraw == MAX_CHARS_PER_BATCH)    {        drawTextEnd();        drawBatchOfChars();        drawTextBegin();    }}

Anything else needed?
Please use [ source ] tags in future (I've added them to your post this time).

So m_textureObject is a 2D texture containing the characters you need then (A bitmap font) - does it actually have an 'é' character on it?
Quote:Original post by Evil Steve
Please use [ source ] tags in future (I've added them to your post this time).

So m_textureObject is a 2D texture containing the characters you need then (A bitmap font) - does it actually have an 'é' character on it?


Would changing every const char to const wchar_t be the solution?
Quote:Original post by m_power_hax
Quote:Original post by Evil Steve
Please use [ source ] tags in future (I've added them to your post this time).

So m_textureObject is a 2D texture containing the characters you need then (A bitmap font) - does it actually have an 'é' character on it?


Would changing every const char to const wchar_t be the solution?
No - if the texture doesn't have an image for an 'é' character, you can't draw it. Characters are just a bunch of images after all.

This topic is closed to new replies.

Advertisement