PDA

View Full Version : Where are the pixels of the current scene stored



Amx90
06-15-2009, 04:15 PM
Hello guys

Where are the pixels of the current scene stored. Basically, I want to know get the pixels information of the current scene such as color, intensity and position.

scratt
06-15-2009, 05:52 PM
Depending on how you are drawing your scene the normal case is the pixels end up in the current FrameBuffer.

You can read pixels from the FrameBuffer using glReadPixels..
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/readpixels.html

Be aware that this is not the fastest way to get data, so depending on what you are trying to do it may be worth looking at FBO (FrameBufferObjects) and "drawing to textures", and then using shaders or other means to do computation on that data.

But for now, for what you need glReadPixels should do.

Dark Photon
06-16-2009, 05:43 AM
Depending on how you are drawing your scene the normal case is the pixels end up in the current FrameBuffer.

You can read pixels from the FrameBuffer using glReadPixels..
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/readpixels.html

Also be aware that you may not get the exact same results as are displayed if you have antialiasing enabled (e.g. multisampling) as the same path is not necessarily used to perform the multisample resolve before scan-out as is used to perform the multisample resolve before readback.

So disable antialiasing and you can be reasonably sure you're going to get the same thing with glReadPixels that you see on the screen.

Amx90
06-16-2009, 06:57 PM
I wrote this code to get the three colors of the pixels


int BIT_R=8;
int BIT_G=8;
int BIT_B=8;
int WIDTH=2;
int HEIGHT=2;
glReadBuffer(GL_BACK);
GLvoid *imageData = malloc(WIDTH*HEIGHT*(BIT_R+BIT_G+BIT_B));
glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, imageData);

I tried to fetech the array but I don't know what how the information stored into imageData array
So how can I store this information into the screen using "cout" as :
x y R G B
value value value value value

dletozeun
06-17-2009, 03:33 AM
I tried to fetech the array but I don't know what how the information stored into imageData array
So how can I store this information into the screen using "cout" as :
x y R G B
value value value value value


You mean, how to display imageData array values?

You can do something like:



int pixelNb = WIDTH*HEIGHT;
for( int i = 0; i< pixelNb; ++i )
{
cout << hex << imageData[ i ] << imageData[ i + 1 ] << imageData[ i + 2 ] << endl;
}


Assuming imageData is a array of GLubyte values.

Amx90
06-18-2009, 02:58 AM
I tried the code but I get output like this:
???
???
???
...

the code that I used


int WIDTH=2;
int HEIGHT=2;
glReadBuffer(GL_BACK);
GLubyte imageData[WIDTH*HEIGHT*4] ;
glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, imageData);
int pixelNb = WIDTH*HEIGHT;
for( int i = 0; i< pixelNb; ++i )
{
cout << hex << imageData[ i ] << imageData[ i + 1 ] << imageData[ i + 2 ] << endl;
}

dletozeun
06-18-2009, 03:14 AM
You allocate to much memory though it is not the problem here, it should be:

GLubyte imageData[WIDTH*HEIGHT*3];

use the hex modifier as I suggested:

cout << hex << imageData[ i ] << imageData[ i + 1 ] << imageData[ i + 2 ] << endl;

Amx90
06-18-2009, 03:28 AM
still
???
???
???

dletozeun
06-18-2009, 03:35 AM
Look at this:
http://www.cplusplus.com/reference/iostream/ios_base/fmtflags/