Skip to main content
gamedev.net
🔒 Locked

terrain blending problem

Started by ade-the-heat 0 replies 350+ views
Original Post
ade-the-heat
ade-the-heat
Hi Just read someone else's terrain func. I realised I didn't understand it ! He does two passes.:

shortened code snip


//blend func set at start up:
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

//1st pass draw:
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glColor4f(1,1,1,1.f);

    //loop:
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(xtexa2,ytexa2);  
    glVertex3f(coord+quality,field[i+quality][i2+quality].y,  coord2+quality);
    glTexCoord2f(xtexa2,ytexa);   
    glVertex3f(coord+quality,field[i+quality][i2].y,coord2);
    glTexCoord2f(xtexa,ytexa2);   
    glVertex3f(coord,field[i2+quality].y,coord2+quality); 
    glTexCoord2f(xtexa,ytexa);   glVertex3f(coord,field[i2].y,coord2); 
    glEnd();

...

    //2nd pass:
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    glColor4f(1,.7,.6,.5f);

    //loop:
    glBegin(GL_TRIANGLE_STRIP);
    glColor4f(1,.7,.6,alpha[i+quality][i2+quality]);
    glTexCoord2f(xtexa2,ytexa2);  
    glVertex3f(coord+quality,field[i+quality][i2+quality].y,  coord2+quality);
    glColor4f(1,.7,.6,alpha[i+quality][i2]);
    glTexCoord2f(xtexa2,ytexa);   
    glVertex3f(coord+quality,field[i+quality][i2].y,coord2); 
    glColor4f(1,.7,.6,alpha[i2+quality]);
    glTexCoord2f(xtexa,ytexa2);   
    glVertex3f(coord,field[i2+quality].y,coord2+quality); 
    glColor4f(1,.7,.6,alpha[i2]);
    glTexCoord2f(xtexa,ytexa);   
    glVertex3f(coord,field[i2].y,coord2); 
    glEnd();


What's being blended with what ?? 1st with 2nd texture ? 1st text with color and 2nd text with 2nd color ? I don't get it and I know it's easy !
__filip
__filip
In the first pass the first texture is blended with whatever was on the screen before. If the first texture doesn't contain any transparency (it's either fully opaque or doesn't have an alpha channel), the first pass will render as if blending were turned off, otherwise you'll get some kind of transparency based only on the first textures alpha channel.
In the second pass the second texture is blended with the result of the first pass, here the alpha is set to 50% by glColor, this means you'll get at least 50% transparency, more if the second texture is transparent too.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.