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
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post 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.
Last edited by Azhukar on Sun Dec 07, 2014 5:18 am, edited 1 time in total.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post by arampl »

OK. May be I'm reacting too fast, sorry! I'll check on it more carefully.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

Post 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...
Last edited by arampl on Sun Dec 07, 2014 5:33 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: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.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

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

Re: Wrappers for glReadPixel, glColor3uiv / glColor4uiv

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

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.

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 »

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.
Attachments
scrn.png
scrn.png (409.25 KiB) Viewed 3685 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 »

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).
Last edited by arampl on Sun Dec 07, 2014 1:48 pm, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 91 guests