Page 1 of 2

Detecting proper framebuffers

Posted: Sun May 01, 2011 1:21 am
by Ertain
Hello again, LÖVErs.

I have seen other posters struggle with actually detecting framebuffer support. Truthfully I'm trying to figure it out myself. So has anyone actually ironed out a surefire way to detect for framebuffers? Just using the function "love.graphics.newFramebuffer()" doesn't cut it. I have thought of detecting the version of LÖVE but that sure as heck doesn't work, either.

Re: Detecting proper framebuffers

Posted: Sun May 01, 2011 4:36 am
by ishkabible
just a hack i thought of that might work, if you use pcall you might be able to detect an error without the program shutting down. just an idea however, probably not the best way but certainly a way.

Re: Detecting proper framebuffers

Posted: Sun May 01, 2011 4:43 am
by slime
Yeah, using pcall should work great. As long as you use pcall correctly. ;)

Re: Detecting proper framebuffers

Posted: Sun May 01, 2011 4:55 am
by Jasoco
In my current project I use pcall to call the function that creates the buffers. Then if it's returned false with an error, I just use a workaround so the game continues but with less "awesomeness". Unfortunately I don't have an incompatible computer to test its failure mode on. Eventually I'll just ask someone here who doesn't have support to test it out.

But pcall should work. I believe it returns whatever the function returns as well as the text for the error.
The internet wrote:Calls function f with the given arguments in protected mode. This means that any error inside f is not propagated; instead, pcall catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error message.

Re: Detecting proper framebuffers

Posted: Sun May 01, 2011 6:49 am
by Ertain
So I should use something like this?

Code: Select all

if pcall( love.graphics.newFramebuffer() ) then
-- Use the framebuffer here.
else
-- Use some other code here.
end

Re: Detecting proper framebuffers

Posted: Sun May 01, 2011 7:35 am
by BlackBulletIV
No. The main problem is that you don't call love.graphics.newFramebuffer and give its results to pcall, you can the function to pcall, following by your desired arguments. pcall returns a status (true or false from memory - I do know it's false on failure) and then whatever the function returned.

So, more like this:

Code: Select all

status, fb = pcall(love.graphics.newFramebuffer, width, height)

if status then
  -- use fb
else
  -- do something else
end

Re: Detecting proper framebuffers

Posted: Sun May 01, 2011 6:25 pm
by Ertain
Thanks, guys, I'll try that out.
*Tries that out*
Now if I could only get the frame rate under control (and get this nasty freeze-up solved).

Re: Detecting proper framebuffers

Posted: Tue May 03, 2011 4:21 pm
by Lafolie
You're not creating the framebuffer and doing a whole bunch of unnecessary drawing-related calls each loop are you? Some more information would allow us to help you with this buddy :)

BlackBulletIV is right in that it does return a boolean based on success. Actually, my code just checks if it exists.... I'm sure it just returns true or nil though.

Re: Detecting proper framebuffers

Posted: Tue May 03, 2011 8:58 pm
by Ertain
I think I am do some unnecessary drawing calls each update. Some of my functions still do drawing even when the enemy is off the screen. So I think I'll add code to see if they've left the screen and stop drawing them. That might alleviate the problem a little.

On one function I'm trying to draw several enemies on the screen and at the same time I'm moving their respective boundary circles (so as to see if they've collided. I'm using vrid's hardon collider).

Re: Detecting proper framebuffers

Posted: Tue May 03, 2011 9:14 pm
by Lafolie

Code: Select all

if enemy.x - enemy.sprite:getWidth() > 0 and enemy.x + enemy.sprite:getWidth() < love.graphics.getWidth()  and enemy.y - enemy.sprite:getHeight() > 0  and enemy.y + enemy.sprite:getHeight() < love.graphics.getHeight() then 
     enemy:draw() 
end
Something like that should help.