Page 1 of 1

Canvas only visible for one frame after I click.

Posted: Sat Aug 01, 2015 3:22 pm
by samurliko
I was experimenting with the canvas. In the test when you click a green dot is placed at your cursor position, but the green dots are only visible for a short time after you click.

This is my entire code:

Code: Select all

function love.load()
  dots = love.graphics.newCanvas(800, 600)
  
  love.mouse.setVisible(false)
end

function love.mousepressed(x, y, button)
  if button == "l" then
    love.graphics.setCanvas(dots)
    love.graphics.setColor(0, 255, 0, 255)
    love.graphics.circle("fill", x, y, 10, 16)
    love.graphics.setCanvas()
  end
end

function love.draw()
  love.graphics.setBlendMode('premultiplied')
  love.graphics.draw(dots)
  local x, y = love.mouse.getPosition()
  love.graphics.setColor(255, 0, 0)
  love.graphics.circle("fill", x, y, 20, 16)
end

Re: Canvas only visible for one frame after I click.

Posted: Sat Aug 01, 2015 4:02 pm
by arampl
This issue becoming soooo common!

Just use love.graphics.setColor(255, 255, 255) before drawing canvas. It's all about colors multiplication.

Re: Canvas only visible for one frame after I click.

Posted: Sat Aug 01, 2015 4:06 pm
by slime
arampl wrote:This issue becoming soooo common!
Yeah, it's one of the problems with the love.graphics API model of setting global state for something that is usually only intended to affect the few lines directly below it.

Suggestions for how to improve the situation are welcome. :)

Re: Canvas only visible for one frame after I click.

Posted: Sat Aug 01, 2015 4:36 pm
by samurliko
Thanks, I did that and it works now.

Re: Canvas only visible for one frame after I click.

Posted: Sat Aug 01, 2015 4:42 pm
by arampl
slime wrote:Suggestions for how to improve the situation are welcome. :)
How about additional 'color' parameter in primitive drawing functions?
SDL_draw and SDL_gfx libraries uses this approach.

Re: Canvas only visible for one frame after I click.

Posted: Sat Aug 01, 2015 6:13 pm
by zorg
arampl wrote:
slime wrote:Suggestions for how to improve the situation are welcome. :)
How about additional 'color' parameter in primitive drawing functions?
SDL_draw and SDL_gfx libraries uses this approach.
And soon after, the need for a "blendmode" parameter comes, then another, then another... :3

And finally, we can all stop worrying
about lg.draw(drawable,x,y,z,r,sx,sy,ox,oy,color,blendmode,mesh,source,scissors,vbo,u,v) et. al.
affecting any state at all :D