integer drawing with fonts [SOLVED]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Sigutis
Posts: 10
Joined: Thu May 01, 2008 8:51 am
Location: Lithuania

integer drawing with fonts [SOLVED]

Post by Sigutis »

I was recently using these handy font functions, and I would like to use it to print integer values. I am not really familiar with const wchar_t * so I cant write a converter of my own.

Code: Select all

font->draw(L"Bloodyness",rect<s32>(5,80,300,50),SColor(255,255,255,255));
font->draw(integer,rect<s32>(5,80,300,50),SColor(255,255,255,255));
And by the way, what is the

Code: Select all

L
for?
Last edited by Sigutis on Fri May 30, 2008 5:52 am, edited 1 time in total.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

You have to use swprintf to format your string. Like this:

Code: Select all

#include <stdio.h>
..

wchar_t myString[64];
swprintf(myString, 64, L"Bloodyness: %i and something else: %i", integer, anotherInteger);
font->draw(myString, rect<s32>(5,80,300,50),SColor(255,255,255,255)); 

pelonzudo
Posts: 20
Joined: Wed May 07, 2008 11:14 am

Post by pelonzudo »

Here you got my two funcions:

Code: Select all

char* wcharToChar (const wchar_t* cadena) {

    size_t alloc_len = wcslen(cadena) + 1;
    char* retorno = new char[alloc_len];
    size_t result = wcstombs (retorno, cadena, alloc_len);
    return retorno;
}

wchar_t* charToWchar (const char* cadena) {

    size_t alloc_len = strlen(cadena) + 1;
    wchar_t* retorno = new wchar_t[alloc_len];
    size_t result = mbstowcs (retorno, cadena, alloc_len);
    return retorno;
}
Afeter use it you sould delete the pointer

Code: Select all

PointerNeeded* pointer = function(...);

//use here the pointer

delete[] pointer
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

For numbers you can also just use the stringw constructor: core::stringw(intvariable).c_str()
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Re: integer drawing with fonts [SOLVED]

Post by JP »

And by the way, what is the L for?
L species that it's a wide character string (wchar_t, rather than char).

I tend to use the stringw class for handling wchar_ts in irrlicht as it makes it all a lot easier. But it's also good to know how the manipulate strings yourself with the standard functions.
Image Image Image
Post Reply