PDA

View Full Version : How to animate 2D textures ?



MarsuGL
07-01-2001, 06:34 AM
Hello,
i want to make a very simple water effect without blending yet,
so i have a 2D square with a water texture mapped on it.
i have tried to move glTexCoord2f parameters
(at first i just want to animate the Y coordinates)
i want the wather to move from the top of my quad from the bottom and to make a circular movement (i'm not sure it's a very clear explaination..)

here's what i am tried :
.
.
.
GLfloat ycdeb=0.0f;
GLfloat ycfin=4.0f;
.
.
glBegin(GL_QUADS);
glTexCoord2f(0.0f, ycdeb);glVertex3f(-20.0,0.0,0.0);
glTexCoord2f(0.0f, ycfin);glVertex3f(-20.0,0.0,-50.0);
glTexCoord2f(4.0f, ycfin);glVertex3f(20.0,0.0,-50.0);
glTexCoord2f(4.0f, ycdeb);glVertex3f(20.0,0.0,0.0);
glEnd();
.
.
.
if (g_keys->keyDown [VK_F5] == TRUE) // Is F1 Being Pressed?
{
if (ycfin==4.0)
{
ycfin=0.1f;
ycdeb+=0.001f;
}
if (ycdeb==4.0)
{
ycdeb=0.1f;
ycfin+=0.001f;
}

ycfin+=0.001f;
ycdeb+=0.001f;
}
.
.
.

the circular effets seem to be good but the texture is not looking good, like if it was extensed.

if you can help me with this, tanks by advance.
Marsu

MButchers
07-02-2001, 01:35 AM
Hi there

use the texture matrix
ie

glBindTexture(GL_TEXTURE_2D,texid);
glMatrixMode(GL_TEXTURE_MATRIX); - i think this is the one
glTranslatef(x,y,z);
glMatrixMode(GL_MODELVIEW_MATRIX);

(its something like this ive got the code
at home and will check it tonight).

you can also rotate the texture using this
method.

Hope it helps

Mark.

MarsuGL
07-02-2001, 10:28 AM
tanks for help,i havn't tried your code yet, but the idea of rotating a texture easily sounds good !

yesterday, i have take again a look at my code, i have put // behind my reset code (that was supposed to reset the UV coords to their starting value when they have reached the end value (4 in my example because 4 tiles)
and it works fine, but now i dont understand why,
i just increment the coords from 0 to ???, and from 4 to ???, it never ends, why didn't the texture don't move away from the poly, all works well and i don't understand why, maybe if i let the programm run a while it will crash ? i havn't tried.
Can you explain why ?
Marsu

vrempire
07-02-2001, 10:36 PM
how about if you try to include the sphere environment mapping inside the code just to make the water texture looks more real.
use texture generation modes.

MarsuGL
07-02-2001, 10:54 PM
ok, tanks for suggest this .
yet i just want the texture to move, after i will work on appearence :-)

Marsu