text color change

Blitz3D Forums/Blitz3D Programming/text color change

Gauge(Posted 2012) [#1]
I'm writing a client but am unsure how or the best way to do this.
I need to display the line read into different colors but cannot seem to change colors in the text command.
Say I wanted to text "HOME" Each letter in a different color how to do so?

For example...
Text 100,100 "H"+color1+"O"+color2+"M"+color3+"e"

Or would I be better off using images....speed is an issue. Thanks for any help


Yasha(Posted 2012) [#2]
The colour of the result of the "Text" command is set by "Color". This means you have to change color in between calls (you'll definitely need a custom solution if you want to encode colours into the passed string).

You probably are better off using some image-based system, as Text is very, very slow; but how to do it depends on the structure and nature of your application.

Last edited 2012


PowerPC603(Posted 2012) [#3]
I have tried something like this before using this code:
Graphics 800, 600, 0, 2

Type tCol
	Field fRed
	Field fGreen
	Field fBlue
End Type

; Init colors
Global ColRed.tCol = New tCol
ColRed\fRed = 255
ColRed\fGreen = 0
ColRed\fBlue = 0
Global ColGreen.tCol = New tCol
ColGreen\fRed = 0
ColGreen\fGreen = 255
ColGreen\fBlue = 0
Global ColBlue.tCol = New tCol
ColBlue\fRed = 0
ColBlue\fGreen = 0
ColBlue\fBlue = 255
Global ColWhite.tCol = New tCol
ColWhite\fRed = 255
ColWhite\fGreen = 255
ColWhite\fBlue = 255
Global ColYellow.tCol = New tCol
ColYellow\fRed = 255
ColYellow\fGreen = 255
ColYellow\fBlue = 0

PrintColored3(ColRed, "This ", ColGreen, "is ", ColBlue, "a test")
PrintColored3(ColWhite, "using multi-", ColYellow, "colored lines ", ColRed, "on one line")





WaitKey()
End


Function PrintColored3(Col1.tCol, String1$, Col2.tCol, String2$, Col3.tCol, String3$)
	Color Col1\fRed, Col1\fGreen, Col1\fBlue
	Write String1$
	Color Col2\fRed, Col2\fGreen, Col2\fBlue
	Write String2$
	Color Col3\fRed, Col3\fGreen, Col3\fBlue
	Print String3$
End Function


It uses the "Write" command instead of "Print", as Write does the same without actually ending the line.
Only the last part of the text uses "Print" to end the line.

It uses custom types to setup the colors, but you can modify it to use hex-codes if you like (or anything else).
If you need more parameters (more or less than 3), you can write a similar function and add a new parameter so you can have 4 or 5 different colors on one line.

Last edited 2012


Rroff(Posted 2012) [#4]
Very quick and dirty replacement function for rendering text with inline hints for changing color/style etc. its incomplete code probably buggy/slow but functional and should be easy enough to extend/debug - I'll prolly flesh it out with the extra functions i.e. replacements for stringwidth, ability to render different fonts other than the default one or import custom ones, etc. at a later date as its potentially useful and easy enough to speed up significantly.



It could be adjusted back to just use the text command with the inline parser for style/color hints but the intention with this code is to move towards a faster rendering solution as well as more flexible solution than the normal text command.

Last edited 2012