WChar functs

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
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

WChar functs

Post by keless »

Hey, I want to print out a score or FPS, which will obviously have different 'text' each time.

I will use the IGUIFont object to draw, but I need to figure out how to format the text. In plain char* I would do sprintf(mystr, "Score: %d", myscore); .. how do i do it for WChar?

TIA
a screen cap is worth 0x100000 DWORDS
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Is this what you're looking for?

Code: Select all

wchar_t _Info[1024]; 
int fps = Driver->getFPS();
swprintf(_Info, 1024,"FPS: %d ",fps);
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

that will definately do it.

also, how would I do it with irr::core::stringw?
a screen cap is worth 0x100000 DWORDS
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

It's not possible to convert numbers into a irr:string with it's methds. You would have to use swprintf(). But that's a feature I should do on my TODO-list.
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Post by Serg Nechaeff »

Pick up my function:

Code: Select all

void StringTextOut (gui::IGUIFont * font, int x, int y ,wchar_t text[], int d=-100)

{

	wchar_t tmp [1024];      
	if (d==-100)   
		swprintf ( tmp, 1024, L"%s", text );
	else
		swprintf ( tmp, 1024, L"%s = %d", text, d );

    font->draw ( tmp, 
                core::rect<s32>(x,y,300,80),
                video::SColor(255,255,255,255));	
}
plainn text:StringTextOut(font, 0 ,10, L"Programmed by Me" );

text + integer value
StringTextOut(font2, 0,20, L"Score: ", Score );
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

how about this one:

Code: Select all

void dout(const char *msg, ...)
{
	va_list argList;
	static char buffer[512] = { 0 }; //max 512 chars long

	va_start(argList, msg);
	vsprintf(buffer, msg, argList);
	
	va_end(argList);
// do something with 'buffer'
// i send my debug output to a file but you can
// send to console via os::Printer::log(buffer);
// or to screen using font->draw

// if you need to turn it into a wchar_t then do this
// wchar_t text[512];
// mbstowcs(text,buffer,512);
}
use it like this:
dout("There are %d ways to code a %s solution\n",10,"working");

just like a printf statement!
Post Reply