纹理没有动画

时间:2013-03-30 00:25:52

标签: opengl-es opengl-es-2.0

我知道我做错了什么。无论如何,我已经编写了一些代码来尝试让我的纹理生成动画,而不是确定出了什么问题或者我做错了什么。

这是在我的纹理中加载的代码:

 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);

这是我的计时器功能,它试图更新纹理坐标

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
}

这是我的着色器,我将数据传递给

uniform sampler2D  sTexture;

均匀采样器2D sTexture2;

不同的mediump vec2 TexCoord; 不同的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;
}

1 个答案:

答案 0 :(得分:0)

texture2D的第二个参数从0-> 1剪裁,它不是绝对值或像素。你有一个TexCoord,我假设也在(0-> 1,0-> 1)范围内。然后,您将通过updateTexture ++“添加”浮点值,该值将在C代码中增加。它也没有初始化!

尝试更像这样的事情:

  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
  }

然后在着色器中做一些比向vec2添加浮动更明确的事情:

  ...
  mediump vec4 tex1 = texture2D(sTexture, vec2(TexCoord.x + Time, TexCoord.y + Time));
  ...