PDA

View Full Version : Creating images from OpenGL



dt
07-05-2005, 01:06 AM
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.

Zengar
07-05-2005, 02:35 AM
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.

dt
07-05-2005, 03:18 AM
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.

Zengar
07-05-2005, 03:30 AM
Try this(never tried it myself), if it doesn't help you, google after jpeg library or such

http://www.ijg.org/

use glreadPixels to get the image from the buffer

have fun :)

dt
07-05-2005, 03:41 AM
thanks

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

Cheers

sparkster
07-05-2005, 08:42 AM
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:

http://www.libpng.org/pub/png/

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.

sparkster
07-05-2005, 08:52 AM
http://www.ijg.org/

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.

Omaha
07-08-2005, 04:10 PM
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.

Nico_dup1
07-09-2005, 09:09 AM
You can use DevIL (www.imagelib.org), 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
ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);

//call this to save a screenshot as screenXX.tga:
ilutGLScreenie();

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