我有一些通过 Photoshop 以 32 位保存的 bmp。前 24 位应代表 RGB,后 8 位应代表 Alpha 通道。我正在加载我的位图:
Bitmap* bStart = new Bitmap("starten.bmp");
我正在加载文件并设置 Alpha 通道的值
Bitmap::Bitmap(const char* filename) {
FILE* file;
file = fopen(filename, "rb");
if(file != NULL) { // file opened
BITMAPFILEHEADER h;
fread(&h, sizeof(BITMAPFILEHEADER), 1, file); //reading the FILEHEADER
fread(&this->ih, sizeof(BITMAPINFOHEADER), 1, file);
this->pixels = new GLbyte[this->ih.biHeight * this->ih.biWidth * this->ih.biBitCount / 8];
fread(this->pixels, this->ih.biBitCount / 8 * this->ih.biHeight * this->ih.biWidth, 1, file);
fclose(file);
for (int i = 3; i < this->ih.biHeight * this->ih.biWidth * this->ih.biBitCount / 8; i+=4) {
this->pixels[i] = 255;
}
}
}
设置纹理:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bStart->ih.biWidth, bStart->ih.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, bStart->pixels);
初始化的东西:
glutInit(argcp, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
//not necessary because we using fullscreen
//glutInitWindowSize(550, 550);
//glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]); //creating the window
glutFullScreen(); //go into fullscreen mode
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //art und weise wie texturen gespeicehrt werden
glClearColor (1.0, 0.6, 0.4, 0.0);
//setting the glut functions
glutDisplayFunc(displayCallback);
glutKeyboardFunc(keyboardCallback);
glutMainLoop(); //starting the opengl mainloop... and there we go
我可以在我的应用程序中看到我的纹理,但它们的背景不透明……它是一种浅蓝色。我究竟做错了什么?