1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| local vert = [[ 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; } ]]
local frag = [[ #ifdef GL_ES precision mediump float; #endif
varying vec4 v_fragmentColor; varying vec2 v_texCoord;
void main(void) { // 当前片源的颜色 vec4 c = texture2D(CC_Texture0, v_texCoord); gl_FragColor.xyz = vec3(0.2126*c.r + 0.7152*c.g + 0.0722*c.b); gl_FragColor.w = c.w; } ]]
local glProgram = cc.GLProgram:createWithByteArrays(vert, frag) local glProgramState = cc.GLProgramState:getOrCreateWithGLProgram(glProgram)
local logo = self.holder:getChildByName("Sprite_start_logo") local size = logo:getTexture():getContentSizeInPixels()
logo:setGLProgramState(glProgramState)
|