矩阵-sprite

2022-05-11  本文已影响0人  许彦峰

sprite-normal

attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;

#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif

void main()
{
    gl_Position = CC_PMatrix * a_position;
    v_fragmentColor = a_color;
    v_texCoord = a_texCoord;
}
#ifdef GL_ES
precision lowp float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

void main()
{
    gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);
}

sprite size: 512*512


sprite的顶点数据

当位置在sprite.position=(0,0)点时,

void Renderer::fillVerticesAndIndices(const TrianglesCommand* cmd)
{
    const Mat4& modelView = cmd->getModelView();
}

modelView[12]=-256,即x坐标偏移
modelView[13]=-256,即y坐标偏移

上一篇下一篇

猜你喜欢

热点阅读