GLBasic forum

Codesnippets => Code Snippets => Topic started by: I love my Brick on 2012-Jun-11

Title: Altering the colour and size of GLBasics preset Font
Post by: I love my Brick on 2012-Jun-11
Just thought this might be handy for new projects.  Instead of bothering with a new font set why not enlarge the original and effect its colour value.  The code grabs a line of text as a sprite and then messes with its RED value - no need to look at GREEN & BLUE cos they are all 255.  It then doubles the size of the sprite and makes it more readable on screen.  Handy for laying out the text on screen.


...

Code (glbasic) Select

example=500 ; newone=501

PRINT "A COLOURED FONT TO PLAY WITH",0,0

GRABSPRITE example,0,0,256,10

CLEARSCREEN

//////////////////////////////////////////////////////

FOR ypos=0 TO 500 STEP 8 ; DRAWSPRITE example,100,ypos

GOSUB recolourgraphics

DRAWSPRITE newone,200,ypos

ZOOMSPRITE newone,RND(600),RND(600),2,2

INC newcol,RND(25)

NEXT

SHOWSCREEN

KEYWAIT

///////////////////////////////////////////////////////

SUB recolourgraphics:

GLOBAL dotz%[]

SPRITE2MEM(dotz%[], example)

FOREACH d% IN dotz%[]
       
        d=changecol(d)

NEXT

LOCAL width%, height%

GETSPRITESIZE example, width, height

MEM2SPRITE(dotz%[], newone, width%, height%)       

ENDSUB


FUNCTION changecol%: colour%

LOCAL r% = bAND(colour%        , 0xff)
       
IF r>140 // NOTE: Changing this value will alter the font

RETURN 0xff000000 + RGB(RND(255),255,newcol)

ENDIF

ENDFUNCTION

Title: Re: Altering the colour and size of GLBasics preset Font
Post by: I love my Brick on 2012-Jun-12
Ive used it for "score", "lifes" etc in past early projects without needing to design or load a font.
Title: Re: Altering the colour and size of GLBasics preset Font
Post by: Albert on 2012-Jun-12
That's really nice!
Title: Re: Altering the colour and size of GLBasics preset Font
Post by: CW on 2013-Mar-05
Very nice, Brick!  :good:

Your trick allows the use of Rotozoomsprite (instead of zoomsprite) for interesting effects. Try:
Code (glbasic) Select

ROTOZOOMSPRITE newone,RND(600),RND(600),-45+RND(90),RND(30)

-CW