Author Topic: multicolored fonts  (Read 4412 times)

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1637
  • Particle Hawk
    • View Profile
Re: multicolored fonts
« Reply #1 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.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile
Re: multicolored fonts
« Reply #2 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.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1637
  • Particle Hawk
    • View Profile
Re: multicolored fonts
« Reply #3 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]
« Last Edit: 2009-Jul-02 by Kitty Hello »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline 9940

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: multicolored fonts
« Reply #4 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

« Last Edit: 2009-Jul-03 by 9940 »

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1637
  • Particle Hawk
    • View Profile
Re: multicolored fonts
« Reply #5 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.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline 9940

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: multicolored fonts
« Reply #6 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



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  ;)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10745
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: multicolored fonts
« Reply #7 on: 2009-Jul-07 »
Do no use CAPITAL_ONLY_COMMANDS. They're mine :P

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1637
  • Particle Hawk
    • View Profile
Re: multicolored fonts
« Reply #8 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]
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline 9940

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: multicolored fonts
« Reply #9 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.
« Last Edit: 2009-Jul-07 by 9940 »

Offline 9940

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: multicolored fonts
« Reply #10 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]
« Last Edit: 2009-Jul-07 by 9940 »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10745
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: multicolored fonts
« Reply #11 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.

Offline 9940

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: multicolored fonts
« Reply #12 on: 2009-Jul-08 »
The func. with CREATESCREEN is more slowly than GRABSPRITE and the sprites created with CREATESCREEN hasn't transparency.