OpenGL GL_BLEND

时间:2014-12-21 12:12:37

标签: c++ opengl transparency

我想绘制16 x 16格的texture_water,沿着i轴增加透明度。不幸的是,所有16x16方块都与首次调用glColor4f时设置的alpha值混合(在本例中为0)。在循环内移动glBegin(GL_QUADS);没有帮助。我究竟做错了什么?

    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);        
    glBindTexture(GL_TEXTURE_2D, texture_water);

    glBegin(GL_QUADS);
    for (UINT i = 0; i < numCells; i++) {
        for (UINT l = 0; l < numCells; l++)  {              
            float h = ((float)(i) / 16);
            glColor4f(1.0, 1.0, 1.0, h);
            glTexCoord2f(0, 0); glVertex3f(sc*i, sc*l, 0.0f);
            glTexCoord2f(0, 1); glVertex3f(sc*i, sc*(l + 1), 0.0f);
            glTexCoord2f(1, 1); glVertex3f(sc*(i + 1), sc*(l + 1), 0.0f);
            glTexCoord2f(1, 0); glVertex3f(sc*(i + 1), sc*l, 0.0f);                             
        }
    }
    glEnd();    

0 个答案:

没有答案