Author Topic: sbw2  (Read 27449 times)

0 Members and 2 Guests are viewing this topic.

wilde32

  • Cutey
  • **
  • Posts: 96
  • Cutes: 9
    • View Profile
  • Pronouns: anything
Re: sbw2
« Reply #300 on: July 15, 2018, 02:33:48 PM »
hey frenchies i dont mean to nag but whats the best way to draw text with outline

currently im drawing the text 8 times behind the main text with a 1px offset in each direction but i cant help but feel that its a little unoptimal

hubol

  • Cutester
  • *****
  • Posts: 907
  • Cutes: 151
    • View Profile
    • hubolhubolhubol
  • Pronouns: he/him
Re: sbw2
« Reply #301 on: July 15, 2018, 02:54:52 PM »
c = # of characters

its probably fine unless you have 1 million characters in your text. each character is just a rectangle aka 2 triangles. ideally the game maker text rendering uses a texture atlas so that should be decently cheap. likely the most expensive part of the operation (cpu-side) is generating the rectangles that the characters have to fill.

your method:
generates c*2*9 triangles
ideally requires 0 texture swaps
requires 0 buffer swaps

a good test is to try a really long string with your current system and see what happens. if performance is bad, you could try the following method:
  • render the text to a surface
  • render the surface to the screen with an offset and a color to give the text an outline
  • render surface to the screen to draw the text

this method:
generates (c+9)*2 triangles
probably requires 2 texture swaps (switch to surface, then back to game atlas)
requires 2 buffer swaps (switch to surface, then back to screen)

wilde32

  • Cutey
  • **
  • Posts: 96
  • Cutes: 9
    • View Profile
  • Pronouns: anything
Re: sbw2
« Reply #302 on: July 15, 2018, 03:55:30 PM »
ok but whats the best way of drawing a coloured "glow" around a sprite with alpha

should i just draw the sprite 8 times onto a surface then draw the surface with alpha or is there a better approach

if only i understood shaders

hubol

  • Cutester
  • *****
  • Posts: 907
  • Cutes: 151
    • View Profile
    • hubolhubolhubol
  • Pronouns: he/him
Re: sbw2
« Reply #303 on: July 15, 2018, 04:01:25 PM »
again, this depends on how many you want to do in a single scene

if there are not many objects that need glow i would just draw some colored silhouette with alpha behind the sprite a bunch of times. if you want a bloom effect you should probably look at using a bloom post shader on your entire surface.

wilde32

  • Cutey
  • **
  • Posts: 96
  • Cutes: 9
    • View Profile
  • Pronouns: anything
Re: sbw2
« Reply #304 on: July 15, 2018, 04:02:55 PM »
like 5-8 at a time i guess

hubol

  • Cutester
  • *****
  • Posts: 907
  • Cutes: 151
    • View Profile
    • hubolhubolhubol
  • Pronouns: he/him
Re: sbw2
« Reply #305 on: July 15, 2018, 04:07:59 PM »
thats not really a substantial amount so the naive approach should be fine

wilde32

  • Cutey
  • **
  • Posts: 96
  • Cutes: 9
    • View Profile
  • Pronouns: anything
Re: sbw2
« Reply #306 on: July 15, 2018, 04:10:23 PM »
ok thanks

aimaina

  • Administrator
  • Cutesterest
  • *****
  • Posts: 1080
  • Cutes: 124
    • View Profile
  • Pronouns: she/her
Re: sbw2
« Reply #307 on: July 15, 2018, 10:27:45 PM »
i generally use the "draw the thing eight times" approach for outlines except i usually just do it four times (no diagonal directions)

the game maker studio debugger has a "profiler" which tells you which parts of the code are taking up the most time each step, id suggest doing things the naive way most of the time and checking the profiler if you are worried about it. if it turns out your outlined text drawing is taking up 70% of the step or something then you can try to optimize it but in my experience its usually not a big deal to draw text 5 times instead of 1 time