Examples of newImageFont usage?

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
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Examples of newImageFont usage?

Post by pekka »

Does anyone have an example of a "specifically formatted image" that the newImageFont() function takes? Seeing one would save me time of trying to figure it out on my own from the source. A high-level explanation would help too.

What does this thing eat?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Examples of newImageFont usage?

Post by Robin »

Help us help you: attach a .love.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Examples of newImageFont usage?

Post by pekka »

EDIT: Original message removed. I fixed the problem.

The image in the Wiki is not PoT, so it displays white rectangles instead of the letter glyphs on my usual test machine. I have attached a fixed png image to this post and a simple test program to try it. When making the image PoT, I also fixed the little problem with the 4 glyph. Look at the image for four in the original image and contrast with this to see the little slip somebody made with the original image. (It isn't exactly serious.. but anyway.)

Somebody could update the Wiki one day perhaps? I won't do it, because I didn't make that page.

Code: Select all

ont = love.graphics.newImageFont("imagefont.png",
    " abcdefghijklmnopqrstuvwxyz" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
    "123456789.,!?-+/():;%&`'*#=[]\"")
love.graphics.setFont(font)
love.graphics.setBackgroundColor(0x55,0x66,0xff)

function love.draw()
	love.graphics.print(
    "abcdefghijklmnopqrstuvwxyz\n" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" ..
    "0123456789.,!?-+/():;%&`'*\n" ..
    "#=[]\"", 30, 30)
end
That's the program, with the most attractive shade of blue ever discovered by a human being. Look at it. Look!

EDIT: See my posting below for a better image and explanation of a slight problem with this.
Imagine the GIMP line drawing tool pressing on a human face for fifteen minutes. That's what the future probably will not be like.
Imagine the GIMP line drawing tool pressing on a human face for fifteen minutes. That's what the future probably will not be like.
imagefont.png (1.83 KiB) Viewed 2165 times
Last edited by pekka on Sun Sep 05, 2010 5:21 am, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Examples of newImageFont usage?

Post by Robin »

Good work!
pekka wrote:Somebody could update the Wiki one day perhaps? I won't do it, because I didn't make that page.
Worst reason not to update a wiki ever. XD
Help us help you: attach a .love.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Examples of newImageFont usage?

Post by pekka »

I ended up reading the source code anyway, and trying various tests. During this testing I found two little features, that will soon find their way to the bug tracker.

I also found that you need only to mark the top line of the image with the spacer color. It will be ignored elsewhere. Even though there is a loop that is supposed to go thru the image and change the spacer color to completely transparent, it does not actually work. (This is one of the features I discovered.) This means you will see some residue of the spacer color at the edge of your bitmaps when you scale imagefont text to a larger size. This makes it actually preferable to only mark the upper row, so you get fewer stained pixels.

You can try this code with the original image and you should see little bars of yellowish color at each glyph's left and right sides. I did see that on my computer. The image below does not have so much yellow, so there will not be so obvious staining.

Code: Select all

font = love.graphics.newImageFont("imagefont.png",
    " abcdefghijklmnopqrstuvwxyz" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
    "123456789.,!?-+/():;%&`'*#=[]\"")
love.graphics.setFont(font)
love.graphics.setBackgroundColor(0x55,0x66,0xff)

function love.draw()
	love.graphics.scale(2)
	love.graphics.print(
    "abcdefghijklmnopqrstuvwxyz\n" ..
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" ..
    "0123456789.,!?-+/():;%&`'*\n" ..
    "#=[]\"\"", 30, 30)
end
In the new image there is no huge swath of yellow at the right hand side, because it affects the spacing of the last glyph. You normally want to leave a little unused space on the right, so the last spacer before it determines the length of the spacing for the last actual glyph. If you don't leave a space, then the spacing apparently becomes zero.

I'll look at writing more about this up at the Wiki some day. I just started a page now with a quick draft.
It's easier to remove pixels of certain color than put them in!
It's easier to remove pixels of certain color than put them in!
imagefont.png (1.55 KiB) Viewed 2146 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Examples of newImageFont usage?

Post by bartbes »

Since fonts were almost entirely rewritten, is this still the case?
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Examples of newImageFont usage?

Post by pekka »

I was talking about version 0.6.2. I'll just stop. This shit is getting ridiculous.
Post Reply

Who is online

Users browsing this forum: No registered users and 68 guests