Author Topic: Textured text (just fast idea)  (Read 2805 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Textured text (just fast idea)
« on: September 17, 2019, 04:35:54 pm »
Code: QB64: [Select]
  1.  
  2.  
  3. SCREEN _NEWIMAGE(1600, 600, 32)
  4. path$ = "arial.ttf"
  5. font = _LOADFONT(path$, 150, "MonoSpace")
  6. _FONT font
  7. texture = _LOADIMAGE("14321.jpg", 32)
  8. t2 = _LOADIMAGE("cihl_zed.jpg", 32)
  9.  
  10.  
  11. FontPrint MIDDLE("This"), 100, texture, "This"
  12. FontPrint MIDDLE("is"), 250, texture, "is"
  13. FontPrint MIDDLE("easy"), 400, texture, "easy"
  14.  
  15.  
  16. FontPrint MIDDLE("example"), 100, t2, "example"
  17. FontPrint MIDDLE("how"), 250, t2, "how"
  18. FontPrint MIDDLE("use"), 400, t2, "use"
  19.  
  20.  
  21. FontPrint MIDDLE("TEXTURED"), 100, texture, "TEXTURED"
  22. FontPrint MIDDLE("TEXT"), 350, t2, "TEXT"
  23.  
  24. _FREEIMAGE t2: _FREEIMAGE texture: _FONT 16: CLS: _FREEFONT font
  25.  
  26.  
  27. SUB FontPrint (X, Y, texture AS LONG, text AS STRING)
  28.     F = _FONT
  29.     W = _PRINTWIDTH(text): H = _FONTHEIGHT(F)
  30.     virtual = _NEWIMAGE(W, H, 32)
  31.     _DEST virtual
  32.     _FONT F, virtual
  33.     _PRINTMODE _FILLBACKGROUND , virtual
  34.     COLOR &HFFFFFFFF, &HFF000000
  35.     _PRINTSTRING (0, 0), text
  36.     _CLEARCOLOR &HFFFFFFFF, virtual
  37.     V2 = _NEWIMAGE(W, H, 32)
  38.     _PUTIMAGE , texture, V2
  39.     _PUTIMAGE , virtual, V2
  40.     _FREEIMAGE virtual
  41.     _CLEARCOLOR &HFF000000, V2
  42.     _PUTIMAGE (X, Y), V2
  43.     _FREEIMAGE V2
  44.  
  45. FUNCTION MIDDLE (t AS STRING)
  46.     MIDDLE = _WIDTH / 2 - _PRINTWIDTH(t) / 2
  47.  


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Textured text (just fast idea)
« Reply #1 on: September 17, 2019, 04:42:16 pm »
Have you seen my textured text routines?  They might help you work with yours a bit.  (And, surprisingly enough, they're FASTER than the native PRINT routines which QB64 uses, without half the options available to them...)

http://qb64.freeforums.net/thread/37/custom-routines-supports-textures-shading
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Textured text (just fast idea)
« Reply #2 on: September 17, 2019, 05:00:00 pm »
Nice work, Steve! You are MEM - king!

Thank for sharing.


  [ You are not allowed to view this attachment ]  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Textured text (just fast idea)
« Reply #3 on: September 17, 2019, 06:25:05 pm »
Good news!
...
good library... is it in the toolbox section?
Programming isn't difficult, only it's  consuming time and coffee