【发布时间】:2012-08-16 04:34:18
【问题描述】:
这是我的情况:我需要预加载 2000 张图像并按顺序显示它们以成为 60 fps 的动画。目前,我正在使用 OpenGL 加载 bmp 文件,但由于内存限制,我最多只能预加载 500 多个图像。我怎么解决这个问题?到目前为止,我可以提出两个方向的解决方案:首先,也许我可以加载 8 位 bmp 图像以节省内存。但是我在使用 glDrawPixels 时遇到了困难。其次,如果可能的话,我可以直接加载 jpeg 吗?感谢您的建议!
不使用视频的原因是我需要通过跳过一个或多个图像来更改动画速度,如您在代码中看到的(imgCount+=stp;//stp表示要转义多少图像。它可以制作视频快点)。在我的动画中,帧率很重要,低于 50 的 FPS 会显示闪烁。
代码如下:
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);
}
我会显示图像序列,显示代码:
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();
}
【问题讨论】:
-
你一开始就不能用 OpenGL 加载位图,所以我猜 JPEG 不会更容易。但请考虑使用压缩纹理,无论您如何加载实际图像数据。
标签: c++ opengl bmp image-preloader