View Full Version : Saving OpenGL output as Fixed Dimension JPG

05-27-2010, 07:21 AM
Hi there,
I am rendering some objects as a scene. After i am done displaying it i want to save it as JPEG file.
I am able to save it to JPEG file by reading pixels by using glReadPixels() method.
Considering i know the bounding rectangle of my object being displayed, now i want to save the JPG file as fixed dimension ( M X N) where M and N will be constant and also i want my object to cover large area with some frame on it.
for example:-
If I want image of dimension 2000*2000 and my object bounding rectangle is 700*550 then i want to scale that to 1800*1800 and remaining outer pixels as the border of image.

How can i achieve this?

thank you

05-27-2010, 08:26 AM
What makes you think that JPEG has something to do with OpenGL?
You obviously have to find an appropiate library that can help you with this.

05-27-2010, 08:34 AM
yes.. openGL doesn't do that. But i was thinking of using FBO and scale the content of it and then save it. But i am not sure if FBO is the right choice or not or if this is the right way to go ?

let me know your thoughts.

05-27-2010, 08:47 AM
You can render to a FBO with the dimensions that you desire.
You could of course use texture filtering to do your scaling, but that would be of a low quality and messy.

The best way to do this is to use a dedicated scaling functionality of an image library.

05-27-2010, 08:56 AM
Another option might be to just use gluScaleImage on the data that you've captured via glReadPixels.

05-28-2010, 06:35 AM
hi guys,

thanks for all the suggestions..
i tried using gluScaleImage and it works fine but again it is dependent on the size of window as i will be taking pixels from glReadPixels() so this approach seems to be temporary solution to my problem.

I think i need to use FBO. Can anyone point me to right direction or simple example on how do i use FBO and how to do scaling using it?

thank you so much for your help.