开发者

glFog causing transparent png to lose transparency

开发者 https://www.devze.com 2022-12-29 11:08 出处:网络
Without glFog, my transparent png displays fine, but with it you can see the rectanglular background and strips of other colours (notice the other dirt material is working as intended, but not using a

Without glFog, my transparent png displays fine, but with it you can see the rectanglular background and strips of other colours (notice the other dirt material is working as intended, but not using a png or transparency).

alt text http://img203.imageshack.us/img203/4466/screenshot20100509at528.pngalt text http://img69.imageshack.us/img69/3131/screenshot20100509at456.png

Here's my code for the fog:

GLfloat colour[4]={0.8f,0.8f,1.0f, 1.0f};
glFogi(GL_FOG_MODE, GL_EXP);
glFogfv(GL_FOG_COLOR, colour);
glFogf(GL_FOG_DENSITY, 0.1);
glHint(GL_FOG_HINT, GL_NICEST);
glFogf(GL_FOG_START, 1.0);
glFogf(GL_FOG_END, 5.0);
glEnable(GL_FOG);   
glClearColor(0.8f,0.8f,1.0f,1.0f);

And my code for the png:

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    GLfloat myAmbient[] = {0.7,0.7,0.7,1.0};
    glMaterialfv(GL_FRONT, GL_AMBIENT, myAmbient);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, pla开发者_StackOverflow中文版ntTexture);
    glColor3f(0.5,0.5,0.2);

    glPushMatrix();
        glTranslated(-1,-14,10);
        glScaled(10,10,10);
        glBegin(GL_QUADS);
            glNormal3f(0,0,1);
            glTexCoord2f(0,1); glVertex2i(1,0);
            glNormal3f(0,0,1);
            glTexCoord2f(0,0); glVertex2i(1,1);
            glNormal3f(0,0,1);
            glTexCoord2f(1,0); glVertex2i(0,1);
            glNormal3f(0,0,1);
            glTexCoord2f(1,1); glVertex2i(0,0);
        glEnd();
    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

I'm completely lost on this one. Any ideas?


Since your quad is translucent, you should disable writes to the depth buffer with glDepthMask(false) prior to draw it (assuming GL_DEPTH_TEST is enabled).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号