Simple ghosting: How can I stop screen from redrawing?

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.
Scio
Prole
Posts: 4
Joined: Wed Jan 26, 2011 8:42 am

Simple ghosting: How can I stop screen from redrawing?

Post 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?
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

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

Post 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.
Scio
Prole
Posts: 4
Joined: Wed Jan 26, 2011 8:42 am

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

Post 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:
User avatar
Julian Assange
Prole
Posts: 5
Joined: Sun Dec 19, 2010 3:39 am
Location: Obey

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

Post 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?
Scio
Prole
Posts: 4
Joined: Wed Jan 26, 2011 8:42 am

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

Post 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:)
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

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

Post 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
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

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

Post 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
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

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

Post 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.
User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

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

Post 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.
Scio
Prole
Posts: 4
Joined: Wed Jan 26, 2011 8:42 am

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 45 guests