Page 2 of 5

Re: Testing the new things in 0.9.0

Posted: Fri Jun 28, 2013 5:31 am
by Santos
Here's an example using some new Font methods:
font_methods.png
font_methods.png (62.46 KiB) Viewed 2564 times

Code: Select all

function love.load()
	Font = love.graphics.setNewFont(50)

	colors = {
		height = {230, 159, 0},
		ascent = {0, 158, 115},
		descent = {213, 94, 0},
		baseline = {86, 180, 223},
	}
end

function love.draw()
	love.graphics.setColor(colors.height)
	love.graphics.rectangle('fill', 200*0, 0, 200, Font:getHeight())
	love.graphics.setColor(colors.ascent)
	love.graphics.rectangle('fill', 200*1, Font:getBaseline()-Font:getAscent(), 200, Font:getAscent())
	love.graphics.setColor(colors.descent)
	love.graphics.rectangle('fill', 200*2, Font:getBaseline(), 200, -Font:getDescent())
	love.graphics.setColor(colors.baseline)
	love.graphics.rectangle('fill', 200*3, 0, 200, Font:getBaseline())

	love.graphics.setColor(255, 255, 255)
	love.graphics.printf('abcdefghijklmnopqrstuvwxyz', 0, 0, 800, 'center')

	love.graphics.setColor(colors.height)
	love.graphics.print('\n\nFont:getHeight() : '..Font:getHeight(), 0, 0)
	love.graphics.setColor(colors.ascent)
	love.graphics.print('\n\n\nFont:getAscent() : '..Font:getAscent(), 0, 0)
	love.graphics.setColor(colors.descent)
	love.graphics.print('\n\n\n\nFont:getDescent() : '..Font:getDescent(), 0, 0)
	love.graphics.setColor(colors.baseline)
	love.graphics.print('\n\n\n\n\nFont:getBaseline() : '..Font:getBaseline(), 0, 0)
	love.graphics.setColor(200, 200, 200)
	love.graphics.print('\n\n\n\n\n\nFont:hasGlyph("Ö") : '..tostring(Font:hasGlyph('Ö')), 0, 0)
	love.graphics.print('\n\n\n\n\n\n\nFont:hasGlyph("の") : '..tostring(Font:hasGlyph('の')), 0, 0)
end
From Wikipedia:

Image

This displays some renderer info:

Code: Select all

function love.draw()
	love.graphics.print("love.graphics.getRendererInfo('name'): "..love.graphics.getRendererInfo('name'), 20, 20)
	love.graphics.print("love.graphics.getRendererInfo('version'): "..love.graphics.getRendererInfo('version'), 20, 40)
	love.graphics.print("love.graphics.getRendererInfo('vendor'): "..love.graphics.getRendererInfo('vendor'), 20, 60)
	love.graphics.print("love.graphics.getRendererInfo('device'): "..love.graphics.getRendererInfo('device'), 20, 80)
end
I'm wondering, what could this information be used for?

Re: Testing the new things in 0.9.0

Posted: Fri Jun 28, 2013 7:59 am
by raidho36
Each glyph character in a string you print has 4 vertices that form a bounding box around the glyph.
So text is rendered per glyph as dual-tri quadrilateral. That answers my question, thanks.

Re: Testing the new things in 0.9.0

Posted: Fri Jun 28, 2013 8:20 am
by slime
Santos wrote:This displays some renderer info:

Code: Select all

function love.draw()
	love.graphics.print("love.graphics.getRendererInfo('name'): "..love.graphics.getRendererInfo('name'), 20, 20)
	love.graphics.print("love.graphics.getRendererInfo('version'): "..love.graphics.getRendererInfo('version'), 20, 40)
	love.graphics.print("love.graphics.getRendererInfo('vendor'): "..love.graphics.getRendererInfo('vendor'), 20, 60)
	love.graphics.print("love.graphics.getRendererInfo('device'): "..love.graphics.getRendererInfo('device'), 20, 80)
end
I'm wondering, what could this information be used for?
It's mostly for debugging, it can really help solve graphics issues if a game outputs that info to a log or error screen so users having the issues can show the output to the game's creator. For example maybe a game fails to load on some systems, or loads fine but seems to be broken sometimes, and it turns out it only happens on ATI cards of a certain generation with an old driver in Windows (true story.)

There's also a possibility of some of the functions being used to display nicer "your computer sucks, upgrade it" messages to users. :P

Re: Testing the new things in 0.9.0

Posted: Fri Jun 28, 2013 8:34 am
by Lafolie
Is there a function to retrieve the X-Height of a typeface? Having studied typography I've been eagerly awaiting these features.

Edit: Following a short discussion on IRC (which someone took place, despite the intolerable amount of crap being spewed about the place), I found that the following meta is available in 0.9.0, I'll leave the diagram here for reference.

Image

Re: Testing the new things in 0.9.0

Posted: Fri Jun 28, 2013 9:19 am
by slime
You'll only be able to get some of that via GlyphData (most of the internal GlyphData and Rasterizer object methods have been exposed to Lua in 0.9.0.)

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 1:26 am
by spectralcanine
Sorry for the lack of research on my part, but can we upload any uniforms and attributes, and use any varyings we want in shaders? Or is it the same SFML deal where you only support the old GLSL 100 predefined variables?

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 2:16 am
by Jasoco
Santos wrote:Here's an example using some new Font methods:
font_methods.png
So are Ascent and Baseline always going to be the same value? Is there a situation where they'd be different?

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 3:47 am
by Santos
I was wondering that too, and indeed they can be different depending on the font, here's a test with Crafty Girls:
Crafty Girls.png
Crafty Girls.png (108.67 KiB) Viewed 2487 times

Here's an example which plays a tone when the window is visible, and stops it when it's not.

Code: Select all

function love.load()
	tonesounddata = love.sound.newSoundData(44100,44100,16,1)
	for i=0, 44100 do tonesounddata:setSample(i, math.sin(440*(2*math.pi/44100)*i)*0.2)	end
	tone = love.audio.newSource(tonesounddata)
	tone:setLooping(true)

	pingsounddata = love.sound.newSoundData(44100,44100,16,1)
	for i=0, 44100 do pingsounddata:setSample(i, math.sin(440*2*(2*math.pi/44100)*i)*0.3*(-(i - 44100) / 44100)) end
	ping = love.audio.newSource(pingsounddata)

	tone:play()
	ping:play()
end

function love.visible(visible)
	ping:stop()
	ping:play()
end

function love.update()
	-- Source:isPlaying is new.
	if love.window.isVisible() and not tone:isPlaying() then
		tone:play()
	elseif not love.window.isVisible() and tone:isPlaying() then
		tone:stop()
	end
end
visible.love
(449 Bytes) Downloaded 101 times
The "ping" which plays when it first starts is also supposed to play when the window gains and loses visibility, but this doesn't happen, any ideas?

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 3:51 am
by slime
Santos wrote:The "ping" which plays when it first starts is also supposed to play when the window gains and loses visibility, but this doesn't happen, any ideas?
It works for me. Does the entire love.visible callback not trigger, or does the sound just not play properly? What OS?

Re: Testing the new things in 0.9.0

Posted: Sat Jun 29, 2013 4:11 am
by Santos
It seems like the callback doesn't trigger, on Windows XP.

I tested something simpler too:

Code: Select all

function love.load()
	love.filesystem.write('This gets created', '')
end

function love.visible()
	love.filesystem.write('But this does not', '')
end