How to change text fonts

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
Guest

How to change text fonts

Post by Guest »

does anyone know how to change the font color( normaly black)
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

Post by [ds] Swift »

depends on how you are displayling your font really.

using IGUIStaticText this is how you would do it:

declare a pointer and create your text:
Example:

Code: Select all

IGUIStaticText *text = guienv -> addStaticText( L"hi", rect<s32>( 10, 10, 200, 22 ) );
next to change the color you need to enable the color override

Code: Select all

text -> enableOverrideColor( true );
then set your override color to the text

Code: Select all

text -> setOverrideColor( irr:video::SColor( alpha, red, green, blue ) );
change the alpha, red, green, blue in the code to integers from 0 - 255. if you need a guide on what colors different combinations make, open up MS Paint and goto Colors | Edit Colors | Define Custom Colors and pick your color and copy the RGB settings on the right into your program.

obviously you could also make an image and use draw2DImage.

you could also get fancy and make textured 3D text models :)
Last edited by [ds] Swift on Mon Nov 29, 2004 4:06 am, edited 1 time in total.
There's a crack in everything -- That's how the light gets in.
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

Complete example

Post by [ds] Swift »

Here is a program that displays colored text on the screen.

Code: Select all

/* irrlicht includes */
#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment( lib, "Irrlicht.lib" )

/* program start */
int main() { 
	IrrlichtDevice *device = createDevice( EDT_SOFTWARE, dimension2d<s32>( 640, 480 ), 128, false, false, false, 0 ); 

	device->setWindowCaption( L"NaNoCrON software - Irrlicht Test" ); 

	IVideoDriver* driver = device->getVideoDriver(); 
	ISceneManager* smgr = device->getSceneManager(); 
	IGUIEnvironment* guienv = device->getGUIEnvironment(); 

	/***********************/
	/* TEXT WORK DONE HERE */
	IGUIStaticText *text = guienv -> addStaticText( L"Hi", rect<s32>( 10, 10, 200, 22 ) ); 
	text -> enableOverrideColor( true );
	text -> setOverrideColor( SColor( 0, 255, 0, 0 ) );
	/***********************/

	while( device->run() ) { 
		driver->beginScene( true, true, SColor( 0, 200, 200, 200 ) ); 

		smgr->drawAll(); 
		guienv->drawAll(); 

		driver->endScene(); 
	} 

	device->drop(); 

	return 0; 
}
Hope it helps :D
There's a crack in everything -- That's how the light gets in.
Post Reply