PDA

View Full Version : glReadPixels corrupting the image?



royshil
01-04-2009, 01:02 PM
Hi guys

I am trying to read the contents of an FBO, but the resulting image is corrupted (see the images).



img_data = (unsigned char*)malloc(width*height*3);
glReadPixels(0,0,width,height, GL_RGB, GL_UNSIGNED_BYTE,img_data);
FILE* f = fopen("tmp.raw","w+");
fwrite(img_data,(width)*(height)*3,1,f);
fclose(f);


Does anyone have a clue what is wrong?

Thanks,
Roy.

result
http://img2.timg.co.il/forums/1_125549087.png

screen framebuffer
http://img2.timg.co.il/forums/1_125549132.png

dletozeun
01-04-2009, 01:27 PM
Use glPixelStore(GL_PACK_ALIGNMENT, 1); before calling glReadPixels.

royshil
01-04-2009, 11:49 PM
i guess the problem is the FBO itself, since glReadPixels on the main framebuffer produced correct results.

using glPixelStore(GL_PACK_ALIGNMENT, 1); did not yield better or different results in any way...


another question, what is the best way to render offscreen scenes?
I tried to do it but it seems the scene is not rendering.
I tried once to initialize OpenGL using HWND - HDC & wglCurrent, and once initialize using GLUT

nothign works

_NK47
01-05-2009, 02:22 AM
the best way is actually FBO. :) there are also pbuffers but they are platform dependend in implementation and somewhat painful to implement. Try some samples on your machine see how the work and how they do it.

k_szczech
01-05-2009, 03:49 AM
I use FBO to render to texture and then glGetTexImage instead of glReadPixels. Works fine everywhere I tried.