Rendering multi-coloured text

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Rendering multi-coloured text

Post by Richard Russell »

If you are rendering text using the gfxlib (high-performance game graphics) library you are likely to be using the FN_gfxCreateTextureFromText function. This takes the RGB colours of the text as parameters:

Code: Select all

      FN_gfxCreateTextureFromText(t$,R%,G%,B%,W%,H%)
      R%,G%,B%: Text colour (red, green, blue: 0-255)
But what if you don't want all of the text to be in the same colour? You can cheat by embedding GCOL codes in the text string! For example:

Code: Select all

      text$ = CHR$18+CHR$0+CHR$7 +"B" + CHR$18+CHR$0+CHR$9 +"B" + CHR$18+CHR$0+CHR$10+"C "+ \
      \       CHR$18+CHR$0+CHR$11+"B" + CHR$18+CHR$0+CHR$12+"A" + CHR$18+CHR$0+CHR$13+"S" + \
      \       CHR$18+CHR$0+CHR$14+"I" + CHR$18+CHR$0+CHR$15+"C"
      tex%% = FN_gfxCreateTextureFromText(text$, 0, 0, 0, W%, H%)
Now the colours can be anything you like (up to a maximum of 127 different colours per string) by setting the palette beforehand.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Rendering multi-coloured text

Post by Richard Russell »

Richard Russell wrote: Thu 12 Sep 2024, 11:53 You can cheat by embedding GCOL codes in the text string!
FN_gfxCreateTextureFromText() uses logical colour 1 internally. If you adopt this technique, avoid logical colour 1 (or pass the wanted physical colour for its palette entry in the function call).