Pixel under cursor

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.
Post Reply
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Pixel under cursor

Post 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?
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Pixel under cursor

Post by nevon »

Code: Select all

screen = love.graphics.newScreenshot()
r,g,b,a = screen:getPixel(x,y)
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Pixel under cursor

Post 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.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Pixel under cursor

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Pixel under cursor

Post by Lap »

Exactly the clarification I was looking fro vlrd. Thanks.
User avatar
Metalcookie
Prole
Posts: 16
Joined: Sat Dec 10, 2011 2:57 pm
Location: Netherlands

Re: Pixel under cursor

Post 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.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Pixel under cursor

Post 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
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 22 guests