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?
Pixel under cursor
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Pixel under cursor
Code: Select all
screen = love.graphics.newScreenshot()
r,g,b,a = screen:getPixel(x,y)
Re: Pixel under cursor
love.graphics.newScreenshot? But it is better to remember the positions and dimensions of the images, and check for collisions between them.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?
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Re: Pixel under cursor
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.Lap wrote:Any thoughts on an engine level function love.graphics.getPixel(x,y)? Is this even technically possible?
Re: Pixel under cursor
Exactly the clarification I was looking fro vlrd. Thanks.
- Metalcookie
- Prole
- Posts: 16
- Joined: Sat Dec 10, 2011 2:57 pm
- Location: Netherlands
Re: Pixel under cursor
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?
I think this is slower than the screenshot way, though.
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
Re: Pixel under cursor
i wouldn't think it'd be much different, since iirc the "screen" itself is technically a framebufferMetalcookie 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?I think this is slower than the screenshot way, though.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
Who is online
Users browsing this forum: Bing [Bot] and 2 guests