0

我似乎无法将图像上的透明背景加载为透明。相反,它总是白色的。我对 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);
}
4

0 回答 0