glReadPixels();

Hi All,

Is it possible to read a 16bit color depth bitmap from a 24bit color rendering context or the two color depth have to always match?

In the case that’s possible. Should we use the following syntax:

glReadPixels(0,0, width, height, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_BYTE, pData);

Thanks,

Alberto

almost :slight_smile:
just do not forget the “format” = GL_RGB
and for 16 bit rgb, use GL_UNSIGNED_SHORT_5_6_5

Nicely detailed on the documentation :
http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml

Thanks ZbuffeR,

With your help we can now correctly load the bitmap. Now the problem is the object ID encoding:

With 24 bit color depth we use:

int R = count % 256;
int G = (count >> 8) % 256;
int B = (count >> 16) % 256;

and the following to read back the ID from pixel color:

int id = (B << 0) + (G << 8) + (R << 16);

How do we need to change this for 16 bit color depth?

Thanks,

Alberto

int R = count % 25;
int G = (count >> 5) % 2
6;
int B = (count >> 11) % 2**5;

int id = (B << 0) + (G << 5) + (R << 11);

Thanks ZbuffeR, I’ll try and let you know.

Alberto

Strangely when I pass count = 8, I get the following values:

int R = (count) % 2^5; // = 8
int G = (count >> 5) % 2^6; // = 0
int B = (count >> 11) % 2^5; // = 0

glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, data);

int id = (B << 0) + (G << 5) + (R << 11); // = 2048

Do you know why?

Thanks,

Alberto

bgr write versus rgb read, wondering why your original formulas were not symetric.

just try :

int B = (count) % 2^5; // = 8
int G = (count >> 5) % 2^6; // = 0
int R = (count >> 11) % 2^5; // = 0

BTW do you earn a lot of money with your company ? You should donate some to forum users helping so much :slight_smile:

Not so much unfortunately :(, but I consider this forum and the help you all provide the main reason of the OpenGL technology never ending success!

We will for sure donate if there is a place where I can do it :slight_smile:

Already tried reversing without success. 2048 in binary is:

00001 000000 00000

It has nothing to do with the ID=8 I have passed… I need to investigate further.

Thanks,

Alberto

just to make sure, did you disable dithering when you rendered ?

Yes, the bitmap is draw with solid colors.

Thanks,

Alberto