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

Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

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

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post 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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post 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...

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
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:
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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

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

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

Look at this, guys.

EDIT: stripped out comments for now...
Attachments
pick.love
(3.66 KiB) Downloaded 240 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 »

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

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

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

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post 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. :(
Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests