【发布时间】:2013-03-30 00:25:52
【问题描述】:
我知道我做错了什么,很明显。无论如何,我已经编写了一些代码来尝试让我的纹理动画化,但并不确定出了什么问题或我做错了什么。
这是加载到我的纹理中的代码:
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;
uniform sampler2D sTexture2;
可变介质p vec2 TexCoord; 变介质p 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;
}
【问题讨论】:
-
你为什么要这样做?
gl_FragColor = tex2 * tex1;为什么不这样呢?gl_FragColor = 0.5*tex2 + 0.5*tex1; -
对不起,丹,这是因为我对 ES 2.0 还很陌生,只是掌握了一点,但我会实施你的建议。
-
不,你没有看错。只是vec4*vec和0.5*vec4+0.5*vec4不同。第一个用于遮蔽颜色,第二个用于将 2 个纹理混合在一起。什么是正确的取决于你想要完成什么。 :) 顺便说一句,如果你想通过切换纹理来使用动画,使用
uniform int u_mode;然后if(u_mode==0) gl_FragColor = tex1; else gl_FragColor = tex2;不是更容易吗? -
也许我没有正确定义我想要实现的目标,我希望两个纹理都能够独立滚动?我认为我在回顾我的代码时采取了错误的方法