Jump to content
  • Advertisement
Sign in to follow this  
ade-the-heat

terrain blending problem

This topic is 4627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 !

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!