我似乎无法将图像上的透明背景加载为透明。它总是白色的。我仍然是OpenGL / SOIL的新手,所以如果我做了一些愚蠢的事情就不要生气:/它是否与我的旗帜上的RGB有关而不是RGBA?
void Scene::loadTexShips()
{
texShips[0] = SOIL_load_OGL_texture(
"Textures/Carrier.png",
SOIL_LOAD_LA,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB
);
if (texShips[0] == 0)
{
printf("SOIL loading error: '%s'\n", SOIL_last_result());
}
}
void Scene::drawShips()
{
glColor4ub(255, 255, 255, 255);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLoadIdentity();
glTranslatef(6.0f, 2.0f, -12.0f);
glBindTexture(GL_TEXTURE_2D, texShips[0]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-4.0f, -3.0f, 2.0);
glTexCoord2f(0, 1);
glVertex3f(-4.0f, -2.3, 2.0);
glTexCoord2f(1, 1);
glVertex3f(-1.0, -2.3, 2.0);
glTexCoord2f(1, 0);
glVertex3f(-1.0, -3.0, 2.0);
glEnd();
glDisable(GL_TEXTURE_2D);
}