PDA

View Full Version : Dissolving



Spahrep
06-22-2001, 05:28 AM
How could i go about making one texture
dissolve into another texture?
Or even better, become transparent or morph into the other texture?
Im looking for same polygone just w/ slowly changed texture.

thanks.

hoshi55
06-22-2001, 06:21 AM
true morphing is not supported by openGL and would be a rather challenging task.

a solution i can think of is to use multipass rendering.
pass 1 would bear your original texture, with an initial alpha value of 1 across the polygon. pass 2 bears the texture you want to fade to, with alpha=0.. then slowly decrease / increase the alpha values so that you end up with an alpha1=0 and alpha2=1. this looks best if you set the blend function to glBlendFunc(GL_SRC_ALPHA,GL_ONE);

Spahrep
06-22-2001, 06:24 AM
you mind giving a tiny bit of psuedo code,
im still quite new at all this,

thanks.

hoshi55
06-22-2001, 02:27 PM
i'm not really sure whether multipass rendering works that way, haven't used it yet, but i think that's the way to go:

GLfloat alpha[2] = {1.0, 0.0 };

void render_poly(int pass)
{
glBindTexture(GL_TEXTURE_2D, textureid[pass]);
glColor4f(1.0,1.0,1.0,alpha[pass]);
glBegin(GL_WHATEVER)
// draw your poly here, including texture coords
glEnd();
}


void gfx_pipeline()
{
glBlendFunc( /* as specified above */);
while(alpha[0]>0.0)
{
alpha[0]-=0.1; alpha[1]+=0.1;
render(0);
render(1);
glFlush(); glSwapBuffers();
}
}

not taking into account proper FPS sync of course. basically, multipass rendering just draws the same polygon twice at the same coordinates. since the coords are the same, the second poly is assumed to be positioned *just on the surface* of the first poly and the second texture (if blended) will appear as a decal on the first one. in this case, it should make up for a texture morph effect.