Page 1 of 5

Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 9:02 am
by arampl
Hi all!

@devs: Please, implement those! Must have for object picking by color without using canvas and formulas for color to number conversion.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 9:28 am
by bartbes
glReadPixel is slow, take a screenshot instead and read the pixel from that. Slow, you say? Exactly.

As to the glColors, I'm not sure what you're on about.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 9:48 am
by arampl
I'm talking about reading several pixels near mouse cursor.
And it will be made each frame.
So taking screenshot...
Now I'm using canvas for reading pixels, but it is not supported everywhere, as I heard.

And about glColor3uiv / glColor4uiv. I will prepare and show sample lua file here to explain what I mean. Little later.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 12:07 pm
by s-ol
arampl wrote:I'm talking about reading several pixels near mouse cursor.
And it will be made each frame.
So taking screenshot...
Now I'm using canvas for reading pixels, but it is not supported everywhere, as I heard.

And about glColor3uiv / glColor4uiv. I will prepare and show sample lua file here to explain what I mean. Little later.
Isn't glColor3/4uiv just setting the color from an array? That's exactly what lovr.graphics.setColor() does...

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 4:15 pm
by arampl
S0lll0s wrote:
arampl wrote:I'm talking about reading several pixels near mouse cursor.
And it will be made each frame.
So taking screenshot...
Now I'm using canvas for reading pixels, but it is not supported everywhere, as I heard.

And about glColor3uiv / glColor4uiv. I will prepare and show sample lua file here to explain what I mean. Little later.
Isn't glColor3/4uiv just setting the color from an array? That's exactly what lovr.graphics.setColor() does...
No. With glColor3uiv / glColor4uiv you can set color as a single unsigned integer value 24/32 bit, not a separate 3 or 4 values RGB or RGBA: setColor(255, 0, 0) opposed to setColor(4356345) or something like this.

I'll post sample code when translate comments to it, and it will tell you all the details.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 4:24 pm
by bartbes
So

Code: Select all

function setColor(r)
    return love.graphics.setColor(math.floor(r/16777216), math.floor(r/65536)%256, math.floor(r/256)%256, r%256)
end
And this is so much more useful because...

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 4:30 pm
by arampl
Look at this, guys.

EDIT: stripped out comments for now...

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 4:36 pm
by arampl
As of now I'm doing all the stuff with canvas and formulas for converting setColor(r,g,b) to some single value (obect's id).
Imho It will be much cleaner if we can just use setColor(obect id)...
In OpenGL + C it can be done flawlessly...

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 4:40 pm
by arampl
bartbes wrote:So

Code: Select all

function setColor(r)
    return love.graphics.setColor(math.floor(r/16777216), math.floor(r/65536)%256, math.floor(r/256)%256, r%256)
end
And this is so much more useful because...
I'm doing exactly something like this and want to get rid of this calculations each frame.

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Posted: Sat Dec 06, 2014 4:49 pm
by arampl
glReadPixels & glColor(single value) will solve so many problems...
This functions is so "base" functions of OpenGL...

Of course I can live without them...

P.S. :(