Coloured Text

Previous topic - Next topic

mrplant

Hi.

I would like to change the colour of text used in the PRINT command like Blitz used to do..

It doesn't look like this is built into GLBasic however..

Anyone else had this and found a solution?

Crivens

Google the forum. There is definitely some code that does some pretty good things with fonts, and I'm pretty sure one of them is changing the colour. Only downside is the code is for freeware only.

On the other hand being able to change the colour of text limits how good it can look really. If you see what you can get out of font creation tools or the tool that is included with GLB (esp the new version - Dingfont I think it is called) then you can get some amazing stuff which really won't have any reason to change colour (impossible to really do that without the whole effect looking worse). Personally I just use this and then if I want a different colour just create a different font from the project but with a different colour/texture/gradient.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Ian Price

#2
There are several possible options for this -

1) Use a bitmap font - you can create several different colour fonts
2) Use a bitmap font - one colour, but use a colour POLYVECTOR to display it
3) Create a virtual screen (CREATESCREEN, USESCREEN) to PRINT your text to and then use a colour POLYVECTOR to display it.


Here is a version of number 3, above.

Code (glbasic) Select

SETSCREEN 640,480,0

GLOBAL a,b,c, press, text$[]

DIM text$[100]

text$[0]="HOWDY"
text$[1]="GOOD DAY"
text$[2]="BON JOUR"
text$[3]="PARDON ME!"
text$[4]="OOOOOOOPS"
text$[5]="WHATEVER!"
text$[6]="YEAH, BUT NO, BUT..."
text$[7]="EUSTON STATION"
text$[8]="LAPTOP"
text$[9]="TOUCHPAD"


// Create virtual screen
CREATESCREEN 1,999,100,20

// Draw on virtual screen
USESCREEN 1

PRINT "HELLO",0,0

// All drawing to be donw on actual visible screen from now on
USESCREEN -1

// Set the initial random colour for text
a=RND(255)
b=RND(255)
c=RND(255)

WHILE TRUE

DRAWRECT 0,0,640,480,RGB(128,128,128)

PRINT "USE SPACE TO CHANGE TEXT COLOUR",10,10

PRINT "USE ENTER TO CHANGE THE TEXT",10,30

// Change text colour by pressing SPACE
IF KEY(57) AND press=0
a=RND(255)
b=RND(255)
c=RND(255)
press=7
ENDIF

// Display coloured text
STARTPOLY 999
POLYVECTOR 100,100,0,0,RGB(a,b,c)
POLYVECTOR 200,100,100,0,RGB(a,b,c)
POLYVECTOR 200,120,100,20,RGB(a,b,c)
POLYVECTOR 100,120,0,20,RGB(a,b,c)
ENDPOLY

// Reduce keypress speed
IF press>0 THEN DEC press

// Press ENTER to change test
IF KEY(28) AND press=0
USESCREEN 1

// Clear graphic
DRAWRECT 0,0,100,16,RGB(255,0,128)

PRINT text$[RND(9)],0,10
 
USESCREEN -1

press=7
ENDIF

SHOWSCREEN

WEND


This code allows you to change the text colour and what the text actually states. As an added bonus, by changing some of the first two values in the POLYVECTOR routine, you can also scale the text.

[EG] Try changing the above POLY routine with this -
Code (glbasic) Select

STARTPOLY 999
POLYVECTOR 100,100,0,0,RGB(a,b,c)
POLYVECTOR 300,100,100,0,RGB(a,b,c)
POLYVECTOR 300,140,100,20,RGB(a,b,c)
POLYVECTOR 100,140,0,20,RGB(a,b,c)
ENDPOLY


You can use this however you wish. :)
I came. I saw. I played.

Minion

Heres a version for version 2

Code (glbasic) Select

FUNCTION Prnt:a$,x,y,cl,cl2,scx,scy

// x,y     - Center point of text
// cl      - top colour of text
// cl2     - bottom colour of text
// scx,scy - Scaling factor for text (1 = normal, 2 = double size, 0.5 = half size etc)

// Needs bitmap font loaded into sprite id 1000 (Use GLBs Font creator to make, or use other bitmap font)
// size of font needs to be 32x32, 16 chars accross, 8 down

LOCAL xx,yy,a,Nm
LOCAL nx,ny,nx2,ny2

Nm=LEN(a$)-1
STARTPOLY 1000,2
FOR m=0 TO Nm

a=ASC(MID$(a$,m,1))

yy= INTEGER((a/16))*32
xx= MOD(a,16)*32


nx=(((m*2)-Nm)-1)*(16*scx)
nx2=((((m+1)*2)-Nm)-1)*(16*scx)
ny=16*scy
ny2=16*scy

POLYVECTOR x+nx,y-ny,   xx,yy,       cl
POLYVECTOR x+nx,y+ny,   xx,yy+32,    cl2
POLYVECTOR x+nx2,y-ny,  xx+32,yy,    cl
POLYVECTOR x+nx2,y+ny,  xx+32,yy+32, cl2

NEXT
ENDPOLY

ENDFUNCTION



This gives sentral justified text of any colour/size. Shouldn`t be too hard to chage it to left/right justify it. I started using this method after the method Ian posted became way too slow on the Pandora.

Kitty Hello

glColour stuff usually is very slow on mobile devices. True shame.

mrplant

Thanks all for brilliant replies - I was thinking along the lines of creating a new font in the chosen colour I wanted but I also wanted to try random rather than fixed colour fonts..

I have a few good things to go test now - many thanks everyone..

I will report back performance on iPad2 later!

aroldo

#6
mrplant,

Just saw your post today.

Create you fonts BMP or PNG files using the GLBasic "Fonte Creator" under the Tools.
Then use SET FONT to change the font to the desired color.

Below is a piece of my code. It is working fine in my game.

Code (glbasic) Select

LOADFONT "fonts/APDfont_Red.bmp",0
LOADFONT "fonts/APDfont_Green.bmp",1
LOADFONT "fonts/APDfont_Blue.bmp",2
LOADFONT "fonts/APDfont_Cyan.bmp",3
LOADFONT "fonts/APDfont_Orange.bmp",4
LOADFONT "fonts/APDfont_Grey.bmp",5
LOADFONT "fonts/APDfont_Brown.bmp",6
LOADFONT "fonts/APDfont_Yellow.bmp",7
LOADFONT "fonts/APDfont_White.bmp",8

// ------------------------------------------------------------- //
// ---  SCOREUPDATE  ---
// ------------------------------------------------------------- //
SUB scoreUpdate:
   SETFONT 0 // red
   PRINT hiscore,40,50
   SETFONT 1 // green
   PRINT score,120,50
   SETFONT 3 // cyan
   PRINT level,200,50
   SETFONT 2 // blue
   PRINT balls,280,50
   SETFONT 7 // white
   IF (score > hiscore)
      hiscore = score
      IF (scoreup)
      scoreup = FALSE
         IF sound
            play(2) //Fame
         ENDIF
      ENDIF
   ENDIF

ENDSUB // SCOREUPDATE


@Edit - added [ code ] blocks
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2

matchy

The idea of real-time masking a white on black (or is it black on white?) is the only way to produce 16 million color fonts by drawrect, multi-colored texture or even patterned textured fonts with polydraw. The only issue is that it is obviously not recommended for for games requiring high fps animation. The other managing alternative is to per-create the know "texture" colors in run-time or level title screen.