is there a way of writing text to a texture????

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

is there a way of writing text to a texture????

Post by nebukadnezzar »

is there a way of writing text to a texture????

i've tried to code it on my own...
but i alwas get an acces violation error....

CGUIFont.cpp: (changed header files are not shown)

Code: Select all

void CGUIFont::drawTexture(video::ITexture* dest, const wchar_t* text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter)
{
	if ((!Driver) || (!dest))
		return;

	core::dimension2d<s32> textDimension;
	core::position2d<s32> offset = position.UpperLeftCorner;

    if (hcenter || vcenter)
	{
		textDimension = getDimension(text);

		if (hcenter)
			offset.X = ((position.getWidth() - textDimension.Width)>>1) + offset.X;

		if (vcenter)
			offset.Y = ((position.getHeight() - textDimension.Height)>>1) + offset.Y;
	}

	u32 n;
	
	while(*text)
	{
		n = (*text) - 32;
		if ( n > Positions.size())
			n = WrongCharacter;

		BlitTexture(dest,Texture,core::rect<s32>(offset.X,offset.Y,dest->getDimension().Width,dest->getDimension().Height),Positions[n] );
		        
		offset.X += Positions[n].getWidth();

		++text;
	}
}
the used blit function: (also my own crap)
(is not supporting transparency)

Code: Select all

s32 BlitTexture(video::ITexture *dest, video::ITexture *src, core::rect<s32> destrec, core::rect<s32> srcrec )
{
	if ( (!dest) || (!src)) return 0;
	if (src->getColorFormat() != dest->getColorFormat()) return 0;

	s32 spitch = src->getPitch();
	s32 dpitch = dest->getPitch();
	
	s32 pixsize = spitch / src->getDimension().Width;
	if (pixsize != (dpitch / dest->getDimension().Width)) return 0;

	destrec.clipAgainst(core::rect<s32>(core::position2d<s32>(0,0),dest->getDimension()) );
  	srcrec.clipAgainst(core::rect<s32>(core::position2d<s32>(0,0),src->getDimension()) );

	core::rect<s32> cprec(srcrec);
	cprec.clipAgainst(destrec);	

	s32 newpitch = pixsize * cprec.getWidth();

	c8 *s = (c8*) src->lock();
	c8 *d = (c8*) dest->lock();

	for (s32 i = 0; i < cprec.getHeight(); i++)
		memcpy(
			d + ((destrec.UpperLeftCorner.Y + i) * dpitch) + (pixsize * destrec.UpperLeftCorner.X) ,
			s + ((srcrec.UpperLeftCorner.Y + i) * spitch) + (pixsize * srcrec.UpperLeftCorner.X),newpitch );

	src->unlock();
	dest->unlock();
	
	return 1;
};
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

did you ever figure this out? *bump*
a screen cap is worth 0x100000 DWORDS
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

Post by nebukadnezzar »

had had a function wich worked - but not with full features....
the text appeard on the texture - but you couldn't change the color...
but since the 4.2 ver i would prefer to write the text on an IImage
but at the lack of time i haven't tried this yet.

(i'm working on a card game called "illuminati - the game of conspiracy"
and i'm involved in design and setting up the main functions.
i will go back later to the Graphics and User-Interface
... may be i'm doing this with irrlicht....)
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

does that card game have anything to do with the Steve Jackson card game "Illuminati - New World Order"?
a screen cap is worth 0x100000 DWORDS
nebukadnezzar
Posts: 25
Joined: Tue Dec 02, 2003 7:45 pm
Location: Germany - Bornheim

Post by nebukadnezzar »

It has.
It is also desgined by Steve Jackson and the first release was in 1982
It is similar - the goal is to rule the world...
but it is not a card-trading game
look at http://sjgames.com/illuminati
Post Reply