将纹理读入opengl的最简单格式是什么?是否有任何教程 - 好的教程,用于将 jpg、png 或 raw 等图像格式加载到可用于纹理映射的数组中(最好不使用 libpng 等库)?
2 回答
OpenGL itself does not knows nothing about common image formats (other than natively supported S3TC/DXT compressed and alikes, but they are a different story). You need to expand you source images into RGBA arrays. Number of formats and combinations are supported. You need to choose one that suits you, e.g. GL_ALPHA4 for masks, GL_RGB5_A1 for 1bit transparency, GL_BGRA/GL_RGBA for fullcolor, etc.
For me the easiest (not the fastest) way are PNGs, for their lossless compression and full Alpha support. I read the PNG and write RGBA values into array which I then hand over to OpenGL texture creation. If you don't need alpha you may as well accept JPG or BMP. Pipeline is common Source -> Expanded RGBA array -> OpenGL texture.
链接上有一个方便的 OpenGL 纹理教程:http ://www.nullterminator.net/gltexture.html