View Full Version : glReadPixels();
devdept
03-03-2010, 07:03 AM
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
ZbuffeR
03-03-2010, 07:10 AM
almost :)
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
devdept
03-04-2010, 06:13 AM
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
ZbuffeR
03-04-2010, 07:33 AM
int R = count % 2**5;
int G = (count >> 5) % 2**6;
int B = (count >> 11) % 2**5;
int id = (B << 0) + (G << 5) + (R << 11);
devdept
03-04-2010, 12:55 PM
Thanks ZbuffeR, I'll try and let you know.
Alberto
devdept
03-05-2010, 01:36 AM
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
ZbuffeR
03-05-2010, 02:14 AM
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 :)
devdept
03-05-2010, 02:27 AM
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 :)
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
Pierre Boudier
03-05-2010, 07:20 AM
just to make sure, did you disable dithering when you rendered ?
devdept
03-05-2010, 07:55 AM
Yes, the bitmap is draw with solid colors.
Thanks,
Alberto
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.