The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Issues with using ReadPixels

Hello,

I'm trying to do picking with openGL. In a first time, before trying ray tracing, I'm trying to use the alpha channel (I only have a few items in my scene) to select the item corresponding to the cursor.

I saw that ReadPixels allows to get back the colors from a pixel, so i tried it. Here is a part of my code (context initialization, mouseDown event function).

So i define an item with a buffer color fulled of (x.x,y.y,z.z,0.6), and put a rotation conditioned by a "if (currentSelection==0.6 || currentSelection==153)". But when I test it it doesn't work. After a few tries, it seems than my readPixels() makes the handleMouseDown(event) bug, indeed every line I add after readPixel() doesn't work. And I don't understand where the issue is as my buffer has good format and as I make sure of keeping the drawing buffer.

Anyone has an idea ?

PS : the mozOpaque for the context is for Firefox, to the canvas remains opaque.

Re: Issues with using ReadPixels

Well well... it seems i should get back to the beginner part of the Forum.. I forgot a "gl." before "RGBA" and that explains it blocks the following, and now it works even if it returns 255 everytime for alpha and 0 for every color (i.e. my background). I'll try to fix it.

// A non-power-of-two texture has restrictions; see
// http://www.khronos.org/webgl/wiki/WebGL ... ifferences
// Important note: This destroys antialiasing, so render to texture is
// fully useful only for doing some computations, unless we do our own antialiasing.
// We could render to a large offscreen texture, say twice the width and height.

Note that antialiasing being turned off is actually what one wants for mouse picking because you don't want an object with id of 10 that is next to an object of id 30 to get picked with an id of 20, which could happen with antialiasing turned on, due to the averaging of neighboring colors.

Re: Issues with using ReadPixels

I'm sorry, but I don't understand the question. Surely one needs to render to a texture in order to be able to read the pixel color from the texture? Can you explain more fully how you would implement picking?