Page 4 of 5
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 5:14 am
by Azhukar
arampl wrote:Any one of them will reside in the rectangular region of the other one.
That is fine, the code I wrote first checks for collision with the rectangular region of the image, if no collision is detected it discards button and proceeds onto another, if it finds a collision with the rectangle it then checks whether there is a visible image pixel on the coordinates.
I don't believe you understood what is happening, or what you want for that matter.
arampl wrote:Now, try your code with this stars:
It works flawlessly even with the stars. What problem are you experiencing?
arampl wrote:You mean I must get all image pixels each time? Several hundred times * 60 FPS?
You only "get" a single pixel, the entire image data is already loaded and stored. The getData call simply gets the reference. And even then it's called only after the mouse coordinates overlap a button. It's extremely miniscule and you won't notice any performance impact even if you had a thousand buttons.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 5:17 am
by arampl
OK. May be I'm reacting too fast, sorry! I'll check on it more carefully.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 5:27 am
by arampl
Then how can I recognize which star was pressed if it will be only outlined and not filled? Like in vector editor for example.
EDIT: Oops. It can't be done with my method either...
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 5:32 am
by Azhukar
arampl wrote:Then how can I recognize which star was pressed if it will be only outlined and not filled? Like in vector editor for example.
A pixel can have 0 alpha but positive rgb values, this can be used to create an invisible mask right in your image for your code to check for, just like in the example you see the rgba check. You could check for rgba(123,123,123,0) and interpret that as a non transparent pixel in your code.
Another option is having 2 images, one is for drawing, the other will not be drawn but will be loaded as a mask for your function to pick the pixel from.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 5:35 am
by arampl
Oh! I like that idea with alpha = 0 and positive rgb values. Thank you! Will check it.
It seems that all my code useless at all.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 6:11 am
by arampl
Again. I still need to generate unique color for the mask of objects to differentiate them. In both methods. Objects not necessarily will be loaded from somewhere with prepared mask, they can be created inside application.
And again love.graphics.setColor(k) is better then love.graphics.setColor(math.floor(k / 2 ^ 16), math.floor(k / 2 ^ 8) % 2 ^ 8, k % 2 ^ 8, 255)...
Will think more about it.
But I feel that image:getData can replace use of canvas.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 11:33 am
by Azhukar
arampl wrote:Again. I still need to generate unique color for the mask of objects to differentiate them. In both methods. Objects not necessarily will be loaded from somewhere with prepared mask, they can be created inside application.
And again love.graphics.setColor(k) is better then love.graphics.setColor(math.floor(k / 2 ^ 16), math.floor(k / 2 ^ 8) % 2 ^ 8, k % 2 ^ 8, 255)...
No you don't, this is absolute non-sense. As you can see in the code I provided, you can already assign unique tables to each mouseover object without any such thing. In the same way you can assign an ID to the objects.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 12:07 pm
by s-ol
There is no "complex formula" in your loop when you store the color in a rgb tuple. Yes, its a bit more space wasted but I wanna see your project if you really need to care about that. And why would you need to reorder the table? You can treat the color tuple just like your super-cool-and-performant-uint and for example store it with the object you are drawing.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 1:33 pm
by arampl
First of all, big thank you, guys! So many ideas, advices.
Well, I explain little about project. (I work in Xubuntu 13.10 and use medit text editor).
It will be someday "yet another LÖVE2D IDE" with content generation capabilities.
As of now it can:
- create/delete/drag&drop buttons (with caption) and simple forms (just bordered rectangles for now)
- generate bitmap fonts with several effects (I'm using ImageMagick library wrapper for that (very much work ahead))
(of course I want to leave ImageMagick behind someday and use shaders for image processing)
- use customizable (I named them "non-regular") grids with align to grid ability (even useful for character ragdoll page for items in rpgs (armor, weapon, rings, etc))
- save / load buttons & action references for them.
Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv
Posted: Sun Dec 07, 2014 1:36 pm
by arampl
I will need extreme speed for object picking in the future because selection of several objects under cursor will be needed. So I will test selection after drawing each single object...
EDIT: And I want universal way to do picking for whatever objects I'll deal with. Write code once and forget about it.
EDIT2: I am already rewrited code and it don't use stencil anymore (for picking)...
EDIT3: Grids supports scaling and in the future will support rotating (will be useful for isometric rpgs).