我想在openGl ES 2.0中为一些数字制作动画。为了尝试使其工作开始我已经创建了一个计时器,并试图让数字改变依赖于计时器。定时器设置在sin()波上,因此数字应该增加然后再减少。数字位于纹理图集的顶行,因此通过增加x方向上的纹理坐标可将其移动到下一个数字。我已经尝试使用片段着色器和if语句移动纹理坐标,但没有运气。我确定必须有更好的方法来做到这一点。
片段着色器
char FragShader[] =
"precision highp float;\n"
"varying highp vec2 textureCoordinate;\n"
"uniform sampler2D Texture;\n"
"uniform float time;\n"
"void main()\n"
"{\n"
"float c1 = 0.5*sin(time)+0.5;\n"
"if (c1 >= 0.0 && c1 < 0.1)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.1 && c1 < 0.2)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.1, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.2 && c1 < 0.3)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.2, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.3 && c1 < 0.4)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.3, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.4 && c1 < 0.5)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.4, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.5 && c1 < 0.6)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.5, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.6 && c1 < 0.7)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.6, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.7 && c1 < 0.8)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.7, 1.0 -textureCoordinate.y);\n"
"elseif (c1 >= 0.8 && c1 < 0.9)"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.8, 1.0 -textureCoordinate.y);\n"
"else"
"vec2 flipped_texcoord = vec2(textureCoordinate.x+0.9, 1.0 -textureCoordinate.y);\n"
"vec4 colour = texture2D(Texture, flipped_texcoord);\n"
"gl_FragColor = colour;\n"
"}\n";
答案 0 :(得分:0)
好的,这是一个基本的修复,我的'elseif'应该是'else if'。这是一个问题,因为我缺乏对C ++编码的了解。