Archived

This topic is now archived and is closed to further replies.

Capturing the screen - glReadPixels

This topic is 4945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I''m havin problem capturing the screen when under MicrosoftWindows. As I''m coding under Linux, everything is tested under it then I port it to Windows cause it is a project, and all my code runs fine under Linux. However, when capturing the screen under windows, the TGA file(the output of my program) is a green mess. I''m using GLUT, I''ve tried glutFullScreen and the glutGameMode but that doesn''t change a thing. I''m using a double RGBA buffer. Here is the code : //Allocation of an array for storing the capture if ((buffer = (unsigned char *)malloc((int)menu.width * (int)menu.height * 4 * sizeof(unsigned char))) == NULL) { printf("Erreur lors de l''allocation du buffer de capture.\n"); exit(0); } //We wanna read the front buffer, the visible one glReadBuffer(GL_FRONT); glReadPixels(0, 0, (int)menu.width, (int)menu.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); //R and B swapped, Alpha omitted for (i=0; i < ((int)menu.width * (int)menu.height * 4); i+=4) { fwrite(buffer + i + 2, 1, 1, capture); fwrite(buffer + i + 1, 1, 1, capture); fwrite(buffer + i, 1, 1, capture); } fclose(capture); After looking at some posts and docs I''ve added this : glPixelStorei(GL_PACK_SWAP_BYTES,GL_FALSE); glPixelStorei(GL_PACK_LSB_FIRST,GL_FALSE); glPixelStorei(GL_PACK_ROW_LENGTH,0); glPixelStorei(GL_PACK_SKIP_ROWS,0); glPixelStorei(GL_PACK_SKIP_PIXELS,0); glPixelStorei(GL_PACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT,1); Doesn''t change a thing though.... I''m running out of time for this project, so pleaze, anyone with an idea or who had encountered the same problem will be of a great help !!! Thks PS : Maybe this could be of a help too, I have an ATI Radeon32SDR(Ze first one...Don''t laugh...).

Share this post


Link to post
Share on other sites
mmm... Its probable the tga file format.
And you have to switch your red and blue value.
and check the tga header file, you not seem to put one.

Share this post


Link to post
Share on other sites
Well of course the file format was respected and there is a header, but this part of the code wasn''t important for the post.

I''ve found out how to solve my problem, it was glReadBuffer(GL_BACK) instead of GL_FRONT. I was so sure that the FRONT BUFFER was the visible one and the BACK was the hidden one to wich we actually draw...

Share this post


Link to post
Share on other sites