Creating images from OpenGL

I wish to create image files in .gif or .jpg format from an opengl implementation in windows xp on Visual Studio .NET C++. I am having trouble trying to find the code to achieve this result. Can you recommend some libraries or code to do this job.

Later on I would like to create an animated gif…but initially would simply like to just output the images.

You simply copy the buffer after rendering(glGetImage? or something) and convert it to jpg/gif. Google for it. And that’s a beginner’s question.

I did google it, but so far the tools tried dont seem to work…the FAQ’s for opengl seem not to work with many of the libraries missing from the website. If someone can actually recommend something. I do know how to use a web search engine. I want a simple pointer on this. Cheers.

Try this(never tried it myself), if it doesn’t help you, google after jpeg library or such

use glreadPixels to get the image from the buffer

have fun :slight_smile:


it seems very general. is there a specific place that you can recommend to do it. I cant find anything vaguely suuitable!


I’m not familiar with any GIF or JPG libraries but the best lossless image format is probably PNG, which has a good library here:

As for getting the pixels themselves from OpenGL you should probably start with the glReadPixels function. That function provides your framebuffer data in a simple uncompressed format such as GL_RGBA.

Sending that data to libpng or to another image library is up to you. OpenGL doesn’t handle that part itself.

If you would prefer a lossy compression library use JPG instead of PNG. JPEG images are smaller on disk than PNG and also lower-quality, although to the eye sometimes you can’t tell the difference. JPEG is what people normally use for family photos etc.

For software images like icons or video game graphics a lossless format like PNG is better.

You don’t even need code; just hit printscreen when your application is running and go to your favorite paint program and goto edit->paste.

Voila! Crop and resize and save as desired. Serve when ready.

You can use DevIL (, then it’s just about 5 lines if you are content with a tga file (and two more if you want jpg or gif):

//one-time initialization

//call this to save a screenshot as screenXX.tga:

Edit: And if you don’t want to use DevIL, you could check out it’s source code…