Page 1 of 1

love.graphics.translate & printf

Posted: Fri Sep 02, 2011 2:03 am
by luminosity
Hi,

apologies if this is already known, I skimmed search results for translate and found nothing, so. I'm trying to add resolution support to my game. The backgrounds and gui are all designed for 1024x768, so my current plan is for higher resolutions to just be a bit lazy and add bars around the content, centreing everything in the middle. This seems to work well except.. the first time printf is called it behaves rather oddly. The first character of the string is printed in the correct place, the rest is then printed in the top left corner or completely off screen. All subsequent drawing is reverted back to the original co ordinates before I called translate.

Is this a known problem with a workaround / fix in the works?

Thanks guys.

Re: love.graphics.translate & printf

Posted: Fri Sep 02, 2011 8:09 am
by kikito
Please upload a .love file so we can test.

Re: love.graphics.translate & printf

Posted: Fri Sep 02, 2011 9:56 am
by miko
luminosity wrote:Hi,
Is this a known problem with a workaround / fix in the works?
For me, it looks like a bug in you code. So yes, upload your *.love file, then the fix will be in the works.

Re: love.graphics.translate & printf

Posted: Sat Sep 03, 2011 11:11 pm
by luminosity
I'm not sure how it could be a bug in my code though, you can see the rendering changes midway through a printf, and the "ontinue" from that string has disappeared completely. I didn't upload a .love vecause my game is nearing completion, and I don't want it sitting on a public forum particularly -- not till it's out for sale. However it seems like this isn't a known bug? I'll try reproducing it in a smaller example file.

Thanks,

Re: love.graphics.translate & printf

Posted: Sat Sep 03, 2011 11:19 pm
by TechnoCat
luminosity wrote:I'm not sure how it could be a bug in my code though, you can see the rendering changes midway through a printf, and the "ontinue" from that string has disappeared completely. I didn't upload a .love vecause my game is nearing completion, and I don't want it sitting on a public forum particularly -- not till it's out for sale. However it seems like this isn't a known bug? I'll try reproducing it in a smaller example file.

Thanks,
Are you popping your state too early?

Re: love.graphics.translate & printf

Posted: Mon Sep 05, 2011 5:29 am
by luminosity
Okay boiled down to code that is breaking:

Code: Select all

function love.draw()
	love.graphics.push()
	love.graphics.translate(100, 100)
	love.graphics.printf("Testing", 100, 100, 1000, "left")
	love.graphics.printf("Testing", 100, 120, 1000, "left")
end
which gives me the following screenshot

Re: love.graphics.translate & printf

Posted: Mon Sep 05, 2011 5:32 am
by thelinx
Not sure if this is an error in just your demo code, but try to .pop() before the end of your draw.

Re: love.graphics.translate & printf

Posted: Mon Sep 05, 2011 6:53 am
by Boolsheet
thelinx is right, you have to keep the push and pops balanced. The example code fills the matrix stack and runs out of space.
This fails silently in LÖVE 0.7.2. The next version will throw a Lua error once the stack is full.

Re: love.graphics.translate & printf

Posted: Mon Sep 05, 2011 7:23 am
by luminosity
Thanks guys. I swear it used to be balanced in my own game, but I guess I missed something. Will go back and look now. :)

Should there be a note in the wiki about this? The page for love.graphics.push doesn't explicitly say that pop/pushes must be balanced.

Thanks again.

Re: love.graphics.translate & printf

Posted: Mon Sep 05, 2011 2:25 pm
by tentus
luminosity wrote:Thanks guys. I swear it used to be balanced in my own game, but I guess I missed something. Will go back and look now. :)

Should there be a note in the wiki about this? The page for love.graphics.push doesn't explicitly say that pop/pushes must be balanced.

Thanks again.
I dunno, I went to the wiki to add your suggestion, but it already has this line:
love.graphics.push wrote:This function is always used to prepare for a corresponding pop operation later
I guess we could word that stronger, but it pretty much tells you that you need a call to pop later.