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;

统一的sampler2D 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;
}
4

1 回答 1

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));
  ...
于 2013-03-30T13:30:29.180 回答