Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Hey I at the moment I have got my texture to move however it stutters as I increment by 0.001 every second. My animation is done via FPS if that make sense and here is some code

FrameCount++;

p_Time = c_Time;
c_Time = PVRShellGetTime();

elapsed = c_Time / 1000.0f;
DT = ((float)(c_Time - p_Time)) / 1000.0f;

fCount += DT;

if(fCount >= 1.0f) //if time is over 1 second reset counters and recount
{
    FPS = FrameCount;
    FrameCount = 0;
    fCount = 0;
    move += 0.001;
    glUniform1f(m_ShaderProgram.auiLoc[eTime], move);
}

My problem is I want it to move more seamlessly and not sure how to achieve this and thought I would get some ideas from you.

Oh and here is my vertex and fragment shader

Vert

    attribute highp   vec3  inVertex;
attribute mediump vec3  inNormal;
attribute mediump vec2  inTexCoord;
attribute mediump vec3  inTangent;

uniform highp   mat4  MVPMatrix;
uniform mediump vec3  EyePos;
uniform mediump float Time;

varying mediump vec3  EyeDir;
varying mediump vec2  TexCoord;
varying mediump vec2  TexCoord2;
varying mediump float vTime;

void main()
{
    // Transform position
    gl_Position = MVPMatrix * vec4(inVertex,1.0);   

    /*mediump vec2 waterCoord = inTexCoord;
    TexCoord = waterCoord.xy * waterSX; 
    TexCoord += watermovementX;*/
    TexCoord = inTexCoord;
    vTime = Time; 
}

and here is my frag

    uniform sampler2D  n_mapTex;
uniform sampler2D  n_mapTex2;

varying mediump vec2  TexCoord;
varying mediump vec2  TexCoord2;
varying mediump float vTime;

void main()
{   
    gl_FragColor =  texture2D(n_mapTex, vec2(TexCoord.x + vTime, TexCoord.y + vTime));
}

Thanks

share|improve this question
    
Before I get into your code, are you sure that your textures are not too big on filesize? –  IMX Apr 27 '13 at 18:56
    
hey IMX I solved the problem its because in my code it only adds 0.001 every second rather than on every frame –  DorkMonstuh Apr 27 '13 at 19:09
add comment

1 Answer

As you already have a delta time in seconds, and also the 'speed' of the texture in whatever units you use per second, then you simply need to move the texture by the speed (0.001) multiplied by the delta in seconds. Say if you have a delta of 0.5 seconds, the movement would be 0.0005, which is what you want.

To implement it in your program, change

if(fCount >= 1.0f) //if time is over 1 second reset counters and recount
{
    FPS = FrameCount;
    FrameCount = 0;
    fCount = 0;
    move += 0.001;
    glUniform1f(m_ShaderProgram.auiLoc[eTime], move);
}

to

if(fCount >= 1.0f) //if time is over 1 second reset counters and recount
{
    FPS = FrameCount;
    FrameCount = 0;
    fCount = 0;
    glUniform1f(m_ShaderProgram.auiLoc[eTime], move);
}
move += 0.001 * DT

This technique is invaluable in developing games which cope with changing framerates, because your objects will always move the same distance per second rather than per frame, which means you no longer need to assume a constant framerate.

EDIT: As you mentioned the 0.001 was supposed to be per frame, you can simply swap 0.001 in the code for what ever per-second value you desire.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.