Reputation: 853
I know I have done something wrong, obviously. Anyway I have wrote some code to try and get my textures to animate and not really sure what's gone wrong or what I have done wrong.
here is the code that loads in my textures:
if(PVRTTextureLoadFromPVR(c_szTextureFile, &m_uiTexture[0]) != PVR_SUCCESS)
{
PVRShellSet(prefExitMessage, "ERROR: Cannot load the texture\n");
return false;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//This loads in the second texture
if(PVRTTextureLoadFromPVR(c_szTextureFile2, &m_uiTexture[1]) != PVR_SUCCESS)
{
PVRShellSet(prefExitMessage, "ERROR: Cannot load the texture2\n");
return false;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
and here is my timer function that attempts to update the texture coordinates
int time_Loc = glGetUniformLocation(m_ShaderProgram.uiId, "Time"); //This stores the location of the uniform
float updateTexture;
float timeElapsed = difftime(time(NULL), Timer) * 1000;
if(timeElapsed > 16.0f)
{
glUniform1f(time_Loc, updateTexture++); // passes the updated value to shader
}
and here is my shader that I am passing the data to
uniform sampler2D sTexture;
uniform sampler2D sTexture2;
varying mediump vec2 TexCoord; varying mediump vec2 TexCoord2;
//This gets updated within the main code
uniform highp float Time;
void main()
{
mediump vec4 tex1 = texture2D(sTexture, TexCoord + Time);
mediump vec4 tex2 = texture2D(sTexture2, TexCoord2 + Time);
gl_FragColor = tex2 * tex1;
}
Upvotes: 0
Views: 91
Reputation: 906
The second paramater of texture2D is clipped from 0->1, it is not in absolutes or pixels. You have a TexCoord, while I'll assume is also in the (0->1, 0->1) range. You're then "adding" a float value, that is getting incremented in your C code, via updateTexture++. Its also not getting initialized!
Try something more like this:
float updateTexture = 0.0f;
...
if(timeElapsed > 16.0f)
{
updateTexture += 0.01; // arbitrary increment
if(updateTexture > 1.0) updateTexture = 0.0f; // wrap, if you want
glUniform1f(time_Loc, updateTexture); // passes the updated value to shader
}
Then in your shader do something more explicit than adding a float to a vec2:
...
mediump vec4 tex1 = texture2D(sTexture, vec2(TexCoord.x + Time, TexCoord.y + Time));
...
Upvotes: 0