Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / get clicked pixel color
- - By OldBoy Date 2016-07-05 13:02
In plain Gosu (no extensions) how to get pixel color at clicked place (of topmost image, or shape)? Something like this
Parent - - By jlnr (dev) Date 2016-07-05 16:31
This question came up just last month, hidden in this thread:

https://www.libgosu.org/cgi-bin/mwf/topic_show.pl?pid=8924#pid8924

You will still need to remember which image was drawn at which position, though.
Parent - - By OldBoy Date 2016-07-05 17:40
I'm not sure if this helps me, what would solution with gl_tex_info look like? All of my images will be single color + transparent only (but irregular shapes) and will be smaller than 512x512 pixels, something like Risk map. I was thinking to identify specific objects/instances on screen like it's suggested on page 2 (fourth take on the problem). Also all images would be loaded with :retro => true, to prevent problems with anti-aliasing
Parent - - By jlnr (dev) Date 2016-07-05 23:36
You can use gl_tex_info to read out the pixels in an image using OpenGL, but that's exactly what Image#to_blob is doing for you, except that you need an extension to make use of gl_tex_info (the opengl gem).

The Image#[] method I've linked to is the exact equivalent of the Löve2D function you've mentioned. But if you need a way to read out an individual image's pixels _under the mouse cursor_, you also need to know where each image has been drawn. You can't take a screenshot of the window and read individual pixels from that (at least not without extensions).

When implementing a Risk map, you have all the information you need: An image for each country plus its x/y coordinate on the world map. When the user clicks, you can iterate over all your images and read out the pixel using @country_image[(mouse_x - @image_left).to_i, (mouse_y - @image_top).to_i]. If pixel[3].ord != 0, the pixel is not transparent.

(I've extended Image#[] with some bounds checking in the old post I've linked to above. Also, :retro only sets a few OpenGL parameters that change how the image is rendered when it is stretched or rotated, it does not affect the image's pixel data.)
Parent - - By OldBoy Date 2016-07-20 17:34
I've set my goal to make a simpler game first, hopefully I'll be back to your explanation sometime ... :)

> Also, :retro only sets a few OpenGL parameters that change how the image is rendered when it is stretched or rotated, it does not affect the image's pixel data.


is "Gosu::enable_undocumented_retrofication", the same thing?
Parent - By jlnr (dev) Date 2016-07-20 20:01
Yes, but enable_undocumented_retrofication was a only temporary hack while I was working on the :retro flag, which is the new way of doing things: Image.new("filename.png", retro: true)
Up Topic Gosu / Gosu Exchange / get clicked pixel color

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill