Hullo, I'm new here; both to Love and Lua! I had a question about how Love draws things. (Lovelily, of course. )
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?
Simple ghosting: How can I stop screen from redrawing?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Simple ghosting: How can I stop screen from redrawing?
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.
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?
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?
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?
- 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?
Do you call love.draw in your new love.run?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?
Re: Simple ghosting: How can I stop screen from redrawing?
Yes of course. love.draw was already being called, I just commented out the love.graphics.clear() part.
In fact, the run() code works fine when I leave the love.graphics.clear() as-is.
(Off-topic: @Julian, weren't you in prison ? )
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
(Off-topic: @Julian, weren't you in prison ? )
Re: Simple ghosting: How can I stop screen from redrawing?
You can use a Framebuffer (well, two) for that. Untested code ahead:
In love.load():
love.draw():
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
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
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Simple ghosting: How can I stop screen from redrawing?
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
https://bitbucket.org/rude/love/issue/1 ... ear-breaks
- 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?
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.
- 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?
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.BlackBulletIV wrote:Framebuffers aren't supported on all computers
Re: Simple ghosting: How can I stop screen from redrawing?
Thanks for all the replies. It does seem trickier than I expected!
I will try the framebuffers now, round them up and see if that works.
I will try the framebuffers now, round them up and see if that works.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests