Jump to content
  • Advertisement
Sign in to follow this  
m_power_hax

extended ascii (, ,...)

This topic is 2744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
What is g_font, what encoding does its drawText method expect and in what encoding is the text that are you giving it?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)
{

}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!