Page 1 of 2

Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 8:50 am
by Scio
Hullo, I'm new here; both to Love and Lua! I had a question about how Love draws things. (Lovelily, of course. :awesome:)

I want to do basic ghosting, a pretty common trick for processing users. Instead of manually redrawing the background at each frame (which processing folk have to do), if we overlay a semi-transparent rectangle it will fade out previously drawn frames slowly. The effect looks pretty spiffy I daresay.

love.draw(), however, redraws the background at every frame on its own. Is there any way to disable the solid background color so that I can use the same ghosting trick?

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 9:02 am
by thelinx
If you use a custom love.run, you can not call the love.graphics.clear() function.

However, that introduces weird issues with bad graphics drivers, so you should really do it the classic way.

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 9:57 am
by Scio
Since I already have love.update and love.draw, I am supposed to simply add a love.run() and comment out love.graphics.clear() right?

But if I do that, nothing draws! Which, I guess, will be the driver problems? (Ubuntu 10.04 64bit Nvidia GTS250)

...So, is this classic way something else I can try? :crazy:

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 11:34 am
by Julian Assange
Scio wrote:Since I already have love.update and love.draw, I am supposed to simply add a love.run() and comment out love.graphics.clear() right?

But if I do that, nothing draws! Which, I guess, will be the driver problems? (Ubuntu 10.04 64bit Nvidia GTS250)

...So, is this classic way something else I can try? :crazy:
Do you call love.draw in your new love.run?

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 11:49 am
by Scio
Yes of course. love.draw was already being called, I just commented out the love.graphics.clear() part.

Code: Select all

function love.run()

        --...

        if love.graphics then
            --love.graphics.clear()
            if love.draw then love.draw() end
        end

        --...

        if love.timer then love.timer.sleep(1) end
        if love.graphics then love.graphics.present() end

    end

end
In fact, the run() code works fine when I leave the love.graphics.clear() as-is.

(Off-topic: @Julian, weren't you in prison ? :o:)

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 12:16 pm
by vrld
You can use a Framebuffer (well, two) for that. Untested code ahead:

In love.load():

Code: Select all

buffers = {}
-- true and false for easier switching, see below
buffers[true] = love.graphics.newFramebuffer()
buffers[false] = love.graphics.newFramebuffer()
buffers.current = true
love.draw():

Code: Select all

love.graphics.setRenderTarget(buffers[buffers.current]) -- draw to current buffer
love.graphics.setColor(255,255,255,100)                 -- alpha value to fade the previous frame out
love.graphics.draw(buffers[not buffers.current], 0, 0)  -- draw previous frame

-- draw new content over last frame
draw_stuff()

love.graphics.setRenderTarget()                    -- draw to screen again
love.graphics.draw(buffers[buffers.current], 0, 0) -- draw 'ghosted' scene
buffers.current = not buffers.current              -- switch buffers

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 1:07 pm
by TechnoCat
I've tried modifying love.run to do this before. It just gave me headaches with different computers with a single buffer or a double and triple buffer.

https://bitbucket.org/rude/love/issue/1 ... ear-breaks

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 8:41 pm
by BlackBulletIV
As far as I know, Framebuffers aren't supported on all computers because of their OpenGL implementations (mine for example), so you have to be careful with that.

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Wed Jan 26, 2011 11:10 pm
by The Burrito
BlackBulletIV wrote:Framebuffers aren't supported on all computers
Yeah, if you want to make sure it will run on all computers I suggest first off, having a fallback mode with no FBOs (even if it doesn't look spiffy), and also rounding up the FBO to the next power of two (like 1024X1024 for 800X600 or 1024X768 resolutions) will make it generally more compatible with bad hardware / drivers.

Re: Simple ghosting: How can I stop screen from redrawing?

Posted: Thu Jan 27, 2011 9:36 am
by Scio
Thanks for all the replies. It does seem trickier than I expected! :brows:

I will try the framebuffers now, round them up and see if that works.