Output Screen To BMPs

Started by
5 comments, last by Bretttido 22 years, 5 months ago
I''m trying to figure out how to output the rendered image produced from my openGL program into a Bitmap file. If anyone knows of a good way to do this that doesn''t cut the framerate down to something like 0.1 fps, please let me know. I know how to write a bitmap file, but mainly all I need is how to access a pointer to the final image data (or something along those lines)
Advertisement
unsigned char* imageData = malloc(width*height*3);
memset(imageData, 0, width*height*3);
glReadPixels(0, 0, width-1, height-1, GL_RGB, GL_UNSIGNED_BYTE, imageData);

// write bitmap file here

free(imageData);

- Mike

Edited by - mkaltner on October 17, 2001 5:28:47 PM
"The important thing to remember when programming is: When you're 90% complete, there's still 50% more to go."
Exactly what i was looking for, thanks. I''ll try that out.
By the way, the function should read:

glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, imageData);

as the third and fourth parameters define the actual width and hieght of the region to be read from, as opposed to the right/top bounds.

Edited by - Bretttido on November 7, 2001 7:40:57 PM
Well, it looks like a silly WindowsXP error has resulted in me trying to fix a bug with creating my bitmap that never even existed. I was using the details-panel on the left of a window that displays the thumbnail of the bitmap (a lot quicker than openning up photoshop). And for some reason, the background color of what was rendered wasn''t being displayed at all. After hours of pulling out my hair, I finally decided to open up the bitmap in photoshop... and behold, the background color was there all along. Looks like the thumbnail preview attempts to figure out the background color and set it to white? Okay... POSSIBLY a useful feature if you like to see things with a different background then they were intended for =P; but look at this, I change the size of the picture from 300*200 to 296*200.. and boom, the background is displayed.

After tons of experiments, it looks like the thumbnail tests if the top right corner can be "paint-bucket-filled", and if a certain percent of the image is filled, it turns that to white. And oddly, the paint bucket fill-size seems to be 2 pixels. This is all just my speculation from a few crude experiments, so don''t quote me on it.

Anyone know what''s going on with this wacked-out thumbnail?

Are you sure you filled out the bitmap header properly? Some readers are particular about the details in the header.

------------
- outRider -
Yes, the header is all correct. In fact, I''ve tried creating a bitmap from scratch with photoshop and see the same results.

This topic is closed to new replies.

Advertisement