GLBasic forum

Codesnippets => Code Snippets => Topic started by: Corax on 2009-Jul-02

Title: multicolored fonts
Post by: Corax on 2009-Jul-02
fnColFnt.zip - 0.34MB (http://www.zshare.net/download/6213221040322427/)
Title: Re: multicolored fonts
Post by: Hemlos on 2009-Jul-02
Please, if you can use the forums to store your projects, do so..

that zdshare place messes up my browser.....so much junk built into that site.
Title: Re: multicolored fonts
Post by: Corax on 2009-Jul-02
What happened ?

Maybe we should install something like the showroom for code-snippets.

Besides: this function may interest beginners, its nothing for advanced programmers.
Title: Re: multicolored fonts
Post by: Hemlos on 2009-Jul-02
Dont need to add anything...


Just click Additional Options... at the bottom of your message.

See look i can attach a picture:


[attachment deleted by admin]
Title: Re: multicolored fonts
Post by: 9940 on 2009-Jul-03
I made a small improvement.

Code (glbasic) Select

SETTRANSPARENCY RGB(255, 255, 255)
LOADFONT "font.png", 1
SETFONT 1
SETTRANSPARENCY RGB(255, 0, 128)

PRINTCOLOR("Red text", 0, 0, RGB(255, 0, 0))
SHOWSCREEN
MOUSEWAIT


FUNCTION PRINTCOLOR: output$, x, y, color
    LOCAL tx, ty
    GETFONTSIZE tx, ty
    LOCAL tw = LEN(output$) * tx

    GRABSPRITE 0, x, y, tw, ty
    DRAWRECT x, y, tw, ty, color
    PRINT output$, x, y
    GRABSPRITE 1, x, y, tw, ty
    DRAWSPRITE 0, x, y
    DRAWSPRITE 1, x, y
ENDFUNCTION


Title: Re: multicolored fonts
Post by: Hemlos on 2009-Jul-07
@9940 :

have you even tested that function?
It does the opposite of color a font...it colors the background...

..also you cant use PRINT as the beginning of a function name.
Title: Re: multicolored fonts
Post by: 9940 on 2009-Jul-07
Quote
It does the opposite of color a font...it colors the background...
You used a wrong font img, try this
(http://img6.imageshack.us/img6/8480/fonttzm.png)


Quote
..also you cant use PRINT as the beginning of a function name.
Rename it to COLORPRINT and add PRINTCOLOR to Gernot's bug list  ;)
Title: Re: multicolored fonts
Post by: Kitty Hello on 2009-Jul-07
Do no use CAPITAL_ONLY_COMMANDS. They're mine :P
Title: Re: multicolored fonts
Post by: Hemlos on 2009-Jul-07
Ok i couldnt get yours to work with the glbasic fonts so i whipped up my own rendition.

However, instead of drawrect etc...try poly vectors...theyre prettier.

here is my version of what you made, you can use standard glbasic fonts with it...

i dont know what good it is...probably good for just making text images.

[attachment deleted by admin]
Title: Re: multicolored fonts
Post by: 9940 on 2009-Jul-07
Are you talking about the speed?
There is a little problem in your func.

Code (glbasic) Select

FUNCTION PRINCOOR: output$, x, y, color

  [some code]

  LOADFONT "smalfont.png",0
  SETFONT 0
  [some code]

ENDFUNCTION


This func. call LOADFONT every time is used which is a big waste of time

   
There is a reason why the background is pink: the default background of the sprites is pink and so there is no need to call every time SETTRANSPARENCY. Only if you use other sprite.
Title: Re: multicolored fonts
Post by: 9940 on 2009-Jul-07
Benchmark for COLORPRINT (up to 30 strings on my pc)

However with PRINT you can write more than 1500 strings without suffering slowdowns...
Depends on what you have to write  =D

[attachment deleted by admin]
Title: Re: multicolored fonts
Post by: Kitty Hello on 2009-Jul-08
using polyvector for coloured fonts might be slightly faster. Grabsprite or createscreen are quite expensive.
Also, instead of GRABSPRITE try CREATESCREEN. It *might* be faster.
Title: Re: multicolored fonts
Post by: 9940 on 2009-Jul-08
The func. with CREATESCREEN is more slowly than GRABSPRITE and the sprites created with CREATESCREEN hasn't transparency.