Page 1 of 2
Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 5:12 pm
by Croutonix
Anyone has an idea why this code
Code: Select all
function love.run()
main()
end
function main()
love.graphics.clear({255, 255, 255, 255})
while true do
love.graphics.setColor({0, 0, 0, 255})
love.graphics.circle("fill", 100, 100, 50)
love.graphics.present()
love.timer.sleep(0.25)
end
end
Draws circle half of the time and make screen go black the other half?
I concluded love.graphics.present() caused that but why? How to prevent it?
Yes love.run() is voluntarily like that and needs to be for my purposes.
Also you should try the .love file not the code so you can close the window with the console
DOWNLOAD LOVE FILE
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 5:15 pm
by Nixola
It constantly works here. Anyway, you're supposed to clear before drawing so it should be like this:
Code: Select all
function love.run()
main()
end
function main()
while true do
love.graphics.clear({255, 255, 255, 255})
love.graphics.setColor({0, 0, 0, 255})
love.graphics.circle("fill", 100, 100, 50)
love.graphics.present()
love.timer.sleep(0.25)
end
end
EDIT: using love.run that way, you're not going to have the window respond to any external event. That also means Windows thinks the app froze and will try to kill it.
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 5:19 pm
by Croutonix
I can't clear for my purpose. What do I do?
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 5:20 pm
by Nixola
Probably use [wiki]Canvas[/wiki]es I guess? Is that what you may need? If not, please state what you need to do exactly; we might be able to help more ffectively then
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 5:26 pm
by Croutonix
Alright I want to write a draw library available in a lua programming app so I can run my code on the computer. The user needs to be able to do draw.refresh() as much as he needs. If draw.refresh() also clears, it makes it useless.
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 8:22 pm
by Croutonix
up?
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 8:26 pm
by Nixola
Please don't double post, especially since your post is still in the first page.
That said, I'm afraid I still don't understand what you're trying to do.
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 8:50 pm
by Croutonix
I want to prevent the black screen thing.
Why would displaying the graphics without clearing first show a black screen?
I want to be able to show newly drawn graphics without clearing.
Let's say I'm trying to do a paint program.
I want to refresh the screen so the user can see what he draws.
1. If I refresh without clearing: black screen every two frame.
2. If I refresh after clearing: what user drawn has been erased
I know I could register everything drawn but why bother if I can get rid of this black frame?
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 9:11 pm
by Nixola
Just learn how to use [wiki]canvas[/wiki]es instead of messing with love.run. That's not a good way of preserving what happened, because the GPU might automatically fill the buffer with gibberish and/or clear it after calling love.graphics.present.
Re: Screen goes black half of the time love.graphics.present()
Posted: Sun Aug 14, 2016 9:13 pm
by zorg
You need to "bother" because you can't do it otherwise, due to people implementing windowing systems this way.
If you want to retain what was drawn n frames before, then you need a canvas; The main window's contents must be invalidated with love.graphics.clear every frame, otherwise you may get garbage shown to you.
Just create one canvas the size of the program's window, draw to that, then draw that every frame. Problem solved.
Also, i see that you replaced love.run; i didn't check out your .love file, but i hope you do have the event loops and whatnot that are in the default love.run somewhere, otherwise you can't use inputs or night anything.
Edit: wow, ninja'd by 2 minutes... getting slower with typing. : )