我使用纹理altas和此顶点着色器在四边形上渲染纹理:
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"attribute vec4 a_Color;" +
"attribute vec2 a_texCoord;" +
"varying vec4 v_Color;" +
"varying vec2 v_texCoord;" +
"uniform vec4 u_newColor;" +
"void main() {" +
" float offset = 0.33;" +
" gl_Position = uMVPMatrix * vPosition;" +
" v_texCoord.x = a_texCoord.x + offset;" +
" v_texCoord.y = a_texCoord.y + offset;" +
" v_Color = u_newColor;" +
"}";
一切正常,我在纹理中渲染第三个,在地图集中显示9的中间拼贴。除了我想要'抵消'成为一个变量,即我想根据哪个'平铺来改变它?我需要纹理图集。
这怎么可能?
答案 0 :(得分:0)
添加制服并使用:
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"attribute vec4 a_Color;" +
"attribute vec2 a_texCoord;" +
"varying vec4 v_Color;" +
"varying vec2 v_texCoord;" +
"uniform vec4 u_newColor;" +
"uniform vec2 u_offset ;" + //vec2 so there is a x and y component that you can set
"void main() {" +
" gl_Position = uMVPMatrix * vPosition;" +
" v_texCoord = a_texCoord + u_offset;" +
" v_Color = u_newColor;" +
"}";
然后用
设置制服glUniform2f(u_offset_location, xTile, yTile);