Drawing outside of love.draw

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.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Drawing outside of love.draw

Post by ReFreezed »

No problem. :)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Drawing outside of love.draw

Post by slime »

SelfDotX wrote: Sun Oct 02, 2022 9:17 pm Just to be clear, I'm doing this outside of the draw loop.
love.graphics.present creates a frame boundary. But bad things can happen on various operating systems if you don't pump and poll events after that frame boundary, and call love.graphics.clear before drawing to the backbuffer in the current frame (i.e. what the default love.run loop does every frame).
User avatar
SelfDotX
Prole
Posts: 25
Joined: Sun Oct 02, 2022 5:06 pm

Re: Drawing outside of love.draw

Post by SelfDotX »

slime wrote: Mon Oct 03, 2022 2:16 am love.graphics.present creates a frame boundary. But bad things can happen on various operating systems if you don't pump and poll events after that frame boundary, and call love.graphics.clear before drawing to the backbuffer in the current frame (i.e. what the default love.run loop does every frame).
I *technically* understand all the words you used - it may take a while longer before I figure out how to properly use that information :nyu:

Thanks for your help too!
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Drawing outside of love.draw

Post by MrFariator »

The short and long of it is that for compatibility, it's better to update game stuff during love.update, and draw stuff during love.draw. Things are not guaranteed to work if you mix and match the two, without modifying the default love.run. Even then, it's better to leave game logic out of render logic, and vice versa, unless you have a specific goal in mind.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Drawing outside of love.draw

Post by pgimeno »

I created this tool for this kind of purpose: viewtopic.php?f=5&t=87262

In this tool, your code is in a coroutine, which yields when you want to display the screen. That gives every event a chance to run. Of course you can implement your own coroutine-based system without the need to use the tool; it's simple enough.

slime wrote: Mon Oct 03, 2022 2:16 am But bad things can happen on various operating systems if you don't [...] call love.graphics.clear before drawing to the backbuffer in the current frame
Is that also true if you are drawing a fully opaque screen-sized canvas to the screen every frame?
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Drawing outside of love.draw

Post by slime »

pgimeno wrote: Mon Oct 03, 2022 6:27 am
slime wrote: Mon Oct 03, 2022 2:16 am But bad things can happen on various operating systems if you don't [...] call love.graphics.clear before drawing to the backbuffer in the current frame
Is that also true if you are drawing a fully opaque screen-sized canvas to the screen every frame?
In that situation the main bad thing is that it will be slower on some GPUs (mobile ones especially) than clear + draw, because GPUs of a certain architecture will have to copy the backbuffer's data from vram to on-chip memory unless you tell it that it doesn't need to via the clear() call.

Also you'd probably want to turn blending off.

There's usually little reason to avoid love.graphics.clear, and if the clear color is something common like opaque black then even non-mobile GPUs have super fast paths for it.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 47 guests