How can I load 8 bit bmp with OpenGL?

前端 未结 2 762
失恋的感觉
失恋的感觉 2021-01-16 17:59

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 mem

相关标签:
2条回答
  • 2021-01-16 18:30

    You should not use glDrawPixels, it is deprecated functionality. The best way to do it would probably be drawing a screen-sized quad (-1,-1 => 1,1 without any matrix transform) that you texture with these images.

    For the textures you can specify several internal formats in glTexImage2D and similar functions. For example, you could use the GL_R3_G3_B2​ format to get your 8-bit size, but could as well use the compressed formats like S3TC. You could for example pass COMPRESSED_SRGB_S3TC_DXT1_EXT, which should reduce your image size to 4 bits per pixel, likely at better quality than the 8 bit format. You cannot use JPEG as a compression format in OpenGL (it's too complex).

    Finally, why do you want to do this through OpenGL? blitting an image to a regular window will likely give you well enough performance. Then you could even store your image sequence as video and just blit the decoded frames. It's very unlikely you will ever get memory problems in this case.

    0 讨论(0)
  • 2021-01-16 18:43

    Maybe you don't need to have 2000 images and display them at 60fps at all? Stable 25fps is just enough for any movie.

    I encourage you to rethink your original problem and come up with a better suited solution (video, animation, vectors, maybe something else)

    As for original question:

    If you need images only once - put them to memory when you need them and discard them right after displaying.

    Use DXT packed images. With a slight degrade in quality you get a constant x4/x8 compression ratio.

    OpenGL is not very good at working with paletted textures these days (many vendors have poor implementations). But you can implement that with shaders.

    0 讨论(0)
提交回复
热议问题