Some questions about using OpenGL glReadPixels()

Started by
5 comments, last by Kuei_ling 21 years, 11 months ago
I want to make AVI from OpenGL Application directly. So I try to use glReadPixels() to get OpenGL data, but got some problem. 1.When de-active ReDrawWin() function, glReadPixels() could get one frame. But that frame is not right. What I got is the frame that the screen scene before got into the ¡§for¡¨ loop. (I think this is because the OpenGL data didn¡¦t refresh yet.) And the following frames I got in the ¡§for¡¨ loop seems didn¡¦t get successfully, or all success but look like the same. Open AVI file and just see the same frame. So I suppose that my problem is that I didn¡¦t refresh my OpenGL data. Then I add the ReDrawWin() function. 2.When active ReDrawWin() function, and add the ¡§for¡¨ loop frames to AVI, the whole frames are all dark. Nothing I can see. But the Rect of frames seems right, and the file size is equal to the foregoing AVI file. (The frame Rect is also equal to the foregoing.) Please reference the following program I used. Is there any wrong with OpenGL or Windows settings when I used glReadPixel? //=============================================== 1.I created a Rendering Context and make it current. 2.I read the back buffer. 3.I set the PIXELFORMATDESCRIPTOR. Above 3 points are the settings I did. ¡K CAVIGenerator AVIGenerator; //Do some AVI setting¡K BYTE* bmBits; //bmBits settings¡K¡K glReadBuffer(GL_BACK); for(int i = 1; i < 10; i ++) { //Changing openGL data¡K ¡K //ReDrawWin(); //To redraw window, cause the OpenGL data has changed. //And the window will call SwapBuffer to refresh buffer and pixels data. glReadPixels(0,0,bmpheader->biWidth, bmpheader ->biHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,bmBits); AVIGenerator .Add Frames(); } glReadBuffer(GL_FRONT);
Advertisement
Do you really want to grab the data from the back buffer? Since you SwapBuffers before you ReadPixels, the back buffer is probably full of junk...see what happens if you read from the front buffer.
If I just read FRONT buffer, and didn''t swap buffer.
All frames are dark.
But when I read FRONT buffer, and swapped buffer.
All frames are whole dark too.

Is there any other function I can try?
try doing glFinish() or better glFlush() beforehand

http://uk.geocities.com/sloppyturds/gotterdammerung.html
I fixed my problem.
Thank you all for your help.

My program must execute on a restricted system.
I must call swap buffer to update OpenGL buffer data, or the data I got will all the same.
Originally, I think my problem is about OpenGL settings.
But, finally I found that after I called swap buffer, my render context changed. (I called ten times, ten times changed.)

If updated this function, wglMakeCurrent(hdc, hRC), I can get the frames I want.

Thank you very much for your help.
Make sure your window is created with the CS_OWNDC style. Then your hDC should not change.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
If the window I used is not created from me, and I don''t know the register class name of this window.(I can''t created by my self.)
I still can re-RegisterClass?
If can, how to know the previous register calss name?

This topic is closed to new replies.

Advertisement