Order of the Butterfly
Posts: 186 from 2003/10/23
hi :D
for picking an object in my game i use the simple opengl color picking method.
for now it only work on pc , and all the example founded in internet refer only to little-endian machines.
first i draw a polygon with this code :
-------------------------------------
int nIndex ;
nIndex = 1000;
glColor3ub ( nIndex % 256, (nIndex>>8) % 256, (nIndex>>16) % 256);
glBegin(GL_QUADS);
glVertex3f( -0.5f, -0.5f, +0.5f);
glVertex3f( +0.5f, -0.5f, +0.5f);
glVertex3f( +0.5f, +0.5f, +0.5f);
glVertex3f( -0.5f, +0.5f, +0.5f);
glEnd();
----------------------------------------------------
my picking routine is this :
-----------------------------------------------
unsigned char *pRGB;
pRGB = malloc(sizeof(unsigned char)*4);
glReadPixels( mousex, viewport[3]-mousey, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pRGB);
ColorNumber = (pRGB[ 0 ]) + (pRGB[ 1 ]*256) + (pRGB[ 2 ]*256*256);
----------------------------------------
this routine work only on Pc, on the peg the number returned isn't 1000.
so there is involved the little/big-endian problem.
i can't find a solution to obtain the same color number i obtain on the Pc (in this example 1000)
and no i don't want to study the ray-plane intersection
anyone want to help ?? please :D
I'm nerdy in the extreme
And whiter than sour cream
White&Nerdy 2006 Al Yankovic