Page 1 of 1

Pixel under cursor

Posted: Wed Mar 14, 2012 2:59 pm
by Lap
Trying to track all the individual images and which one is on top can be a bit of a pain. We have a way to get the pixel from an ImageData, but not from absolute coordinates of the full display.

Any thoughts on an engine level function love.graphics.getPixel(x,y)? Is this even technically possible?

Re: Pixel under cursor

Posted: Wed Mar 14, 2012 3:17 pm
by nevon

Code: Select all

screen = love.graphics.newScreenshot()
r,g,b,a = screen:getPixel(x,y)

Re: Pixel under cursor

Posted: Wed Mar 14, 2012 3:31 pm
by miko
Lap wrote:Trying to track all the individual images and which one is on top can be a bit of a pain. We have a way to get the pixel from an ImageData, but not from absolute coordinates of the full display.

Any thoughts on an engine level function love.graphics.getPixel(x,y)? Is this even technically possible?
love.graphics.newScreenshot? But it is better to remember the positions and dimensions of the images, and check for collisions between them.

Re: Pixel under cursor

Posted: Wed Mar 14, 2012 3:37 pm
by vrld
Lap wrote:Any thoughts on an engine level function love.graphics.getPixel(x,y)? Is this even technically possible?
Not in a reasonably fast way, because LÖVE uses OpenGL and OpenGL does not allow direct access to the pixels on the screen. The only way to get to those pixels is to copy them from graphics memory to RAM, which is exactly what love.graphics.newScreenshot() does.

Re: Pixel under cursor

Posted: Wed Mar 14, 2012 3:45 pm
by Lap
Exactly the clarification I was looking fro vlrd. Thanks.

Re: Pixel under cursor

Posted: Wed Mar 14, 2012 6:01 pm
by Metalcookie
Isn't it also possible to first draw everything on a framebuffer and then get the imagedata from that and get a pixel from that?

Code: Select all

function love.draw()
	love.graphics.setRenderTarget(FB1)
	
	--draw stuff
	
	love.graphics.setRenderTarget()
	love.graphics.draw(FB1, 0, 0)
	
	local data = FB1:getImageData()
	r, g, b, a = data:getPixel(mouse.x, mouse.y)
end
I think this is slower than the screenshot way, though.

Re: Pixel under cursor

Posted: Wed Mar 14, 2012 6:45 pm
by Xgoff
Metalcookie wrote:Isn't it also possible to first draw everything on a framebuffer and then get the imagedata from that and get a pixel from that?

Code: Select all

function love.draw()
	love.graphics.setRenderTarget(FB1)
	
	--draw stuff
	
	love.graphics.setRenderTarget()
	love.graphics.draw(FB1, 0, 0)
	
	local data = FB1:getImageData()
	r, g, b, a = data:getPixel(mouse.x, mouse.y)
end
I think this is slower than the screenshot way, though.
i wouldn't think it'd be much different, since iirc the "screen" itself is technically a framebuffer