Fonts!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Fonts!

Post by Mr. Strange »

Alright, I'm playing around with font stuff, and now I want more font functionality. Maybe some of this already exists?

1 - I want to load a true type font as a new font type. I have no idea what font I could use other than love.default_font, or loading a font in via an image.
2 - I want to use bold and italics.
3 - I want to use rotated & formatted text together. Currently I can only do one or the other! (sad panda face) Ideally the "wrap after this many pixels" value would be smart enough to act as the # of pixels in the current font orientation.
4 - I haven't been able to get the "align" portion of drawf to work for me. Could someone post an example of what valid values for align are? Or maybe this is currently working sub-optimally?

5 - Technical question - I have 50-100 elements on screen which have several text areas. If I wanted to have each area drawn with a different font / font size / font color would the overhead of switching fonts be something I might worry about? That is to say, would I be better off drawing font style A across all elements, then switch the font and draw all of style B, or would it be fine to simply draw each of the multiple font areas for each element in turn?

6 - Finally, I've noticed that my performance drops significantly with even a modest amount of wrapping text on the screen. Is this consistent with everyone else's experience?

--Mr. Strange
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Fonts!

Post by rude »

  1. Use love.graphics.newFont("myfont.ttf", 14)
  2. Then use the corresponding font file. Bold and italics are not embedded into the same ttf-file.
  3. Font switching will probably not be a bottleneck.
  4. Yes.
Mike will have to fill in the blanks. (I've never used rotated text).

I believe the entire Font system is subject to review, but frankly, drawing vast amount of text is of limited importance right now. The "fix font"-task has been gathering dust somwhere in the task list for some time now, and it will continue to do so ... for now.
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Fonts!

Post by Mr. Strange »

Is it just the wrapping text which is slow, or is text in general slow?

If it's just wrapping that is a problem, I could take the time to "pre-wrap" all of my text. Lots more display calls, since I'd need one per line. But it would give me better control.

That would also be a work around for not supporting wrap & rotate at the same time. Of course, it's a hugely unpleasant data-munge task.

Mike, I'm hoping you have a more positive outlook on these matters?

--Mr. Strange
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Fonts!

Post by Mr. Strange »

I discovered the source of my performance woes - it was actually the way I was scaling my text.

Since I want word wrap, I coludn't scale my text in the draw function, so I was re-loading my font dozens of time every frame with different size values.

When I got rid of word wrap, and loaded the font only once my performance shot right back up.

So I optimized my script, and re-loaded the fonts only when the scale was adjusted. Now I have performance, and scaled text. Yay!

But I'm still not quite there, because I can't format my text when it is rotated.

I'd really like to use the align and wrap formatting options on rotated and scaled text.

Please?

--Mr. Strange
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Fonts!

Post by rude »

I just remembered some undocumented functions:

Code: Select all

love.graphics.push()
love.graphics.rotate(deg)
--draw whatever
love.graphics.pop()
Love.graphics.scale and love.graphics.translate also exist. Be warned that these functions may be removed.
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Fonts!

Post by Lord Tim »

Haha. Put this at the start of your draw callback.

Code: Select all

	if(not shake) then
		shake = 3
	end
	love.graphics.rotate(shake)
	shake = shake * -1
	if(shake > 0) then
		shake = math.random()*3
	end
You should totally keep that in. And add some way to rotate around a different point.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Fonts!

Post by rude »

The only way to rotate around "a different point" (in computer graphics in general) is to translate your point to origo, perform the rotation, and then translate back.
User avatar
subrime
Citizen
Posts: 76
Joined: Thu Nov 13, 2008 6:18 pm
Location: Australia

Re: Fonts!

Post by subrime »

It is quite possible to rotate about "a different point" as follows:

love.graphics.rotate(angle,centrex,centrey) -- in keeping with the current api

c + opengl implementation:

Code: Select all

static int fancy_rotate(lua_State *s) {
  float x,y,r;
  if (lua_gettop(s)>2 && lua_isnumber(s,1) &&
      lua_isnumber(s,2) &&  lua_isnumber(s,3)) {
    r=lua_tonumber(s,1); // positive angle -> anticlockwise rotation
    x=lua_tonumber(s,2); // x of rotation point
    y=lua_tonumber(s,3); // y of rotation point
    GLfloat m[]={cos(r),sin(r),0,0,-sin(r),cos(r),0,0,
                          x*(1-cos(r))+y*sin(r),y*(1-cos(r))-x*sin(r),
                          1,0,0,0,0,1};
    glLoadMatrix(m);
  } else return existing_rotate(s);
  return 0;
}
With this, your love.graphics.push/rotate/pop code should do what Mr. Strange is after.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests