String drawing

Information about the engine technology is revealed and discussed here
Post Reply
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

String drawing

Post by Rookie One.pl »

OK, treat this thread as a kind of engine documentation. ;)

I've implemented RitualFont support, which works alongside Q3's FreeType renderer. Both font formats can now be used interchangeably.

So, to put it simply, the message of the day is:
From now on all the internal cgame and/or UI text drawing routines should be abandoned in favour of the following engine traps:
  • trap_R_RegisterFont - loads and prepares a font for use
  • trap_R_Text_Width - returns length of a string rendered with the given font in pixels
  • trap_R_Text_Height - returns height of a string rendered with the given font in pixels
  • trap_R_Text_Paint - draws a string using given font
  • trap_R_Text_PaintChar - draws a single character using given font
See the declarations of these functions for details.

Colouring: the string painter has support for Quake colour codes, which can be switched off by the last parametre. For single characters and strings that don't use the colour codes, call trap_R_SetColor with an appropriate vec4_t before calling trap_R_Text_Paint*. Calling trap_R_SetColor(NULL) afterwards is good practice.
trap_R_Text_Paint has an alpha parameter which is only taken into account when using the colour codes to set the entire string's transparency.
For text with drop shadow, draw the same string using the black colour and offsetting it to the right and bottom before drawing the actual string.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
wombat23
Sergeant
Posts: 54
Joined: Wed Feb 06, 2008 6:48 pm
Location: Zürich, CH

Post by wombat23 »

there is some bug, which i dont know whats wrong about:

calling from inside cgame (CG_Draw2D)

Code: Select all

	trap_R_Text_Paint( &font1, 20, 20, 1, 1, "wombat TEsT!", 0, 0 );
	trap_R_Text_Paint( &font1, 20, 40, 1, 1, "wombat TEsT!", 0, 1 );
the first one works (it has useColorcodes 0) but the second one only draws the first character (w)
i just cant see whats wrong cause there should be no difference since the text string obviously doesnt contain any colour code.

any idea?
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Nope. :? Try debugging it - run it in gdb and track what's going on in R_Text_Paint.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
wombat23
Sergeant
Posts: 54
Joined: Wed Feb 06, 2008 6:48 pm
Location: Zürich, CH

Post by wombat23 »

setting the last parameter to 2 will draw the first 2 letters, so the last 2 parameters are somehow confused. i'll track that down tomorrow...
wombat23
Sergeant
Posts: 54
Joined: Wed Feb 06, 2008 6:48 pm
Location: Zürich, CH

Post by wombat23 »

you mixed up parameters for Text_Paint function. sometimtes it has 8 parameters and sometimes 9. it's the "adjust" parameter. maybe you wanted to omit it? i'll add it to all definitions so that it s consistent again.

man, took me 2 hours to find that out :twisted:


//
now i'm trying to call Text_Paint from within the main menu. it doesnt draw... but i guess you don't know whats wrong with that, either :x


// OK, similar problem. fixed now...
Last edited by wombat23 on Mon Sep 01, 2008 2:08 pm, edited 1 time in total.
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Ah, my bad. :oops: The parameter list in cgame and UI's trap list was different than the actual function, right? Dammit, I was trying so hard not to make this mistake. :?

I take it you're calling it from the UI module? Have you registered the font first? Check if the trap is called on the engine part at all.

Sorry I haven't given it thorough enough testing. :?
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
wombat23
Sergeant
Posts: 54
Joined: Wed Feb 06, 2008 6:48 pm
Location: Zürich, CH

Post by wombat23 »

it is fixed now. apart from crashing when i open console, which must be some silly bug, everything should be ok now. that should provide us with a basic menu so that we dont need the Q3 media anymore for text

//edit:

in code/client/cl_keys.c in line 383 you made some mistake that causes a write operation to str[-1] which makes it kind of a russian crash roulette.

i'm trying to figure out what you had in mind when writing this code... i think resolved it...
m0d hippY
Warrant Officer
Posts: 132
Joined: Tue Apr 27, 2004 3:58 am

Post by m0d hippY »

haha, I don't know why, but this made me laugh haha:
you made some mistake that causes a write operation to str[-1] which makes it kind of a russian crash roulette.
Anywho, good job so far Wombat, keep up the good work man!
Image
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Don't blame me, I haven't done anything with that code. :? AFAICR that function is used for drawing some parts of the UI (edit fields I think), but I think I neither ever touched it nor used it in any of my code. :?

Anyhoo, good job on fixing it. :)

<EDIT>Ah, no, now I remember, I did it when porting the console from drawing single characters to entire strings. Still can't remember what was the intention of the -1, though.</EDIT>
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply