使用libjpeg library
1. 先把libkpeg.dsw(在我的信箱裡)點開compile
2. 連結libjpeg.lib檔
3. 也要把pic.h, pic.c納進來
4. #include "pic.h"
5. 把以下程式碼放程式中,每個frame都要呼叫到一次
//filename:預存出之檔名 ex “a.jpg”
//nFrameNum:現在輸出的是第幾個frame
//w, h:輸出圖片的寬和高
void save (char *filename, int nFrameNum, int w, int h)
{
int i;
int j;
static char anim_filename[512];
static Pic *in = NULL;
sprintf(anim_filename, "%s_%03d.jpg", filename, nFrameNum); //設定anim_filename
if (filename == NULL) return;
//Allocate a picture buffer.
if(in == NULL) in = pic_alloc(w,h,3,NULL);
printf("File to save to: %s\n", anim_filename);
for (i=h-1; i>=0; i—)
{
glReadPixels(0,h-1-i,w,1,GL_RGB, GL_UNSIGNED_BYTE, &in->pix[i*in->nx*in->bpp]);
}
if ( jpeg_write(anim_filename, in) ) //匯出去成jpg檔
printf("%s saved Successfully\n", anim_filename);
else
printf("Error in Saving\n");
}