Page 3 of 5

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 3:40 am
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.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 3:57 am
by arampl
Remember this?

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 4:01 am
by arampl
To detect button under mouse cursor I need to draw this first:

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 4:41 am
by Azhukar
I have no idea why you're using a shader, stencil, scissors and a canvas to do a simple pixel perfect button.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 4:49 am
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.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 4:55 am
by arampl
Of course. I'm talking about their arrangement. Any one of them will reside in the rectangular region of the other one.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 4:56 am
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.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 5:04 am
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.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 5:07 am
by arampl
Now, try your code with this stars:

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sun Dec 07, 2014 5:09 am
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?