Screen goes black half of the time love.graphics.present()

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.
Croutonix
Prole
Posts: 34
Joined: Fri Aug 12, 2016 12:49 pm

Screen goes black half of the time love.graphics.present()

Post 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
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Screen goes black half of the time love.graphics.present()

Post 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.
Last edited by Nixola on Sun Aug 14, 2016 5:20 pm, edited 1 time in total.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Croutonix
Prole
Posts: 34
Joined: Fri Aug 12, 2016 12:49 pm

Re: Screen goes black half of the time love.graphics.present()

Post by Croutonix »

I can't clear for my purpose. What do I do?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Screen goes black half of the time love.graphics.present()

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Croutonix
Prole
Posts: 34
Joined: Fri Aug 12, 2016 12:49 pm

Re: Screen goes black half of the time love.graphics.present()

Post 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.
Croutonix
Prole
Posts: 34
Joined: Fri Aug 12, 2016 12:49 pm

Re: Screen goes black half of the time love.graphics.present()

Post by Croutonix »

up?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Screen goes black half of the time love.graphics.present()

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Croutonix
Prole
Posts: 34
Joined: Fri Aug 12, 2016 12:49 pm

Re: Screen goes black half of the time love.graphics.present()

Post 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?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Screen goes black half of the time love.graphics.present()

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Screen goes black half of the time love.graphics.present()

Post 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. : )
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests