Wrappers for glReadPixel, glColor3uiv / glColor4uiv

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.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

S0lll0s wrote: So just store the values in a table!
Objects (sprites, widgets, anything, hundreds or more of them) in the table will be inserted, deleted, sorted. Possibly many times per frame. If I place corresponding color tuples in the table I will have to renumerate them to maintain connection with corresponding objects. So this values must be generated on the fly.
What is faster in such situation? setColor(simply object index) or setColor(complex formula). (formula to generate sequence rgb(0,0,1)...rgb(0,0,255),rgb(0,1,0)...rgb(255,255,255)).
If we have glColor3uiv then rgb(0,0,1) = simply "1", rgb(0,1,0) = simply "256", etc.
So in the loop it will be (pseudo code):

for i = 1 to 10
setColor(i)
next

instead of

for i = 1 to 10
setColor(some formula)
next
S0lll0s wrote: And why would you need to get the pixel color? If its a colorpicker you have the formula anyway...
No. It is object picker, not a colorpicker. Non-rectangular button for example. Picking object by color is one of the common and simple techniques in OpenGL. Yes, I still will need formula (simple enough) when I read pixel to convert color to obect index, but I will not need any formulas to calculate next object's color when I draw it.

Didn't you tried code I've posted yet?
I'm talking about specific problem for real application, not some abstraction, not some academic exercise in LÖVE2D / Lua programming.
And I'm also talking not about how to do it (it is already done in the code I've posted), but how to do it better, with speed in mind.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

Remember this?
Attachments
iwd2.png
iwd2.png (42.57 KiB) Viewed 3614 times
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

To detect button under mouse cursor I need to draw this first:
Attachments
iwd2colors.png
iwd2colors.png (27.13 KiB) Viewed 3613 times
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by Azhukar »

I have no idea why you're using a shader, stencil, scissors and a canvas to do a simple pixel perfect button.
Attachments
Pixel-perfect buttons.love
(4.31 KiB) Downloaded 223 times
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

You simply test rectangular region + alpha.
It will not work on non-rectangular objects, like buttons inside ellipse in IWD2 interface, because rectangular regions for them will cross each other.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

Of course. I'm talking about their arrangement. Any one of them will reside in the rectangular region of the other one.
Last edited by arampl on Sun Dec 07, 2014 4:56 am, edited 1 time in total.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by Azhukar »

arampl wrote:You simply test rectangular region + alpha.
It will not work on non-rectangular objects, like buttons inside ellipse in IWD2 interface, because rectangular regions for them will cross each other.
The IWD2 interface can be made exactly like the example I posted. It works for overlapping objects. Did you actually run it?

Go over the buttons with your mouse and think about it for a moment what is happening in the code.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

See this cross-section between two buttons? Which will be pressed if mouse cursor will be inside it?
It's just simple example.
Attachments
image3047.png
image3047.png (46.95 KiB) Viewed 3598 times
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

Now, try your code with this stars:
Attachments
path3064.png
path3064.png (12.38 KiB) Viewed 3589 times
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

Azhukar wrote:
arampl wrote:You simply test rectangular region + alpha.
It will not work on non-rectangular objects, like buttons inside ellipse in IWD2 interface, because rectangular regions for them will cross each other.
The IWD2 interface can be made exactly like the example I posted. It works for overlapping objects. Did you actually run it?

Go over the buttons with your mouse and think about it for a moment what is happening in the code.
Of course. I'm talking about their arrangement. Any one of them will reside in the rectangular region of the other one.
Yes I executed your code. You mean I must get all image pixels of each object each time? Several hundred times * 60 FPS?
Last edited by arampl on Sun Dec 07, 2014 5:16 am, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 54 guests