glReadPixels and gluUnProject

[email protected] (V01D)
Newsgroups perl.sdl.devel
Message-ID <[email protected]>
Hi,
I've been wanting to do a small test project with SDL_perl and I noticed 
there's a problem with glReadPixels. I need it to get the 3D point of a 
click of the mouse on 2D. The problem with glReadPixels is that it will 
only return one byte of data when requested something different than RGB 
or BGR (in my case, GL_DEPTH_COMPONENT). In the code you'll see:

                 int len, size;
                 char *buf;
                 size = 1;       /* ALPHA, BLUE, GREEN or RED */
                 if (format == GL_BGR || format == GL_RGB)
                         size = 3;
                 if (format == GL_BGRA || format == GL_RGBA)
                         size = 4;
                 len = height * width * size;    /* in bytes */
                 RETVAL = newSV(len);            /* alloc len+1 bytes */
                 SvPOK_on(RETVAL);               /* make an PV */
                 buf = SvPVX(RETVAL);            /* get ptr to buffer */
                 glReadPixels(x,y,width,height,format,type,buf);
                 SvCUR_set(RETVAL, len);         /* set real length */

I need format = GL_DEPTH_COMPONENT. The code above doesn't care about 
the data type requested (GL_FLOAT in my case, which is usually 4 bytes). 
The above code assumes that I will only request RGB/BGR or BGRA/RGBA. If 
I request something else it assumes 1 byte.
The correct behaviour, i think, would be to multiply 'len' by the size 
corresponding to the data type requested (GL_BYTE, GL_UNSIGNED_INT, 
etc). This way retrieving all values and every format would be possible.

On the other hand, gluUnProject has a weird behavior regarding its 
output. It returns an array, but inside a scalar (?). And its not a 
reference (although I may be missing something):

my $ret = gluUnProject($xpos, $ypos, $zpos, $mdl, $proj, $viewport);
print "$ret\n";

gives me:
ARRAY(0x8668138)

I tried making gluUnProject work by reading only one byte (and doing 
$data/255, to get a float) using glReadPixels but it doesn't seem to 
work (maybe it needs the precision of a float).

Thank you

	
	
		
___________________________________________________________ 
1GB gratis, Antivirus y Antispam 
Correo Yahoo!, el mejor correo web del mundo 
http://correo.yahoo.com.ar
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.