C++ OpenGL 显示 TGA 文件的实现
在 C++ OpenGL 编程中,使用 TGA 图像格式是非常常见的。TGA 格式是一种无损压缩的位图格式,可以存储图像的颜色和透明度信息。本文将介绍如何在 OpenGL 中显示 TGA 图像,并提供相应的源代码。
一、TGA 文件格式
TGA 文件格式的头信息占用了前 18 个字节,包含以下字段:
typedef struct tga_header_t{
unsigned char id_length;
unsigned char color_map_type;
unsigned char image_type;
unsigned short color_map_offset;
unsigned short color_map_length;
unsigned char color_map_depth;
unsigned short x_origin;
unsigned short y_origin;
unsigned short width;
unsigned short height;
unsigned char bits_per_pixel;
unsigned char image_descriptor;
}tga_header_t;
其中比较重要的字段有:
- image_type:图像类型,支持三种