Here is my situation: I need to preload 2000 images and display them in sequence to be an animation in 60 fps. Currently, I am using OpenGL to load bmp files, but due to memory limit, I can only preload up to 500+ images. How can I solve this problem? I can so far come up with two directions of solutions: First, maybe I can load 8 bit bmp images to save memory. But I have difficulty in using glDrawPixels. Secondly, if possible can I load jpeg directly? Thanks for any advice!
The reason for not using video is that I need to change to animation speed by skipping one or more images as you can see in the code (imgCount+=stp; // stp means how many images to escape. it can make video faster). And in my animation, frame rate is important, FPS lower than 50 shows flickering.
Here is the code:
void Frame::LoadBMP(void){
FILE *in;
in=fopen(file,"rb");//open file
if(in==NULL){
exit(0);
}
fread(&(this->bmfh),sizeof(BITMAPFILEHEADER),1,in);//read bmp file header
fread(&(this->bmih),sizeof(BITMAPINFOHEADER),1,in);//read bmp infomation header
colours=new RGBQUAD[bmih.biBitCount];
fread(colours,sizeof(RGBQUAD),bmih.biBitCount,in);//read bmp colour table
size=bmfh.bfSize-bmfh.bfOffBits;
tempPixelData=new GLubyte[size];
if(tempPixelData==NULL) {
fclose(in);
}
fread(tempPixelData,sizeof(GLubyte),size,in);//read bmp image data
fclose(in);
}
and I will display the sequence of images, the display code:
void display(void){
static clock_t start=clock();
static clock_t end=clock();
CurrtempPixelData=msFrame[offset]->tempPixelData;
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDrawPixels(frWidth, frHeight, GL_RGBA, GL_UNSIGNED_BYTE, msFrame[offset]->tempPixelData);
for(int i=0;i<m;i++){
clock_t c=clock();
}
glutSwapBuffers();
imgCount+=stp; // stp means how many images to escape. it can make video faster.
offset=imgCount%numFrame;
glutPostRedisplay();
}