GLubyte* image;
image = new GLubyte[display_width * display_height * 3];
glReadBuffer(GL_BACK);
glReadPixels(0,0, display_width, display_height, GL_BGR, GL_UNSIGNED_BYTE, image);
FILE *out = fopen((image_dir+screen_shot_name + ".tga").c_str(), "w");
short TGAhead[] = {0, 2, 0, 0, 0, 0, display_width, display_height, 24};
fwrite(&TGAhead, sizeof(TGAhead), 1, out);
fwrite(image, 3*display_width*display_height, 1, out);
screen shot using glReadPixels produces garbled image
I am having some with screen shots. The result I get looks like this:
http://img147.imageshack.us/img147/4997/imagexx7.png
The screen image is fine at run time and the objects are drawn with display lists - I mention this as the output is fine with only the skybox which at this stage is drawn in immediate mode.
The code that produced this soup is:
All suggestions appreciated.
Since you're reading from the back buffer, are you calling this code BEFORE swapping buffers? After a buffer swap, the content of the back buffer is undefined, and you should then read from the rfont buffer.
I wondered the same thing but found that I got the same result whether I use the back or front buffer.
Then I think you have to show more code. Can you produce a complete, MINIMAL, compilable and runnable example demonstrating the error? Remove anything that isn't relevant to the problem. Reduce the object to a single tringle, remove user interaction, don't use textures, anything as long as the problem is still there. Anything to reduce the amount of code.
Hmmm, I agree but it would be difficult to get the code down to be small enough to post as it would at least include SDL and the .obj loader that I have written.
I might play around with this a bit before trying to strip it down to that point as there are about 25 translation units...
I might play around with this a bit before trying to strip it down to that point as there are about 25 translation units...
Did you try to read the backbuffer before swapping? It should work.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1) is needed if you will use BGR
or don't call glPixelStorei and just use BGRA
What's you video card + drivers?
glPixelStorei(GL_UNPACK_ALIGNMENT, 1) is needed if you will use BGR
or don't call glPixelStorei and just use BGRA
What's you video card + drivers?
Quote:Original post by manton
Hmmm, I agree but it would be difficult to get the code down to be small enough to post as it would at least include SDL and the .obj loader that I have written.
Why would you have to include the entire .obj loader? As I said, replace the object with a single triangle or something. That's, like, 5 small lines of code only. Handcoded coordinates; no need for dynamic loading of complex shapes in complex file formats. If the problem is still there, it doesn't matter what you draw.
SDL isn't so much code. Just open a window, draw a triangle, make the screen dump and exit the program.
Did you intend to write as binary instead? Opening a .tga file in notepad, it looks like it is in the binary format.
Try changing
FILE *out = fopen((image_dir+screen_shot_name + ".tga").c_str(), "w");
to
FILE *out = fopen((image_dir+screen_shot_name + ".tga").c_str(), "wb");
Can you also show us a picture of what its supposed to look like? Just use print screen instead.
[Edited by - ScottC on September 27, 2006 9:18:50 PM]
Try changing
FILE *out = fopen((image_dir+screen_shot_name + ".tga").c_str(), "w");
to
FILE *out = fopen((image_dir+screen_shot_name + ".tga").c_str(), "wb");
Can you also show us a picture of what its supposed to look like? Just use print screen instead.
[Edited by - ScottC on September 27, 2006 9:18:50 PM]
Uh, if you're using this on a big-endian architecture like PowerPC or SPARC, that TGA loader doesn't appear to be endian-independent.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement